Beispiel #1
0
 def test_default_args_mac(self):
     """
     Mac google chrome does not support --no-sandbox option
     """
     browser_config = BrowserConfig(
         running_os=SupportedOS.mac, browser_window=BrowserWindow(),
     )
     assert "--no-sandbox" not in browser_config.default_args()
Beispiel #2
0
 def test_default_args_linux(self):
     """
     Linux google chrome requires --no-sandbox option if runing as root
     - by default linux boxes (docker) use root profile when connecting to them
     """
     browser_config = BrowserConfig(
         running_os=SupportedOS.linux, browser_window=BrowserWindow(),
     )
     assert "--no-sandbox" in browser_config.default_args()
Beispiel #3
0
 def test_chrome_launch_options_defaults(self):
     window = BrowserWindow()
     config = BrowserConfig(running_os=SupportedOS.linux, browser_window=window)
     chrome_launch_options = config.chrome_launch_options()
     assert chrome_launch_options["ignoreHTTPSErrors"] == True
     assert chrome_launch_options["userDataDir"] == config.browser_profile_path
     assert chrome_launch_options["ignoreDefaultArgs"] == [
         "--enable-automation",
         "--mute-audio",
         "--hide-scrollbars",
     ]
     assert "executablePath" in chrome_launch_options
     assert chrome_launch_options["defaultViewport"] == window.view_port
Beispiel #4
0
 def test_creates_browser_data_path(self):
     create_pat_mock = Mock()
     with patch("bopbot.browser.launcher.create_path", create_pat_mock):
         config = BrowserConfig(
             running_os=SupportedOS.linux, browser_window=BrowserWindow
         )
     create_pat_mock.assert_called_with(path=config.browser_profile_path)
Beispiel #5
0
 def test_validate_headless(self):
     browser_config = BrowserConfig(
         running_os=SupportedOS.mac,
         browser_window=BrowserWindow(),
         xvfb_headless=True,
     )
     assert browser_config.xvfb_headless == False
     assert browser_config.native_headless == True
Beispiel #6
0
 def test_detect_running_os(self):
     detected_os = identify_running_os()
     get_chrome_path_mock = Mock()
     with patch("bopbot.browser.launcher.get_chrome_path", get_chrome_path_mock):
         browser_config = BrowserConfig(
             browser_window=BrowserWindow(), xvfb_headless=True,
         )
         assert detected_os == browser_config.running_os
         get_chrome_path_mock.assert_called_with(running_os=detected_os)
Beispiel #7
0
 def test_options_sync_chrome_config(self):
     browser_config = BrowserConfig(
         running_os=SupportedOS.mac,
         browser_window=BrowserWindow(),
         native_headless=True,
     )
     launcher = ChromeLauncher(chrome_config=browser_config)
     expected = browser_config.chrome_launch_options()
     assert launcher.chromeExecutable == browser_config.exe_path
     assert launcher.ignoreHTTPSErrors == expected["ignoreHTTPSErrors"]
     assert (
         f"--user-data-dir={browser_config.browser_profile_path}"
         in launcher.chromeArguments
     )
     # verify we're omiting the default arguments
     for ignore_arg in expected["ignoreDefaultArgs"]:
         assert ignore_arg not in launcher.chromeArguments
     # verify the needed arguments are present
     for required_arg in expected["args"]:
         assert required_arg in launcher.chromeArguments
Beispiel #8
0
    def test_native_headless_launch_cmd(self):
        browser_config = BrowserConfig(
            running_os=SupportedOS.mac,
            browser_window=BrowserWindow(),
            native_headless=True,
        )
        launcher = ChromeLauncher(chrome_config=browser_config)
        launch_cmd = launcher._launch_cmd()

        assert "xvfb-run" not in launch_cmd
        assert "--headless" in launch_cmd
Beispiel #9
0
 def test_debug_flag_option(self):
     config = BrowserConfig(
         running_os=SupportedOS.linux, browser_window=BrowserWindow(), devtools=True,
     )
     assert config.chrome_launch_options()["devtools"] is True
Beispiel #10
0
 def test_window_flag_option(self):
     window = BrowserWindow()
     config = BrowserConfig(running_os=SupportedOS.linux, browser_window=window)
     assert window.as_arg_option() in config.default_args()
Beispiel #11
0
 def test_default_loop(self):
     browser_config = BrowserConfig(browser_window=BrowserWindow())
     launcher = ChromeLauncher(chrome_config=browser_config)
     assert launcher._loop is not None
Beispiel #12
0
def get_default_bot(headless_mode=True):
    chrome_config = BrowserConfig(browser_window=BrowserWindow(),
                                  xvfb_headless=headless_mode)
    chrome_driver = RawDriver(chrome_config=chrome_config)
    return BaseAction(driver=chrome_driver)