Beispiel #1
0
    def test_find_browser_mock(self):
        class MockBrowserWin(Browser):
            name = "mockbrowserwin"
            platform = "win"
            nopath = True

        class MockBrowserMac(Browser):
            name = "mockbrowsermac"
            platform = "mac"
            executable = "mockexecutable"
            nopath = True

        old_browser_classes = browsers_manager.browser_classes
        browsers_manager.browser_classes = [MockBrowserWin, MockBrowserMac]

        browser_info = BrowserInfo(name="nonexistent-browser")
        self.assertRaises(BrowserException, browsers_manager.find_browser,
                          browser_info)

        browser_info = BrowserInfo(name="mockbrowserwin", platform="win")
        browser = browsers_manager.find_browser(browser_info)
        self.assertEqual(type(browser), MockBrowserWin)

        browser_info = BrowserInfo(name="mockbrowsermac", platform="mac")
        browser = browsers_manager.find_browser(browser_info)
        self.assertEqual(type(browser), MockBrowserMac)

        browser_info = BrowserInfo(name="mockbrowsermac",
                                   path="/nonexistent-path/mockexecutable",
                                   platform="mac")
        self.assertRaises(BrowserException, browsers_manager.find_browser,
                          browser_info)

        browser_info = BrowserInfo(name="mockbrowsermac",
                                   path="/nonexistent-path/mockexecutable",
                                   platform="mac")
        self.assertRaises(BrowserException, browsers_manager.find_browser,
                          browser_info)

        mockexecutable = os.path.join(os.path.dirname(__file__),
                                      "mockexecutable")
        browser_info = BrowserInfo(name="mockbrowsermac", path=mockexecutable,
                                   platform="mac")
        browser = browsers_manager.find_browser(browser_info)
        self.assertEqual(type(browser), MockBrowserMac)

        browser_info = BrowserInfo(path=mockexecutable, platform="mac")
        browser = browsers_manager.find_browser(browser_info)
        self.assertEqual(type(browser), MockBrowserMac)

        browsers_manager.browser_classes = old_browser_classes
Beispiel #2
0
 def test_browsers(self):
     for browser_name in utils.browser_names_to_test():
         log.info("**** Testing browser %s", browser_name)
         browser_info = BrowserInfo(name=browser_name)
         browser = browsers_manager.find_browser(
             BrowserInfo(name=browser_name))
         self._do_test_browser(browser)
Beispiel #3
0
    def _post_init(self):
        if self.options.browser:
            # Batch mode is active if there's a browser to control.
            self.batch = True

            name = path = None
            if len(os.path.split(self.options.browser)) > 1:
                name = self.options.browser
            else:
                path = self.options.browser

            browser_info = BrowserInfo(name=name, path=path)
            self.browser = browsers_manager.find_browser(browser_info)
            log.info("Using browser: %s", self.browser)

        store_info = self._options_to_store_info(self.options)

        if self.batch:
            if not store_info:
                raise Exception("No tests to load. You should specify options "
                                "for test loading such as --tests-path or "
                                "--username and --token")
            self.test_store = self._create_store(store_info)
            threading.Thread(target=self._main_loop).start()
        else:
            if store_info:
                self.load_tests(store_info)

            log.info("The runner is started. You should now point your "
                     "browser to http://localhost:8888/")
            self.status = STOPPED

        self.running = True
        if not self.start_loop:
            return

        try:
            while self.running:
                time.sleep(1)
        except KeyboardInterrupt:
            # If not killed other thread will keep it running
            if hasattr(os, "kill"):
                os.kill(os.getpid(), signal.SIGKILL)
            sys.exit()
        log.info("End of main()")
        self.end_event.set()
Beispiel #4
0
 def is_browser_available(browser_name):
     try:
         browsers_manager.find_browser(BrowserInfo(name=browser_name))
     except BrowserException, e:
         return False
Beispiel #5
0
    def test_find_browser_system(self):
        browser_checks = [
            # Windows
            {
                "name": "firefox",
                "path": os.path.expandvars(r"%PROGRAMFILES%\Mozilla Firefox\firefox.exe"),
                "class": w3testrunner.browsers.firefox.FirefoxWin,
            },
            {
                "name": "opera",
                "path": os.path.expandvars(r"%PROGRAMFILES%\Opera\opera.exe"),
                "class": w3testrunner.browsers.opera.OperaWin,
            },
            {
                "name": "safari",
                "path": os.path.expandvars(r"%PROGRAMFILES%\Safari\Safari.exe"),
                "class": w3testrunner.browsers.safari.SafariWin,
            },
            {
                "name": "chrome",
                # XXX there's no LOCALAPPDATA on XP.
                "path": os.path.expandvars(r"%LOCALAPPDATA%\Google\Chrome\Application\chrome.exe"),
                "class": w3testrunner.browsers.chrome.ChromeWin,
            },
            {
                "name": "ie",
                "path": os.path.expandvars(r"%PROGRAMFILES%\Internet Explorer\iexplore.exe"),
                "class": w3testrunner.browsers.ie.IE,
            },
            # Linux
            {
                "name": "firefox",
                "path": "/usr/bin/firefox",
                "class": w3testrunner.browsers.firefox.FirefoxLin,
            },
            {
                "name": "opera",
                "path": "/usr/bin/opera",
                "class": w3testrunner.browsers.opera.OperaLin,
            },
            {
                "name": "chrome",
                "path": "/usr/bin/google-chrome",
                "class": w3testrunner.browsers.chrome.ChromeLin,
            },
            # Mac
            {
                "name": "firefox",
                "path": "/Applications/Firefox.app/Contents/MacOS/firefox-bin",
                "class": w3testrunner.browsers.firefox.FirefoxMac,
            },
            {
                "name": "opera",
                "path": "/Applications/Opera.app/Contents/MacOS/Opera",
                "class": w3testrunner.browsers.opera.OperaMac,
            },
            {
                "name": "safari",
                "path": "/Applications/Safari.app/Contents/MacOS/Safari",
                "class": w3testrunner.browsers.safari.SafariMac,
            },
            {
                "name": "chrome",
                "path": "/Applications/Google Chrome.app/Contents/MacOS/"
                        "Google Chrome",
                "class": w3testrunner.browsers.chrome.ChromeMac,
            },
        ]

        for browser_check in browser_checks:
            if not os.path.exists(browser_check["path"]):
                log.debug("Skipping browser %s (path %r not found)",
                          browser_check["name"], browser_check["path"])
                continue

            def assert_browser_equals(browser, browser_check):
                self.assertEqual(type(browser), browser_check["class"])
                self.assertEqual(browser.browser_info.name,
                                 browser_check["name"])
                self.assertEqual(browser.browser_info.path.lower(),
                                 browser_check["path"].lower())

            # Find browser by name
            browser_info = BrowserInfo(name=browser_check["name"])
            browser = browsers_manager.find_browser(browser_info)
            assert_browser_equals(browser, browser_check)

            # Find browser by path
            browser_info = BrowserInfo(path=browser_check["path"])
            browser = browsers_manager.find_browser(browser_info)
            assert_browser_equals(browser, browser_check)

            # Find browser by name and path
            browser_info = BrowserInfo(name=browser_check["name"],
                                       path=browser_check["path"])
            browser = browsers_manager.find_browser(browser_info)
            assert_browser_equals(browser, browser_check)
Beispiel #6
0
 def test_find_browser_dummy(self):
     browser_info = BrowserInfo(name="dummy")
     browser = browsers_manager.find_browser(browser_info)
     self.assertEqual(type(browser),
                      w3testrunner.browsers.dummy.DummyBrowser)