Skip to content

Update UC Mode and Refactor #2376

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 8 commits into from
Dec 19, 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
3 changes: 2 additions & 1 deletion examples/boilerplates/samples/google_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def test_google_dot_com(self):
self.assert_title_contains("Google")
self.sleep(0.05)
self.save_screenshot_to_logs() # ("./latest_logs" folder)
self.wait_for_element('iframe[role="presentation"]')
if not self.is_element_visible("iframe"):
self.sleep(1.5) # A slow pop-up might appear
self.hide_elements('iframe') # Hide "Sign in" pop-up
self.sleep(0.05)
self.save_screenshot_to_logs()
Expand Down
3 changes: 2 additions & 1 deletion examples/boilerplates/samples/test_page_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def assert_google_title(self, sb):
sb.assert_title_contains("Google")

def hide_sign_in_pop_up(self, sb):
sb.wait_for_element('iframe[role="presentation"]')
if not sb.is_element_visible("iframe"):
sb.sleep(1.5) # A slow pop-up might appear
sb.hide_elements('iframe')
sb.sleep(0.05)

Expand Down
3 changes: 1 addition & 2 deletions examples/github_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ def test_github(self):
message = "Unsupported mode for this test."
print("\n " + message)
self.skip(message)
self.open("https://github.com/search?q=SeleniumBase")
self.slow_click('a[href="/seleniumbase/SeleniumBase"]')
self.open("https://github.com/seleniumbase/SeleniumBase")
self.click_if_visible('[data-action="click:signup-prompt#dismiss"]')
self.highlight("div.Layout-main")
self.highlight("div.Layout-sidebar")
Expand Down
8 changes: 6 additions & 2 deletions examples/test_geolocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ def tearDown(self):
self.save_teardown_screenshot() # If test fails, or if "--screenshot"
if self.is_chromium() and not self._multithreaded:
# Reset Permissions and GeolocationOverride
self.execute_cdp_cmd("Browser.resetPermissions", {})
self.execute_cdp_cmd("Emulation.setGeolocationOverride", {})
try:
self.open("about:blank")
self.execute_cdp_cmd("Emulation.setGeolocationOverride", {})
self.execute_cdp_cmd("Browser.resetPermissions", {})
except Exception:
pass
super().tearDown()

def test_geolocation(self):
Expand Down
3 changes: 3 additions & 0 deletions examples/test_scrape_bing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

class ScrapeBingTests(BaseCase):
def test_scrape_bing(self):
if self._multithreaded:
self.open_if_not_url("about:blank")
self.skip("Skipping test in multi-threaded mode.")
self.open("www.bing.com/search?q=SeleniumBase+GitHub&qs=n&form=QBRE")
self.wait_for_element("main h2 a")
soup = self.get_beautiful_soup()
Expand Down
9 changes: 5 additions & 4 deletions mkdocs_build/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ pymdown-extensions>=10.5
pipdeptree>=2.13.1
python-dateutil>=2.8.2
Markdown==3.5.1
markdown2==2.4.11
markdown2==2.4.12
MarkupSafe==2.1.3
Jinja2==3.1.2
click==8.1.7
ghp-import==2.1.0
watchdog==3.0.0
cairocffi==1.6.1
pathspec==0.11.2
Babel==2.13.1
pathspec==0.12.1
Babel==2.14.0
paginate==0.5.6
lxml==4.9.4
pyquery==2.0.0
readtime==3.0.0
mkdocs==1.5.3
mkdocs-material==9.5.0
mkdocs-material==9.5.2
mkdocs-exclude-search==0.6.6
mkdocs-simple-hooks==0.1.5
mkdocs-material-extensions==1.3.1
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pip>=23.3.1
pip>=23.3.2
packaging>=23.2
setuptools>=68.0.0;python_version<"3.8"
setuptools>=69.0.2;python_version>="3.8"
Expand All @@ -23,7 +23,7 @@ sniffio==1.3.0
h11==0.14.0
outcome==1.3.0.post0
trio==0.22.2;python_version<"3.8"
trio==0.23.1;python_version>="3.8"
trio==0.23.2;python_version>="3.8"
trio-websocket==0.11.1
wsproto==1.2.0
selenium==4.11.2;python_version<"3.8"
Expand Down Expand Up @@ -65,7 +65,7 @@ rich==13.7.0

