Exemplo n.º 1
0
    def managed_driver() -> WebDriver:
        from selenium import webdriver

        def create_chrome():
            from selenium.webdriver.chrome.service import (
                Service as ChromeService, )

            return webdriver.Chrome(
                service=ChromeService(
                    ChromeDriverManager(
                        chrome_type=ChromeType.GOOGLE).install()),
                options=webdriver.ChromeOptions(),
            )

        # if _driver and Help(_driver).has_browser_still_alive():
        #     return _driver
        #
        # _driver = create_chrome()

        if (Settings.reset_driver and Settings.driver
                and WebHelper(Settings.driver).is_browser_still_alive()):
            Settings.driver.quit()
            Settings.reset_driver = False

        if (Settings.driver is None
                or not WebHelper(Settings.driver).is_browser_still_alive()):
            Settings.driver = create_chrome()

        return Settings.driver
Exemplo n.º 2
0
def test_automatic_quit_for_previous_driver():
    driver_from_test_d = browser.config.driver
    assert WebHelper(driver_from_test_d).is_browser_still_alive() is True

    browser.config.driver = webdriver.Chrome(
        service=Service(
            ChromeDriverManager(chrome_type=ChromeType.GOOGLE).install()
        )
    )

    assert WebHelper(driver_from_test_d).is_browser_still_alive() is False
    assert WebHelper(browser.driver).is_browser_still_alive() is True
Exemplo n.º 3
0
        def save_and_log_page_source(error: TimeoutException) -> Exception:
            filename = (self.last_screenshot.replace('.png', '.html')
                        if self.last_screenshot else self.generate_filename(
                            suffix='.html'))
            path = WebHelper(self.driver).save_page_source(filename)
            self.last_page_source = path
            return TimeoutException(error.msg + f'''
PageSource: file://{path}''')
Exemplo n.º 4
0
def test_no_hold_on_default_false():
    browser.open('http://todomvc.com/examples/emberjs/')
    driver = browser.driver
    browser.element('#new-todo').type('a').press_enter()

    atexit._run_exitfuncs()

    assert not WebHelper(driver).is_browser_still_alive()
Exemplo n.º 5
0
    def save_page_source(self, file: str = None) -> Optional[str]:
        # warnings.warn('browser.save_page_source(file) might be deprecated in future', FutureWarning)

        if not file:
            file = self.config.generate_filename(suffix='.html')

        saved_file = WebHelper(self.driver).save_page_source(file)

        self.config.last_page_source = saved_file

        return saved_file
Exemplo n.º 6
0
    def save_screenshot(self, file: str = None):
        # warnings.warn('browser.save_screenshot might be deprecated', FutureWarning)

        if not file:
            file = self.config.generate_filename(suffix='.png')
        if file and not file.lower().endswith('.png'):
            file = os.path.join(file, f'{next(self.config.counter)}.png')
        folder = os.path.dirname(file)
        if not os.path.exists(folder) and folder:
            os.makedirs(folder)
        # todo: refactor to catch errors smartly in get_screenshot_as_file. or not needed?
        self.config.last_screenshot = WebHelper(self.driver).save_screenshot(
            file
        )

        return self.config.last_screenshot
Exemplo n.º 7
0
 def has_browser_alive(self):
     return WebHelper(self._stored).is_browser_still_alive()
Exemplo n.º 8
0
        def save_and_log_screenshot(error: TimeoutException) -> Exception:
            path = WebHelper(self.driver).save_screenshot(
                self.generate_filename(suffix='.png'))
            self.last_screenshot = path
            return TimeoutException(error.msg + f'''
Screenshot: file://{path}''')