コード例 #1
0
    def test_remote_chrome_with_custom_capabilities_chomeoptions_and_with_options(
            self):
        capabilities = {
            "browserName": "chrome",
            "version": "ANY",
            "platform": "ANY",
            "goog:chromeOptions": {
                "args": ["--disable-gpu", "--no-sandbox"],
                "extensions": [],
                "prefs": {}
            }
        }

        option = {
            "highlight": True,
            "headless": True,
            "resolution": "maximum",
            "mobileEmulation": "iPhone X"
        }
        DriverRegistry.register_driver(local=False,
                                       capabilities=capabilities,
                                       options=option)
        self.assertIsInstance(DriverRegistry.get_driver(), BrowserDriver)
        self.assertIsInstance(DriverRegistry.get_webdriver(), WebDriver)
        self.assertEqual(DriverRegistry.get_driver().name, DriverTypes.CHROME)
        DriverRegistry.deregister_driver()
        self.assertIsNone(DriverRegistry.get_driver(),
                          'Error: Driver found without registration')
コード例 #2
0
 def test_remote_ff_driver_registration(self):
     DriverRegistry.register_driver(DriverTypes.FIREFOX, local=False)
     self.assertIsInstance(DriverRegistry.get_driver(), BrowserDriver)
     self.assertIsInstance(DriverRegistry.get_webdriver(), WebDriver)
     self.assertEqual(DriverRegistry.get_driver().name, DriverTypes.FIREFOX)
     DriverRegistry.deregister_driver()
     self.assertIsNone(DriverRegistry.get_driver(),
                       'Error: Driver found without registration')
コード例 #3
0
 def test_default_chrome_local_driver_creation(self):
     DriverRegistry.register_driver()
     self.assertIsInstance(DriverRegistry.get_driver(), BrowserDriver)
     self.assertIsInstance(DriverRegistry.get_webdriver(), WebDriver)
     self.assertEqual(DriverRegistry.get_driver().name, DriverTypes.CHROME)
     DriverRegistry.deregister_driver()
     self.assertIsNone(DriverRegistry.get_driver(),
                       'Error: Driver found without registration')
コード例 #4
0
 def test_ff_headless_local_driver_registration(self):
     option = {"highlight": True, "headless": True, "resolution": "maximum"}
     DriverRegistry.register_driver("firefox", options=option)
     self.assertIsInstance(DriverRegistry.get_driver(), BrowserDriver)
     self.assertIsInstance(DriverRegistry.get_webdriver(), WebDriver)
     self.assertEqual(DriverRegistry.get_driver().name, DriverTypes.FIREFOX)
     DriverRegistry.deregister_driver()
     self.assertIsNone(DriverRegistry.get_driver(),
                       'Error: Driver found without registration')
コード例 #5
0
 def test_default_chrome_headless_local_driver_creation(self):
     option = {"highlight": True, "headless": True, "resolution": "maximum"}
     DriverRegistry.register_driver(options=option)
     self.assertIsInstance(DriverRegistry.get_driver(), BrowserDriver)
     self.assertIsInstance(DriverRegistry.get_webdriver(), WebDriver)
     self.assertEqual(DriverRegistry.get_driver().name, DriverTypes.CHROME)
     DriverRegistry.deregister_driver()
     self.assertIsNone(DriverRegistry.get_driver(),
                       'Error: Driver found without registration')
コード例 #6
0
 def test_remote_chrome_headless_driver_registration_with_capabilities(
         self):
     option = {"highlight": True, "headless": True, "resolution": "maximum"}
     DriverRegistry.register_driver(DriverTypes.CHROME,
                                    local=False,
                                    options=option)
     self.assertIsInstance(DriverRegistry.get_driver(), BrowserDriver)
     self.assertIsInstance(DriverRegistry.get_webdriver(), WebDriver)
     self.assertEqual(DriverRegistry.get_driver().name, DriverTypes.CHROME)
     DriverRegistry.deregister_driver()
     self.assertIsNone(DriverRegistry.get_driver(),
                       'Error: Driver found without registration')
