Skip to content

Updates for UC Mode and more #2283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ pytest test_coffee_cart.py --trace
--message-duration=SECONDS # (The time length for Messenger alerts.)
--check-js # (Check for JavaScript errors after page loads.)
--ad-block # (Block some types of display ads from loading.)
--host-resolver-rules=RULES # (Set host-resolver-rules, comma-separated.)
--block-images # (Block images from loading during tests.)
--do-not-track # (Indicate to websites that you don't want to be tracked.)
--verify-delay=SECONDS # (The delay before MasterQA verification checks.)
Expand Down
42 changes: 29 additions & 13 deletions examples/presenter/edge_presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_presentation(self):
self.play_tour()
self.sleep(0.25)
self.open("data:,")
self.create_presentation(theme="sky", transition="fade")
self.create_presentation(theme="beige", transition="fade")
self.add_slide(
"<p><b>About the presenter:</b></p>\n"
"<ul>\n"
Expand Down Expand Up @@ -153,24 +153,40 @@ def test_presentation(self):
self.play_tour()
self.highlight('[href*="microsoft-edge/tools/webdriver"]')

self.get_new_driver(browser="edge")
self.get_new_driver(browser="edge", disable_csp=True)
self.maximize_window()
self.open(
"https://developer.microsoft.com/en-us/"
"microsoft-edge/tools/webdriver/"
)
self.wait_for_element("#page-heading")
self.scroll_to("#page-heading")
zoom_in = '#page-heading{zoom: 1.2;-moz-transform: scale(1.2);}'
self.wait_for_element("div.common-heading")
self.scroll_to("div.common-heading")
zoom_in = 'div.h1{zoom: 1.02;-moz-transform: scale(1.02);}'
self.add_css_style(zoom_in)
self.highlight("#page-heading", loops=8)
self.sleep(1.2)
self.highlight("#downloads-channel", loops=8)
self.sleep(1.2)
self.highlight("#downloads", loops=12)
self.sleep(1.8)
self.highlight("#installation", loops=12)
self.sleep(1.8)
self.highlight("div.common-heading", loops=8)
self.create_tour(theme="driverjs")
self.add_tour_step(
"", "div.common-heading", alignment="left"
)
self.play_tour()
self.highlight('div[data-fetch-key="block-web-driver:0"]', loops=12)
self.create_tour(theme="driverjs")
self.add_tour_step(
"", 'div[data-fetch-key="block-web-driver:0"]', alignment="top"
)
self.play_tour()
self.highlight('div[data-fetch-key="block-web-driver:1"]', loops=12)
self.create_tour(theme="driverjs")
self.add_tour_step(
"", 'div[data-fetch-key="block-web-driver:1"]', alignment="top"
)
self.play_tour()
self.highlight('section[data-section-id="installation"]', loops=12)
self.create_tour(theme="driverjs")
self.add_tour_step(
"", "div.block-heading--sixtyforty", alignment="left"
)
self.play_tour()
self.quit_extra_driver()

self.switch_to_default_driver()
Expand Down
4 changes: 2 additions & 2 deletions examples/presenter/multi_uc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

@pytest.mark.parametrize("", [[]] * 3)
def test_multi_threaded(sb):
sb.driver.get("https://nowsecure.nl/#relax")
sb.driver.uc_open_with_tab("https://nowsecure.nl/#relax")
sb.set_window_rect(randint(0, 755), randint(38, 403), 700, 500)
try:
sb.assert_text("OH YEAH, you passed!", "h1", timeout=4)
sb.post_message("Selenium wasn't detected!", duration=4)
sb._print("\n Success! Website did not detect Selenium! ")
except Exception:
sb.driver.get("https://nowsecure.nl/#relax")
sb.driver.uc_open_with_tab("https://nowsecure.nl/#relax")
try:
sb.assert_text("OH YEAH, you passed!", "h1", timeout=4)
sb.post_message("Selenium wasn't detected!", duration=4)
Expand Down
8 changes: 4 additions & 4 deletions examples/presenter/uc_presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ def test_presentation(self):

self.get_new_driver(undetectable=True)
try:
self.driver.get("https://nowsecure.nl/#relax")
self.driver.uc_open_with_tab("https://nowsecure.nl/#relax")
try:
self.assert_text("OH YEAH, you passed!", "h1", timeout=4)
self.post_message("Selenium wasn't detected!", duration=4)
except Exception:
self.clear_all_cookies()
self.driver.get("https://nowsecure.nl/#relax")
self.driver.uc_open_with_tab("https://nowsecure.nl/#relax")
self.assert_text("OH YEAH, you passed!", "h1", timeout=4)
self.post_message("Selenium wasn't detected!", duration=4)
finally:
Expand Down Expand Up @@ -355,10 +355,10 @@ def test_presentation(self):

try:
with SB(uc=True) as sb:
sb.driver.get("https://nowsecure.nl/#relax")
sb.driver.uc_open_with_tab("https://nowsecure.nl/#relax")
sb.sleep(1)
if not sb.is_text_visible("OH YEAH, you passed", "h1"):
sb.driver.get("https://nowsecure.nl/#relax")
sb.driver.uc_open_with_tab("https://nowsecure.nl/#relax")
sb.sleep(1)
sb.activate_demo_mode()
sb.assert_text("OH YEAH, you passed!", "h1", timeout=3)
Expand Down
4 changes: 1 addition & 3 deletions examples/raw_form_turnstile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ def open_the_form_turnstile_page(sb):


def click_turnstile_and_verify(sb):
iframe = sb.driver.find_element("iframe")
sb.driver.reconnect(0.1) # Another way to reconnect
sb.driver.switch_to.frame(iframe)
sb.driver.uc_switch_to_frame("iframe")
sb.driver.uc_click("span.mark")
sb.highlight("img#captcha-success", timeout=3.33)

Expand Down
1 change: 1 addition & 0 deletions examples/raw_parameter_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
sb._disable_beforeunload = False
sb.save_screenshot_after_test = False
sb.no_screenshot_after_test = False
sb.host_resolver_rules = None
sb.page_load_strategy = None
sb.timeout_multiplier = None
sb.pytest_html_report = None
Expand Down
4 changes: 1 addition & 3 deletions examples/raw_turnstile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ def open_the_turnstile_page(sb):


def click_turnstile_and_verify(sb):
iframe = sb.driver.find_element("iframe")
sb.driver.reconnect(0.1) # Another way to reconnect
sb.driver.switch_to.frame(iframe)
sb.driver.uc_switch_to_frame("iframe")
sb.driver.uc_click("span.mark")
sb.assert_element("img#captcha-success", timeout=3.33)

Expand Down
1 change: 1 addition & 0 deletions examples/test_chromedriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class ChromedriverTests(BaseCase):
def test_chromedriver_matches_chrome(self):
if self.browser != "chrome":
self.open_if_not_url("data:,")
print("\n This test is only for Chrome!")
print(' (Run with: "--browser=chrome")')
self.skip("This test is only for Chrome!")
Expand Down
5 changes: 5 additions & 0 deletions examples/test_verify_chromedriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ def test_fail_if_versions_dont_match(self):
print("\nWarning -> " + message)
elif int(major_chromedriver_version) != int(major_chrome_version):
raise Exception(message)
else:
print(
"\n* Chrome version: {%s}\n* Driver version: {%s}"
% (chromedriver_version, chrome_version)
)
1 change: 1 addition & 0 deletions help_docs/customizing_test_runs.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ pytest my_first_test.py --settings-file=custom_settings.py
--message-duration=SECONDS # (The time length for Messenger alerts.)
--check-js # (Check for JavaScript errors after page loads.)
--ad-block # (Block some types of display ads from loading.)
--host-resolver-rules=RULES # (Set host-resolver-rules, comma-separated.)
--block-images # (Block images from loading during tests.)
--do-not-track # (Indicate to websites that you don't want to be tracked.)
--verify-delay=SECONDS # (The delay before MasterQA verification checks.)
Expand Down
14 changes: 13 additions & 1 deletion help_docs/method_summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -993,10 +993,16 @@ driver.highlight_click(selector)

driver.sleep(seconds)

driver.locator(selector)

driver.get_attribute(selector, attribute)

driver.get_page_source()

driver.get_title()

driver.switch_to_frame(frame)

############

# "driver"-specific methods added by SeleniumBase for UC Mode: "--uc" / uc=True
Expand All @@ -1007,7 +1013,13 @@ driver.uc_open_with_tab(url)

driver.uc_open_with_reconnect(url, reconnect_time=None)

driver.uc_click(selector)
driver.reconnect(timeout)

driver.uc_click(
selector, by="css selector",
timeout=settings.SMALL_TIMEOUT, reconnect_time=None)

driver.uc_switch_to_frame(frame)
```

--------
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ nav:
- 🔑 CF Turnstile on Form: https://seleniumbase.io/apps/form_turnstile
- 🔐 reCAPTCHA v2 Test: https://seleniumbase.io/apps/recaptcha
- 🔐 reCAPTCHA v2 on Form: https://seleniumbase.io/apps/form_recaptcha
- 🔐 reCAPTCHA, invisible: https://seleniumbase.io/apps/invisible_recaptcha
- Additional Help Docs:
- 📑 Table of Contents: help_docs/ReadMe.md
- 🖼️ How to handle iframes: help_docs/handling_iframes.md
Expand Down
2 changes: 1 addition & 1 deletion mkdocs_build/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

regex>=2023.10.3
PyYAML>=6.0.1
pymdown-extensions>=10.3.1
pymdown-extensions>=10.4
pipdeptree>=2.13.1
python-dateutil>=2.8.2
Markdown==3.5.1
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ attrs>=23.1.0
certifi>=2023.7.22
filelock>=3.12.2;python_version<"3.8"
filelock>=3.13.1;python_version>="3.8"
platformdirs>=3.11.0
platformdirs>=4.0.0
parse>=1.19.1
parse-type>=0.6.2
six==1.16.0
idna==3.4
chardet==5.2.0
charset-normalizer==3.3.2
urllib3>=1.26.18,<2;python_version<"3.10"
urllib3>=1.26.18,<2.1.0;python_version>="3.10"
urllib3>=1.26.18,<2.2.0;python_version>="3.10"
requests==2.31.0
pynose==1.4.8
sniffio==1.3.0
Expand All @@ -40,7 +40,7 @@ pytest-html==2.0.1
pytest-metadata==3.0.0
pytest-ordering==0.6
pytest-rerunfailures==12.0
pytest-xdist==3.3.1
pytest-xdist==3.4.0
parameterized==0.9.0
sbvirtualdisplay==1.3.0
behave==1.2.6
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.21.1"
__version__ = "4.21.2"
8 changes: 8 additions & 0 deletions seleniumbase/behave/behave_sb.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def get_configured_sb(context):
sb.proxy_bypass_list = None
sb.proxy_pac_url = None
sb.multi_proxy = False
sb.host_resolver_rules = None
sb.enable_3d_apis = False
sb.swiftshader = False
sb.ad_block_on = False
Expand Down Expand Up @@ -772,6 +773,13 @@ def get_configured_sb(context):
if low_key in ["multi-proxy", "multi_proxy"]:
sb.multi_proxy = True
continue
# Handle: -D host-resolver-rules=RULES / host_resolver_rules=RULES
if low_key in ["host-resolver-rules", "host_resolver_rules"]:
host_resolver_rules = userdata[key]
if host_resolver_rules == "true":
host_resolver_rules = sb.host_resolver_rules
sb.host_resolver_rules = host_resolver_rules
continue
# Handle: -D enable-3d-apis / enable_3d_apis
if low_key in ["enable-3d-apis", "enable_3d_apis"]:
sb.enable_3d_apis = True
Expand Down
Loading