def kwarg_builder(new_items, return_socket=False): mach_parsed_kwargs.update(new_items) runner = MarionetteTestRunner(**mach_parsed_kwargs) with patch('marionette.runner.base.socket') as socket: built_kwargs = runner._build_kwargs() if return_socket: return built_kwargs, socket return built_kwargs
def test_load_testvars_throws_expected_errors(mach_parsed_kwargs): mach_parsed_kwargs['testvars'] = ['some_bad_path.json'] runner = MarionetteTestRunner(**mach_parsed_kwargs) with pytest.raises(IOError) as io_exc: runner._load_testvars() assert 'does not exist' in io_exc.value.message with patch('os.path.exists', return_value=True): with patch('__builtin__.open', mock_open(read_data='[not {valid JSON]')): with pytest.raises(Exception) as json_exc: runner._load_testvars() assert 'not properly formatted' in json_exc.value.message
def test_parsing_testvars(mach_parsed_kwargs): mach_parsed_kwargs.pop('tests') testvars_json_loads = [{ "wifi": { "ssid": "blah", "keyManagement": "WPA-PSK", "psk": "foo" } }, { "wifi": { "PEAP": "bar" }, "device": { "stuff": "buzz" } }] expected_dict = { "wifi": { "ssid": "blah", "keyManagement": "WPA-PSK", "psk": "foo", "PEAP": "bar" }, "device": { "stuff": "buzz" } } with patch('marionette.runtests.MarionetteTestRunner._load_testvars', return_value=testvars_json_loads) as load: runner = MarionetteTestRunner(**mach_parsed_kwargs) assert runner.testvars == expected_dict assert load.call_count == 1
def runner(mach_parsed_kwargs): """ MarionetteTestRunner instance initialized with default options. """ return MarionetteTestRunner(**mach_parsed_kwargs)
def run_test(self, testname, testvars={}): if not self.ready: return self.error("run_test() called before setup") self.info("Beginning marionette test '%s'" % testname) e10s = testvars.get("e10s", False) prefs = { # disable network access "network.proxy.socks": "localhost", "network.proxy.socks_port": testvars.get("proxyPort", 90000), "network.proxy.socks_remote_dns": True, "network.proxy.type": 1, # Socks # Don't open the first-run dialog, it loads a video 'startup.homepage_welcome_url': '', 'startup.homepage_override_url': '', 'browser.newtab.url': 'about:blank', # make sure e10s is enabled "browser.tabs.remote.autostart": e10s, "browser.tabs.remote.autostart.1": e10s, "browser.tabs.remote.autostart.2": e10s, # We're not testing flash memory usage. Also: it likes to crash in VNC sessions. "plugin.disable": True, # Specify a communications port "marionette.defaultPrefs.port": self.port, # override image expiration in hopes of getting less volatile numbers "image.mem.surfacecache.min_expiration_ms": 10000 } # Setup a test runner with our prefs and a default logger. # TODO(ER): We might want to use a larger set of "automation" preferences # until marionette sets them for us. See bug 1123683. profile = mozprofile.FirefoxProfile(preferences=prefs) debug = testvars.get("debug", False) if debug: commandline.formatter_option_defaults['level'] = 'debug' logger = commandline.setup_logging("MarionetteTest", {}) runner = MarionetteTestRunner(binary=self.tester.binary, profile=profile, logger=logger, address="localhost:%d" % self.port, gecko_log=self.gecko_log, startup_timeout=60) # Add test testpath = os.path.join(*testvars['test']) if not os.path.exists(testpath): return self.error( "Test '%s' specifies a test that doesn't exist: %s" % (testname, testpath)) # Add our testvars runner.testvars.update(testvars) # Run test self.info("Marionette - starting browser") try: self.info("Marionette - running test") runner.run_tests([testpath]) failures = runner.failed except Exception, e: try: runner.cleanup() except: pass return self.error("Marionette test run failed -- %s: %s" % (type(e), e))
def run_test(self, testname, testvars={}): if not self.ready: return self.error("run_test() called before setup") self.info("Beginning marionette test '%s'" % testname) e10s = testvars.get("e10s", False) prefs = { # disable network access "network.proxy.socks": "localhost", "network.proxy.socks_port": testvars.get("proxyPort", 90000), "network.proxy.socks_remote_dns": True, "network.proxy.type": 1, # Socks # Don't open the first-run dialog, it loads a video 'startup.homepage_welcome_url': '', 'startup.homepage_override_url': '', 'browser.newtab.url': 'about:blank', # make sure e10s is enabled "browser.tabs.remote.autostart": e10s, "browser.tabs.remote.autostart.1": e10s, "browser.tabs.remote.autostart.2": e10s, # We're not testing flash memory usage. Also: it likes to crash in VNC sessions. "plugin.disable": True, # Specify a communications port "marionette.defaultPrefs.port": self.port, # override image expiration in hopes of getting less volatile numbers "image.mem.surfacecache.min_expiration_ms": 10000 } # Setup a test runner with our prefs and a default logger. # TODO(ER): We might want to use a larger set of "automation" preferences # until marionette sets them for us. See bug 1123683. profile = mozprofile.FirefoxProfile(preferences=prefs) debug = testvars.get("debug", False) if debug: commandline.formatter_option_defaults['level'] = 'debug' logger = commandline.setup_logging("MarionetteTest", {}) runner = MarionetteTestRunner( binary=self.tester.binary, profile=profile, logger=logger, address="localhost:%d" % self.port, gecko_log=self.gecko_log, startup_timeout=60) # Add test testpath = os.path.join(*testvars['test']) if not os.path.exists(testpath): return self.error("Test '%s' specifies a test that doesn't exist: %s" % (testname, testpath)) # Add our testvars runner.testvars.update(testvars) # Run test self.info("Marionette - starting browser") try: self.info("Marionette - running test") runner.run_tests([ testpath ]) failures = runner.failed except Exception, e: try: runner.cleanup() except: pass return self.error("Marionette test run failed -- %s: %s" % (type(e), e))