Skip to content

Some improvements #2257

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 13 commits into from
Nov 9, 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
10 changes: 9 additions & 1 deletion examples/boilerplates/samples/google_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
"""google.com example test that uses page objects"""
from seleniumbase import BaseCase
from .google_objects import HomePage, ResultsPage
try:
from .google_objects import HomePage, ResultsPage
except Exception:
from google_objects import HomePage, ResultsPage
BaseCase.main(__name__, __file__)


class GoogleTests(BaseCase):
def test_google_dot_com(self):
if self.headless and self._multithreaded:
self.open_if_not_url("about:blank")
print("Skipping test in headless multi-threaded mode.")
self.skip("Skipping test in headless multi-threaded mode.")
self.open("https://google.com/ncr")
self.assert_title_contains("Google")
self.sleep(0.05)
Expand Down
4 changes: 4 additions & 0 deletions examples/boilerplates/samples/test_page_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def do_search_and_click(self, sb, search_term):

class MyTests(BaseCase):
def test_page_objects(self):
if self.headless and self._multithreaded:
self.open_if_not_url("about:blank")
print("Skipping test in headless multi-threaded mode.")
self.skip("Skipping test in headless multi-threaded mode.")
search_term = "SeleniumBase.io Docs"
expected_text = "SeleniumBase"
GooglePage().go_to_google(self)
Expand Down
19 changes: 14 additions & 5 deletions examples/locale_code_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@

class LocaleCodeTests(BaseCase):
def test_locale_code(self):
self.open("https://localeplanet.com/support/browser.html")
locale_code = self.get_locale_code()
self.open("about:blank")
locale_code = self.get_locale_code() # navigator.language
print("\nYour Browser's Locale Code: %s" % locale_code)
expected_text = "navigator.language: %s" % locale_code
self.demo_mode = True # Display test actions
self.assert_text(expected_text, "pre")
if self.browser == "chrome" and not self.headless:
self.open("chrome://settings/languages")
language_info = self.get_text(
"settings-ui::shadow "
"settings-main::shadow "
"settings-basic-page::shadow "
"settings-languages-page::shadow "
"#languagesSection div.start div"
)
print("Language info (chrome://settings/languages):")
print(language_info)
self.sleep(1)
37 changes: 37 additions & 0 deletions examples/raw_form_turnstile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from seleniumbase import SB


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


with SB(uc=True, test=True) as sb:
sb.driver.uc_open_with_reconnect(
"https://seleniumbase.io/apps/form_turnstile",
reconnect_time=2.33,
)
try:
click_turnstile_and_verify(sb)
except Exception:
sb.driver.uc_open_with_reconnect(
"https://seleniumbase.io/apps/form_turnstile",
reconnect_time=2.33,
)
click_turnstile_and_verify(sb)
sb.press_keys("#name", "SeleniumBase")
sb.press_keys("#email", "[email protected]")
sb.press_keys("#phone", "1-555-555-5555")
sb.click('[for="date"]')
sb.click("td.is-today button")
sb.click('div[class="select-wrapper"] input')
sb.click('span:contains("9:00 PM")')
sb.highlight_click('input[value="AR"] + span')
sb.click('input[value="cc"] + span')
sb.highlight_click('button:contains("Request & Pay")')
sb.highlight("img#submit-success")
sb.highlight('button:contains("Success!")')
16 changes: 16 additions & 0 deletions examples/raw_turnstile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from seleniumbase import SB

with SB(uc=True, test=True) as sb:
sb.driver.uc_open_with_reconnect(
"https://seleniumbase.io/apps/turnstile",
reconnect_time=2.33,
)
sb.driver.reconnect(0.1)
iframe = sb.driver.find_element("iframe")
sb.driver.reconnect(0.5)
sb.driver.switch_to.frame(iframe)
sb.driver.uc_click("span.mark")
sb.switch_to_default_content()
sb.assert_element("img#captcha-success", timeout=3.33)
sb.set_messenger_theme(location="top_left")
sb.post_message("Selenium wasn't detected!", duration=3)
28 changes: 28 additions & 0 deletions examples/test_cdp_ad_blocking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from seleniumbase import BaseCase
BaseCase.main(__name__, __file__)


