|
2 | 2 | Some sites use scripts to detect Selenium, and then block you. |
3 | 3 | To evade detection, add --uc as a pytest command-line option.""" |
4 | 4 | from seleniumbase import BaseCase |
| 5 | +from seleniumbase import DriverContext |
5 | 6 | BaseCase.main(__name__, __file__, "--uc", "-s") |
6 | 7 |
|
7 | 8 |
|
8 | 9 | class UndetectedTest(BaseCase): |
9 | 10 | def test_browser_is_undetected(self): |
10 | 11 | url = "https://gitlab.com/users/sign_in" |
11 | 12 | if not self.undetectable: |
12 | | - self.get_new_driver(undetectable=True) |
13 | | - self.uc_open_with_reconnect(url, 4) |
14 | | - self.uc_gui_click_captcha() |
15 | | - self.assert_text("Username", '[for="user_login"]', timeout=3) |
16 | | - self.post_message("SeleniumBase wasn't detected", duration=4) |
17 | | - self._print("\n Success! Website did not detect Selenium! ") |
| 13 | + with DriverContext(uc=True) as driver: |
| 14 | + driver.uc_activate_cdp_mode(url) |
| 15 | + driver.uc_gui_click_captcha() |
| 16 | + driver.assert_text("Username", '[for="user_login"]', timeout=3) |
| 17 | + print("\n Success! Website did not detect Selenium! ") |
| 18 | + else: |
| 19 | + self.activate_cdp_mode(url) |
| 20 | + self.uc_gui_click_captcha() |
| 21 | + self.assert_text("Username", '[for="user_login"]', timeout=3) |
| 22 | + self.post_message("SeleniumBase wasn't detected", duration=4) |
| 23 | + self._print("\n Success! Website did not detect Selenium! ") |
0 commit comments