def edit_device_profile(device_profile_path, message): resp = '' result = None try: env = environment.get(environment.InProcessTestEnvironment) url = "http://%s:%d/profile.html" % (env.server.addr[0], env.server.addr[1]) webbrowser.open(url) environment.env.handler = server.wait_for_client() resp = environment.env.handler.prompt(message) message = 'Create device profile failed!!' if resp: result = json.loads(resp) if result['return'] == 'ok': with open(device_profile_path, 'w') as device_profile_f: json.dump(result, device_profile_f, indent=4) message = 'Create device profile successfully!!' else: message = 'Create device profile is cancelled by user!!' else: message = '' logger.info(message) except: logger.error("Failed create device profile:\n%s" % traceback.format_exc()) return result
def run(suite, logger, spawn_browser=True, verbosity=1, quiet=False, failfast=False, catch_break=False, buffer=True, **kwargs): """A simple test runner. This test runner is essentially equivalent to ``unittest.main`` from the standard library, but adds support for loading test classes with extra keyword arguments. The easiest way to run a test is via the command line:: python -m semiauto test_sms See the standard library unittest module for ways in which tests can be specified. For example it is possible to automatically discover tests:: python -m semiauto discover .""" if catch_break: import unittest.signals unittest.signals.installHandler() env = environment.get(environment.InProcessTestEnvironment, addr=None if spawn_browser else ("127.0.0.1", 6666), verbose=(verbosity > 1)) url = "http://%s:%d/" % (env.server.addr[0], env.server.addr[1]) if spawn_browser: import webbrowser webbrowser.open(url) else: print >> sys.stderr, "Please connect your browser to %s" % url # Wait for browser to connect and get socket connection to client try: so = server.wait_for_client() except server.ConnectError as e: logger.error("%s: error: %s" % (sys.argv[0], e)) sys.exit(1) tests = serialize_suite(suite) test_runner = StructuredTestRunner(logger=logger, test_list=tests) # This is a hack to make the test suite metadata and the handler # available to the tests. so.suite = suite environment.env.handler = so logger.suite_start(tests=tests) try: results = test_runner.run(suite) except (SystemExit, KeyboardInterrupt) as e: sys.exit(1) logger.suite_end() return results
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 run(suite, logger=None, spawn_browser=True, verbosity=1, quiet=False, failfast=False, catch_break=False, buffer=True, **kwargs): """A simple test runner. This test runner is essentially equivalent to ``unittest.main`` from the standard library, but adds support for loading test classes with extra keyword arguments. The easiest way to run a test is via the command line:: python -m semiauto test_sms See the standard library unittest module for ways in which tests can be specified. For example it is possible to automatically discover tests:: python -m semiauto discover . """ if catch_break: import unittest.signals unittest.signals.installHandler() if not logger: logger = create_logger() env = environment.get(environment.InProcessTestEnvironment, addr=("localhost", get_free_port(6666)), verbose=(verbosity > 1)) url = "http://%s:%d/" % (env.server.addr[0], env.server.addr[1]) if spawn_browser: import webbrowser webbrowser.open(url) else: print >> sys.stderr, "Please connect your browser to %s" % url # Wait for browser to connect and get socket connection to client try: so = server.wait_for_client() except server.ConnectError as e: print >> sys.stderr, "%s: error: %s" % (sys.argv[0], e) sys.exit(1) tests = runner.serialize_suite(suite) test_runner = StructuredTestRunner(logger=logger, test_list=tests) # This is a hack to make the test suite metadata and the handler # available to the tests. so.suite = suite environment.env.handler = so logger.add_handler(runner.WSHandler(so)) try: results = test_runner.run(suite) except (SystemExit, KeyboardInterrupt) as e: sys.exit(1) return results