class CDPNetworkBlockingTests(BaseCase):
def test_cdp_network_blocking(self):
if not self.is_chromium:
self.skip("This test is only for Chromium browsers!")
self.execute_cdp_cmd(
'Network.setBlockedURLs', {"urls": [
"*googlesyndication.com*",
"*doubleclick.net*",
"*adsafeprotected.com*",
"*2mdn.net*",
"*googletagmanager.com*",
"*adsafeprotected.com*",
"*snigelweb.com*",
"*fastclick.net*",
"*amazon-adsystem.com*",
"*google-analytics.com*",
]})
self.execute_cdp_cmd('Network.enable', {})
self.open('https://www.w3schools.com/jquery/default.asp')
source = self.get_page_source()
self.assert_true("doubleclick.net" not in source)
self.assert_true("google-analytics.com" not in source)
if self.demo_mode:
self.post_message("Blocking was successful!")
1 change: 1 addition & 0 deletions examples/test_repeat_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest
from parameterized import parameterized
from seleniumbase import BaseCase
BaseCase.main(__name__, __file__, "-n6")

url = "data:text/html,<h2>Hello</h2><p><input />&nbsp;<button>OK!</button></p>"

Expand Down
2 changes: 2 additions & 0 deletions examples/translations/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class 我的测试类(硒测试用例):
self.开启("https://zh.wikipedia.org/wiki/")
self.断言标题("维基百科,自由的百科全书")
self.断言元素('a[title="Uncyclopedia:关于"]')
self.断言元素('span:contains("创建账号")')
self.断言元素('span:contains("登录")')
self.断言文本("新闻动态", "span#新闻动态")
self.输入文本('input[name="search"]', "舞龍")
self.单击('button:contains("搜索")')
Expand Down
2 changes: 2 additions & 0 deletions examples/translations/chinese_test_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ def test_例子1(self):
self.开启("https://zh.wikipedia.org/wiki/")
self.断言标题("维基百科,自由的百科全书")
self.断言元素('a[title="Uncyclopedia:关于"]')
self.断言元素('span:contains("创建账号")')
self.断言元素('span:contains("登录")')
self.断言文本("新闻动态", "span#新闻动态")
self.输入文本('input[name="search"]', "舞龍")
self.单击('button:contains("搜索")')
Expand Down
10 changes: 6 additions & 4 deletions help_docs/method_summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,14 @@ self.bring_active_window_to_front()

self.bring_to_front(selector, by="css selector")

self.highlight_click(selector, by="css selector", loops=3, scroll=True)
self.highlight_click(selector, by="css selector", loops=3, scroll=True, timeout=None)

self.highlight_type(selector, text, by="css selector", loops=3, scroll=True)
self.highlight_type(selector, text, by="css selector", loops=3, scroll=True, timeout=None)
# Duplicates:
# self.highlight_update_text(selector, text, by="css selector", loops=3, scroll=True)
# self.highlight_update_text(
# selector, text, by="css selector", loops=3, scroll=True, timeout=None)

self.highlight(selector, by="css selector", loops=4, scroll=True)
self.highlight(selector, by="css selector", loops=4, scroll=True, timeout=None)

self.press_up_arrow(selector="html", times=1, by="css selector")

Expand Down Expand Up @@ -1025,6 +1026,7 @@ driver.uc_click(selector)
* [test_login.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_login.py)
* [test_markers.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_markers.py)
* [test_swag_labs.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_swag_labs.py)
* [test_simple_login.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_simple_login.py)
* [test_suite.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_suite.py)
* [test_tinymce.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_tinymce.py)
* And many more...
Expand Down
4 changes: 4 additions & 0 deletions help_docs/syntax_formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ class 我的测试类(硒测试用例):
self.开启("https://zh.wikipedia.org/wiki/")
self.断言标题("维基百科,自由的百科全书")
self.断言元素('a[title="Uncyclopedia:关于"]')
self.断言元素('span:contains("创建账号")')
self.断言元素('span:contains("登录")')
self.断言文本("新闻动态", "span#新闻动态")
self.输入文本('input[name="search"]', "舞龍")
self.单击('button:contains("搜索")')
Expand Down Expand Up @@ -973,6 +975,8 @@ finally:

The ``Driver()`` manager format can be used as a drop-in replacement for virtually every Python/selenium framework, as it uses the raw ``driver`` instance for handling commands. The ``Driver()`` method simplifies the work of managing drivers with optimal settings, and it can be configured with multiple args. The ``Driver()`` also accepts command-line options (such as ``python --headless``) so that you don't need to modify your tests directly to use different settings. These command-line options only take effect if the associated method args remain unset (or set to ``None``) for the specified options.