coverage==6.2;python_version<"3.7"
coverage==7.2.7;python_version>="3.7" and python_version<"3.8"
coverage==7.3.2;python_version>="3.8"
coverage==7.3.3;python_version>="3.8"
pytest-cov==4.0.0;python_version<"3.7"
pytest-cov==4.1.0;python_version>="3.7"
flake8==5.0.4;python_version<"3.9"
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.22.0"
__version__ = "4.22.1"
14 changes: 11 additions & 3 deletions seleniumbase/fixtures/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,15 @@ def open(self, url):
try:
self.driver.get(url)
except Exception as e:
if (
if not hasattr(e, "msg") and hasattr(self.driver, "default_get"):
try:
self._check_browser()
time.sleep(0.4)
except Exception:
logging.debug("Browser crashed! Will open new browser!")
self.driver = self.get_new_driver()
self.driver.default_get(url)
elif (
"ERR_CONNECTION_TIMED_OUT" in e.msg
or "ERR_CONNECTION_CLOSED" in e.msg
or "ERR_CONNECTION_RESET" in e.msg
Expand Down Expand Up @@ -1018,7 +1026,7 @@ def add_text(self, selector, text, by="css selector", timeout=None):
# Use after "\t" or Keys.TAB to cycle through elements first.
self.click_active_element()
return
element = self.wait_for_element_visible(
element = self.wait_for_element_present(
selector, by=by, timeout=timeout
)
if (
Expand Down Expand Up @@ -1113,7 +1121,7 @@ def send_keys(self, selector, text, by="css selector", timeout=None):
def press_keys(self, selector, text, by="css selector", timeout=None):
"""Use send_keys() to press one key at a time."""
self.wait_for_ready_state_complete()
element = self.wait_for_element_clickable(
element = self.wait_for_element_present(
selector, by=by, timeout=timeout
)
if self.demo_mode:
Expand Down
4 changes: 3 additions & 1 deletion seleniumbase/fixtures/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class Mobile:


class UC:
RECONNECT_TIME = 2.27 # Seconds
RECONNECT_TIME = 2.28 # Seconds


class ValidBrowsers:
Expand Down Expand Up @@ -390,12 +390,14 @@ class ValidBinaries:
"brave-browser-stable",
"opera",
"opera-stable",
"chrome.exe", # WSL (Windows Subsystem for Linux)
]
valid_edge_binaries_on_linux = [
"microsoft-edge",
"microsoft-edge-stable",
"microsoft-edge-beta",
"microsoft-edge-dev",
"msedge.exe", # WSL (Windows Subsystem for Linux)
]
valid_chrome_binaries_on_macos = [
"Google Chrome",
Expand Down
4 changes: 2 additions & 2 deletions seleniumbase/fixtures/page_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,7 @@ def send_keys(
driver, selector, text, by="css selector", timeout=settings.LARGE_TIMEOUT
):
selector, by = page_utils.recalculate_selector(selector, by)
element = wait_for_element_clickable(
element = wait_for_element_present(
driver, selector, by=by, timeout=timeout
)
if not text.endswith("\n"):
Expand All @@ -1597,7 +1597,7 @@ def press_keys(
driver, selector, text, by="css selector", timeout=settings.LARGE_TIMEOUT
):
selector, by = page_utils.recalculate_selector(selector, by)
element = wait_for_element_clickable(
element = wait_for_element_present(
driver, selector, by=by, timeout=timeout
)
if not text.endswith("\n"):
Expand Down
7 changes: 4 additions & 3 deletions seleniumbase/undetected/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,13 @@ def quit(self):
try:
logger.debug("Terminating the UC browser")
os.kill(self.browser_pid, 15)
if IS_POSIX:
if "linux" in sys.platform:
os.waitpid(self.browser_pid, 0)
time.sleep(0.02)
else:
time.sleep(0.05)
time.sleep(0.04)
except (AttributeError, ChildProcessError, RuntimeError, OSError):
pass
time.sleep(0.05)
except TimeoutError as e:
logger.debug(e, exc_info=True)
except Exception:
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
],
python_requires=">=3.7",
install_requires=[
'pip>=23.3.1',
'pip>=23.3.2',
'packaging>=23.2',
'setuptools>=68.0.0;python_version<"3.8"',
'setuptools>=69.0.2;python_version>="3.8"',
Expand All @@ -156,7 +156,7 @@
'h11==0.14.0',
'outcome==1.3.0.post0',
'trio==0.22.2;python_version<"3.8"',
'trio==0.23.1;python_version>="3.8"',
'trio==0.23.2;python_version>="3.8"',
'trio-websocket==0.11.1',
'wsproto==1.2.0',
'selenium==4.11.2;python_version<"3.8"',
Expand Down Expand Up @@ -206,7 +206,7 @@
# Usage: coverage run -m pytest; coverage html; coverage report
"coverage": [
'coverage==7.2.7;python_version<"3.8"',
'coverage==7.3.2;python_version>="3.8"',
'coverage==7.3.3;python_version>="3.8"',
'pytest-cov==4.1.0',
],
# pip install -e .[flake8]
Expand Down