コード例 #7
0
 def test_registering_multiple_drivers(self):
     DriverRegistry.register_driver(DriverTypes.CHROME, local=False)
     current_driver = DriverRegistry.get_driver()
     new_driver = DriverRegistry.register_driver(DriverTypes.FIREFOX)
     self.assertIsNotNone(
         new_driver, "Error: Should return previously registered driver")
     self.assertEqual(
         current_driver, new_driver,
         "Error: Should return same driver instance created before")
     DriverRegistry.deregister_driver()
     self.assertIsNone(DriverRegistry.get_driver(),
                       'Error: Driver found without registration')
     self.assertIsNone(DriverRegistry.get_webdriver(),
                       'Error: Webdriver found without registration')
コード例 #8
0
 def test_custom_local_driver_registration(self):
     test_capabilities = {
         "browserName": "firefox",
         "platform": 'LINUX',
         "version": '',
         "javascriptEnabled": True
     }
     DriverRegistry.register_driver(DriverTypes.FIREFOX,
                                    capabilities=test_capabilities)
     self.assertIsInstance(DriverRegistry.get_driver(), BrowserDriver)
     self.assertIsInstance(DriverRegistry.get_webdriver(), WebDriver)
     self.assertEqual(DriverRegistry.get_driver().name, DriverTypes.FIREFOX)
     DriverRegistry.deregister_driver()
     self.assertIsNone(DriverRegistry.get_driver(),
                       'Error: Driver found without registration')
コード例 #9
0
 def stop_browser(self):
     """
     Stop the browser instance
     """
     if DriverRegistry.get_driver():
         DriverRegistry.deregister_driver()
         self._driver = None
コード例 #10
0
 def start_browser(self,
                   headless=False,
                   resolution="maximum",
                   mobileEmulation=""):
     """
     Start the browser in a grid with proxy setup
     :param bool headless: run browser in headless mode
     :param str resolution: maximum or width * height
     :param str mobileEmulation: chrome emulation mode e.g. iPhone X, Samsung Galaxy S5 etc
     :return: Framework driver wrapper
     """
     proxy_server_arg = "--proxy-server={0}".format(self._client.proxy)
     options = {
         "highlight": False,
         "headless": headless,
         "resolution": resolution,
         "mobileEmulation": mobileEmulation
     }
     self._capabilities["goog:chromeOptions"] = {
         "args":
         [proxy_server_arg, '--ignore-certificate-errors', '--test-type']
     }
     DriverRegistry.register_driver(DriverTypes.CHROME,
                                    capabilities=self._capabilities,
                                    local=False,
                                    options=options,
                                    grid_url=self._grid_url)
     self._driver = DriverRegistry.get_driver()
コード例 #11
0
    def test_remote_chrome_with_capabilities_and_with_options(self):
        capabilities = {
            "browserName": "chrome",
            "version": "ANY",
            "platform": "ANY"
        }

        option = {
            "highlight": True,
            "headless": True,
            "resolution": "maximum",
            "mobileEmulation": "iPhone X"
        }
        DriverRegistry.register_driver(local=False,
                                       capabilities=capabilities,
                                       options=option)
        self.assertIsInstance(DriverRegistry.get_driver(), BrowserDriver)
        self.assertIsInstance(DriverRegistry.get_webdriver(), WebDriver)
        self.assertEqual(DriverRegistry.get_driver().name, DriverTypes.CHROME)
        DriverRegistry.deregister_driver()
        self.assertIsNone(DriverRegistry.get_driver(),
                          'Error: Driver found without registration')
コード例 #12
0
 def take_screenshot(self):
     DriverRegistry.register_driver(DriverTypes.CHROMEHEADLESS, local=False)
     driver = DriverRegistry.get_driver()
     for url in self.urls_json["urls"]:
         driver.goto_url(url["url"], absolute=True)
         for device in self._devices_list:
             driver.set_window_size(
                 self.devices_json[device]["w"], self.devices_json[device]["h"])
             filename = "%s_%s_%s.png" % (url["name"].replace(" ", ""), device,
                                          datetime.now().strftime("%Y%m%d-%H%M%S"))
             driver.take_screenshot_current_window(
                 self._folder + "/%s" % filename)
     DriverRegistry.deregister_driver()