When using the ``Driver()`` format, you may need to activate a Virtual Display on your own if you want to run headed tests in a headless Linux environment. (See https://github.com/mdmintz/sbVirtualDisplay for details.) One such example of this is using an authenticated proxy, which is configured via a Chrome extension that is generated at runtime. (Note that regular headless mode in Chrome doesn't support extensions.)

--------

<h3 align="left"><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.github.io/img/sb_logo_10.png" title="SeleniumBase" width="280" /></a></h3>
2 changes: 2 additions & 0 deletions help_docs/translations.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class 我的测试类(硒测试用例):
self.开启("https://zh.wikipedia.org/wiki/")
self.断言标题("维基百科,自由的百科全书")
self.断言元素('a[title="Uncyclopedia:关于"]')
self.断言元素('span:contains("创建账号")')
self.断言元素('span:contains("登录")')
self.断言文本("新闻动态", "span#新闻动态")
self.输入文本('input[name="search"]', "舞龍")
self.单击('button:contains("搜索")')
Expand Down
5 changes: 5 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ nav:
- ↔️ W3Schools drag & drop: https://seleniumbase.io/w3schools/drag_drop
- ☑️ W3Schools checkboxes: https://seleniumbase.io/w3schools/checkboxes
- 🔘 W3Schools radio buttons: https://seleniumbase.io/w3schools/radio_buttons
- Pages with CAPTCHAs:
- 🔑 CF Turnstile Test: https://seleniumbase.io/apps/turnstile
- 🔑 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
- 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 @@ -20,7 +20,7 @@ paginate==0.5.6
pyquery==2.0.0
readtime==3.0.0
mkdocs==1.5.3
mkdocs-material==9.4.7
mkdocs-material==9.4.8
mkdocs-exclude-search==0.6.5
mkdocs-simple-hooks==0.1.5
mkdocs-material-extensions==1.3
7 changes: 4 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ pynose==1.4.8
sniffio==1.3.0
h11==0.14.0
outcome==1.3.0.post0
trio==0.22.2
trio==0.22.2;python_version<"3.8"
trio==0.23.1;python_version>="3.8"
trio-websocket==0.11.1
wsproto==1.2.0
selenium==4.11.2;python_version<"3.8"
selenium==4.14.0;python_version>="3.8"
selenium==4.15.2;python_version>="3.8"
cssselect==1.2.0
sortedcontainers==2.4.0
fasteners==0.19
Expand All @@ -41,7 +42,7 @@ pytest-ordering==0.6
pytest-rerunfailures==12.0
pytest-xdist==3.3.1
parameterized==0.9.0
sbvirtualdisplay==1.2.0
sbvirtualdisplay==1.3.0
behave==1.2.6
soupsieve==2.4.1;python_version<"3.8"
soupsieve==2.5;python_version>="3.8"
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.20.9"
__version__ = "4.21.0"
27 changes: 22 additions & 5 deletions seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,18 @@ def find_edgedriver_version_to_use(use_version, driver_version):

def has_cf(text):
if (
"<title>Just a moment...</title>" in text
or "<title>403 Forbidden</title>" in text
"<title>403 Forbidden</title>" in text
or "Permission Denied</title>" in text
or 'id="challenge-error-text"' in text
or "<title>Just a moment..." in text
or 'action="/?__cf_chl_f_tk' in text
or 'src="chromedriver.js"' in text
or 'class="g-recaptcha"' in text
or 'content="Pixelscan"' in text
or 'id="challenge-form"' in text
or "window._cf_chl_opt" in text
or "/recaptcha/api.js" in text
or "/turnstile/" in text
):
return True
return False
Expand Down Expand Up @@ -427,11 +431,24 @@ def uc_open_with_reconnect(driver, url, reconnect_time=None):


def uc_click(
driver, selector, by="css selector", timeout=settings.SMALL_TIMEOUT
driver,
selector,
by="css selector",
timeout=settings.SMALL_TIMEOUT,
reconnect_time=None,
):
try:
rct = float(by) # Add shortcut: driver.uc_click(selector, RCT)
if not reconnect_time:
reconnect_time = rct
by = "css selector"
except Exception:
pass
element = driver.wait_for_element(selector, by=by, timeout=timeout)
try:
element.uc_click()
element.uc_click(
driver, selector, by=by, reconnect_time=reconnect_time
)
except ElementClickInterceptedException:
driver.js_click(selector, by=by, timeout=timeout)

Expand Down Expand Up @@ -2876,7 +2893,7 @@ def get_local_driver(
disable_build_check = True
uc_driver_version = None
if is_using_uc(undetectable, browser_name):
if use_br_version_for_uc:
if use_br_version_for_uc or driver_version == "mlatest":
uc_driver_version = get_uc_driver_version(full=True)
full_ch_driver_version = uc_driver_version
else:
Expand Down
Loading