summaryrefslogtreecommitdiffstats
path: root/testing/marionette/harness/marionette_harness/tests/unit/test_session.py
blob: 1b709ed28b4125874e815810b364922107696152 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import six

from marionette_driver import errors

from marionette_harness import MarionetteTestCase


class TestSession(MarionetteTestCase):
    def setUp(self):
        super(TestSession, self).setUp()

        self.marionette.delete_session()

    def test_new_session_returns_capabilities(self):
        # Sends newSession
        caps = self.marionette.start_session()

        # Check that session was created.  This implies the server
        # sent us the sessionId and status fields.
        self.assertIsNotNone(self.marionette.session)

        # Required capabilities mandated by WebDriver spec
        self.assertIn("browserName", caps)
        self.assertIn("browserVersion", caps)
        self.assertIn("platformName", caps)

    def test_get_session_id(self):
        # Sends newSession
        self.marionette.start_session()

        self.assertTrue(self.marionette.session_id is not None)
        self.assertTrue(isinstance(self.marionette.session_id, six.text_type))

    def test_session_already_started(self):
        self.marionette.start_session()
        self.assertTrue(isinstance(self.marionette.session_id, six.text_type))
        with self.assertRaises(errors.SessionNotCreatedException):
            self.marionette._send_message("WebDriver:NewSession", {})

    def test_no_session(self):
        with self.assertRaises(errors.InvalidSessionIdException):
            self.marionette.get_url()

        self.marionette.start_session()
        self.marionette.get_url()