コード例 #13
0
 def start_browser(self,
                   headless=False,
                   resolution="maximum",
                   mobileEmulation=""):
     """
     Starts local chrome browser with proxy configured
     :param bool headless: run browser in headless mode
     :param str resolution: maximum or width * height
     :param str mobileEmulation: chrome emulation mode e.g. iPhone X, Samsung Galaxy S5 etc
     :return: Framework driver wrapper
     """
     proxy_server_arg = "--proxy-server={0}".format(self._client.proxy)
     capabilities = {
         "browserName": "chrome",
         "version": "ANY",
         "platform": "ANY",
         "goog:chromeOptions": {
             "args": [
                 proxy_server_arg, '--ignore-certificate-errors',
                 '--test-type'
             ],
             "extensions": [],
             "prefs": {}
         }
     }
     options = {
         "highlight": False,
         "headless": headless,
         "resolution": resolution,
         "mobileEmulation": mobileEmulation
     }
     DriverRegistry.register_driver(DriverTypes.CHROME,
                                    capabilities=capabilities,
                                    options=options,
                                    local=True)
     self._driver = DriverRegistry.get_driver()
コード例 #14
0
 def setUpClass(cls):
     DriverRegistry.register_driver(DriverTypes.CHROME, local=False)
     cls.driver = DriverRegistry.get_driver()
     cls.driver.goto_url(cls.TEST_URL, absolute=True)
コード例 #15
0
ファイル: basepage.py プロジェクト: longlylove/nzme-skynet
 def driver(self):
     # type: () -> BaseDriver
     return DriverRegistry.get_driver()
コード例 #16
0
 def test_no_driver_registered_exception(self):
     self.assertIsNone(DriverRegistry.get_driver(),
                       'Error: Driver found without registration')
コード例 #17
0
def driver_setup(request):
    DriverRegistry.register_driver(driver_type=request.param, local=False)
    driver = DriverRegistry.get_driver()
    yield driver
    DriverRegistry.deregister_driver()
コード例 #18
0
ファイル: basetest.py プロジェクト: longlylove/nzme-skynet
def before_scenario(context, scenario):
    """
    Open app instance form a browser
    :param context: behave.runner.Context
    :param scenario: behave.model.Scenario
    """
    Logger.create_test_folder(scenario.name)
    context.test_name = scenario.name
    # cleanup app state for new test
    if context.driver is not None:
        try:
            DriverRegistry.deregister_driver()
            context.driver = None
        except Exception:
            logger.exception('Failed to stop browser instance')
            raise

    tags = str(context.config.tags)
    try:
        logger.debug("Building driver..")
        if 'api' not in tags:
            if 'android' in tags or 'ios' in tags:
                # Mobile tests
                if 'android-browser' in tags:
                    context.driver = DriverRegistry.register_driver(
                        DriverTypes.ANDROIDWEB,
                        capabilities=context.android_capabilities,
                        grid_url=context.selenium_grid_hub)
                elif 'ios-browser' in tags:
                    context.driver = DriverRegistry.register_driver(
                        DriverTypes.IOSWEB,
                        capabilities=context.ios_capabilities,
                        grid_url=context.selenium_grid_hub)
                elif 'android-app' in tags:
                    context.driver = DriverRegistry.register_driver(
                        DriverTypes.ANDROID,
                        capabilities=context.android_capabilities,
                        grid_url=context.selenium_grid_hub)
                elif 'ios-app' in tags:
                    context.driver = DriverRegistry.register_driver(
                        DriverTypes.IOS,
                        capabilities=context.ios_capabilities,
                        grid_url=context.selenium_grid_hub)
                else:
                    logger.exception(
                        "Only supports tags @android-app, @android-browser, @ios-app, @ios-browser"
                    )
                    raise Exception(
                        "Only supports tags @android-app, @android-browser, @ios-app, @ios-browser"
                    )
            else:
                # Desktop browser tests
                # Add Feature and Scenario name for grouping Zalenium Test
                # https://github.com/zalando/zalenium/blob/master/docs/usage_examples.md#test-name
                if not context.local and context.zalenium:
                    context.browser_capabilities['name'] = context.test_name
                DriverRegistry.register_driver(
                    driver_type=context.browser_capabilities['browserName'],
                    capabilities=context.browser_capabilities,
                    local=context.local,
                    grid_url=context.selenium_grid_hub,
                    options=context.options)
            context.driver = DriverRegistry.get_driver()
            context.driver.baseurl = context.testurl
    except Exception:
        logger.exception("Failed building the driver")
        raise

    logger.info('Start of Scenario: {}'.format(scenario.name))