1# This Source Code Form is subject to the terms of the Mozilla Public 2# License, v. 2.0. If a copy of the MPL was not distributed with this 3# file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5from marionette_driver import errors 6 7from marionette_harness import MarionetteTestCase 8 9 10class TestSession(MarionetteTestCase): 11 def setUp(self): 12 super(TestSession, self).setUp() 13 self.marionette.delete_session() 14 15 def test_new_session_returns_capabilities(self): 16 # Sends newSession 17 caps = self.marionette.start_session() 18 19 # Check that session was created. This implies the server 20 # sent us the sessionId and status fields. 21 self.assertIsNotNone(self.marionette.session) 22 23 # Required capabilities mandated by WebDriver spec 24 self.assertIn("browserName", caps) 25 self.assertIn("browserVersion", caps) 26 self.assertIn("platformName", caps) 27 self.assertIn("platformVersion", caps) 28 29 # Optional capabilities we want Marionette to support 30 self.assertIn("rotatable", caps) 31 32 def test_get_session_id(self): 33 # Sends newSession 34 self.marionette.start_session() 35 36 self.assertTrue(self.marionette.session_id is not None) 37 self.assertTrue(isinstance(self.marionette.session_id, unicode)) 38 39 def test_set_the_session_id(self): 40 # Sends newSession 41 self.marionette.start_session(session_id="ILoveCheese") 42 43 self.assertEqual(self.marionette.session_id, "ILoveCheese") 44 self.assertTrue(isinstance(self.marionette.session_id, unicode)) 45 46 def test_session_already_started(self): 47 self.marionette.start_session() 48 self.assertTrue(isinstance(self.marionette.session_id, unicode)) 49 with self.assertRaises(errors.SessionNotCreatedException): 50 self.marionette._send_message("newSession", {}) 51 52 def test_no_session(self): 53 with self.assertRaises(errors.InvalidSessionIdException): 54 self.marionette.get_url() 55 self.marionette.start_session() 56 self.marionette.get_url() 57