def setUp(self): """Sets up the environment for a test case. Retreive already running test environment, or create a new one if one doesn't exist. A test environment consists of a web server with HTTP and WebSocket handlers which tests can access through ``self.handler``. Then set up a Marionette session to the connected device if one does not already exist. This is assigned to ``self.marionette``. Marionette can be used to remote control the device. """ super(TestCase, self).setUp() env = environment.get(InProcessTestEnvironment) self.server = env.server self.handler = env.handler self.assert_browser_connected() self.marionette = TestCase.create_marionette() turn_screen_on(self.marionette) unlock_screen(self.marionette) if not certapp.is_installed(): certapp.install(self.marionette) # Make sure we don't reuse the certapp context from a previous # testrun that was interrupted and left the certapp open. try: certapp.kill(self.marionette) except certapp.CloseError: self.close_app_manually() try: self.app = certapp.launch(self.marionette) except certapp.LaunchError: self.launch_app_manually()
def cleanup(self): if self.marionette is not None: certapp.kill(self.marionette, app=self.app)