Skip to content

Commit f1a86b0

Browse files
authored
Merge pull request #2085 from seleniumbase/enhancements-and-bug-fixes
Enhancements and bug fixes
2 parents 63d95c4 + 738e808 commit f1a86b0

22 files changed

+976
-227
lines changed

examples/raw_browser_launcher.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
"""Driver() test. Runs with "python". (pytest not needed)."""
22
from seleniumbase import Driver
3-
from seleniumbase import js_utils
4-
from seleniumbase import page_actions
53

6-
# Example with options. (Also accepts command-line options.)
74
driver = Driver(browser="chrome", headless=False)
85
try:
96
driver.get("https://seleniumbase.io/apps/calculator")
10-
page_actions.wait_for_element(driver, '[id="4"]').click()
11-
page_actions.wait_for_element(driver, '[id="2"]').click()
12-
page_actions.wait_for_text(driver, "42", "#output")
13-
js_utils.highlight_with_js(driver, "#output", loops=6)
7+
driver.click('[id="4"]')
8+
driver.click('[id="2"]')
9+
driver.assert_text("42", "#output")
10+
driver.highlight("#output", loops=6)
1411
finally:
1512
driver.quit()
1613

17-
# Example 2 using default args or command-line options
1814
driver = Driver()
1915
try:
2016
driver.get("https://seleniumbase.github.io/demo_page")
21-
js_utils.highlight_with_js(driver, "h2", loops=5)
22-
by_css = "css selector"
23-
driver.find_element(by_css, "#myTextInput").send_keys("Automation")
24-
driver.find_element(by_css, "#checkBox1").click()
25-
js_utils.highlight_with_js(driver, "img", loops=5)
17+
driver.highlight("h2")
18+
driver.type("#myTextInput", "Automation")
19+
driver.click("#checkBox1")
20+
driver.highlight("img", loops=6)
2621
finally:
2722
driver.quit()

examples/raw_driver_context.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
"""Can run with "python". (pytest not needed)."""
2-
from seleniumbase import js_utils
3-
from seleniumbase import page_actions
42
from seleniumbase import DriverContext
53

6-
# Driver Context Manager - (By default, browser="chrome". Lots of options)
74
with DriverContext() as driver:
85
driver.get("https://seleniumbase.github.io/")
9-
js_utils.highlight_with_js(driver, 'img[alt="SeleniumBase"]', loops=6)
6+
driver.highlight('img[alt="SeleniumBase"]', loops=6)
107

118
with DriverContext(browser="chrome", incognito=True) as driver:
129
driver.get("https://seleniumbase.io/apps/calculator")
13-
page_actions.wait_for_element(driver, '[id="4"]').click()
14-
page_actions.wait_for_element(driver, '[id="2"]').click()
15-
page_actions.wait_for_text(driver, "42", "#output")
16-
js_utils.highlight_with_js(driver, "#output", loops=6)
10+
driver.click('[id="4"]')
11+
driver.click('[id="2"]')
12+
driver.assert_text("42", "#output")
13+
driver.highlight("#output", loops=6)
1714

1815
with DriverContext() as driver:
1916
driver.get("https://seleniumbase.github.io/demo_page")
20-
js_utils.highlight_with_js(driver, "h2", loops=5)
21-
by_css = "css selector"
22-
driver.find_element(by_css, "#myTextInput").send_keys("Automation")
23-
driver.find_element(by_css, "#checkBox1").click()
24-
js_utils.highlight_with_js(driver, "img", loops=5)
17+
driver.highlight("h2")
18+
driver.type("#myTextInput", "Automation")
19+
driver.click("#checkBox1")
20+
driver.highlight("img", loops=6)

examples/raw_uc_mode.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
from seleniumbase import SB
33

44
with SB(uc=True) as sb:
5-
sb.open("https://nowsecure.nl/#relax")
6-
sb.sleep(3)
5+
sb.driver.get("https://nowsecure.nl/#relax")
6+
sb.sleep(2)
77
if not sb.is_text_visible("OH YEAH, you passed!", "h1"):
88
sb.get_new_driver(undetectable=True)
9-
sb.open("https://nowsecure.nl/#relax")
10-
sb.sleep(3)
9+
sb.driver.get("https://nowsecure.nl/#relax")
10+
sb.sleep(2)
1111
if not sb.is_text_visible("OH YEAH, you passed!", "h1"):
1212
if sb.is_element_visible('iframe[src*="challenge"]'):
1313
with sb.frame_switch('iframe[src*="challenge"]'):
1414
sb.click("area")
15-
sb.sleep(3)
15+
sb.sleep(4)
16+
sb.activate_demo_mode()
1617
sb.assert_text("OH YEAH, you passed!", "h1", timeout=3)

examples/test_repeat_tests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010
class RepeatTests(BaseCase):
1111
@parameterized.expand([[]] * 2)
1212
def test_repeat_this_test_with_parameterized(self):
13-
self.open("seleniumbase.github.io")
13+
self.open("seleniumbase.github.io/")
1414
self.click('a[href="help_docs/method_summary/"]')
1515
self.assert_text("API Reference", "h1")
1616

1717

1818
@pytest.mark.parametrize("", [[]] * 2)
1919
def test_repeat_this_test_with_pytest_parametrize(sb):
20-
sb.open("seleniumbase.github.io")
20+
sb.open("seleniumbase.github.io/")
2121
sb.click('a[href="seleniumbase/console_scripts/ReadMe/"]')
2222
sb.assert_text("Console Scripts", "h1")
2323

2424

2525
class RepeatTestsWithPytest:
2626
@pytest.mark.parametrize("", [[]] * 2)
2727
def test_repeat_test_with_pytest_parametrize(self, sb):
28-
sb.open("seleniumbase.github.io")
28+
sb.open("seleniumbase.github.io/")
2929
sb.click('a[href="help_docs/customizing_test_runs/"]')
3030
sb.assert_text("Command Line Options", "h1")

examples/test_url_asserts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
class URLTestClass(BaseCase):
66
def test_url_asserts(self):
7-
self.open("https://seleniumbase.io/")
8-
self.assert_url("https://seleniumbase.io/")
7+
self.open("https://seleniumbase.github.io/")
8+
self.assert_url("https://seleniumbase.github.io/")
99
self.assert_title_contains("SeleniumBase")
1010
self.js_click('nav a:contains("Coffee Cart")')
1111
self.assert_url_contains("/coffee")

examples/uc_cdp_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ def fail_me(self):
2525
def test_display_cdp_events(self):
2626
if not (self.undetectable and self.uc_cdp_events):
2727
self.get_new_driver(undetectable=True, uc_cdp_events=True)
28-
self.open("https://nowsecure.nl/#relax")
28+
self.driver.get("https://nowsecure.nl/#relax")
2929
try:
3030
self.verify_success()
3131
except Exception:
3232
self.clear_all_cookies()
3333
self.get_new_driver(undetectable=True, uc_cdp_events=True)
34-
self.open("https://nowsecure.nl/#relax")
34+
self.driver.get("https://nowsecure.nl/#relax")
3535
try:
3636
self.verify_success()
3737
except Exception:

examples/verify_undetected.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ def fail_me(self):
2020
def test_browser_is_undetected(self):
2121
if not (self.undetectable):
2222
self.get_new_driver(undetectable=True)
23-
self.open("https://nowsecure.nl/#relax")
23+
self.driver.get("https://nowsecure.nl/#relax")
2424
try:
2525
self.verify_success()
2626
except Exception:
2727
self.clear_all_cookies()
2828
self.get_new_driver(undetectable=True)
29-
self.open("https://nowsecure.nl/#relax")
29+
self.driver.get("https://nowsecure.nl/#relax")
3030
try:
3131
self.verify_success()
3232
except Exception:

help_docs/method_summary.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ self.hover(selector, by="css selector", timeout=None)
171171
# self.hover_over_element(selector, by="css selector", timeout=None)
172172

173173
self.hover_and_click(
174+
hover_selector, click_selector,
175+
hover_by="css selector", click_by="css selector",
176+
timeout=None, js_click=False)
177+
178+
self.hover_and_js_click(
174179
hover_selector, click_selector,
175180
hover_by="css selector", click_by="css selector",
176181
timeout=None)
@@ -418,6 +423,8 @@ self.disable_beforeunload()
418423

419424
self.get_domain_url(url)
420425

426+
self.get_active_element_css()
427+
421428
self.get_beautiful_soup(source=None)
422429

423430
self.get_unique_links()

help_docs/syntax_formats.md

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
<a id="syntax_formats"></a>
44

5-
## [<img src="https://seleniumbase.github.io/img/logo6.png" title="SeleniumBase" width="40">](https://github.com/seleniumbase/SeleniumBase/) The 23 Syntax Formats / Design Patterns
5+
<h2><img src="https://seleniumbase.github.io/img/logo6.png" title="SeleniumBase" width="40"> The 23 Syntax Formats / Design Patterns</h2>
66

7-
<h3>SeleniumBase supports multiple ways of structuring tests:</h3>
7+
<h3>🔡 SeleniumBase supports multiple ways of structuring tests:</h3>
88

99
<blockquote>
1010
<p dir="auto"></p>
@@ -873,30 +873,26 @@ with SB(test=True, rtf=True, demo=True) as sb:
873873
This pure Python format gives you a raw <code translate="no">webdriver</code> instance in a <code translate="no">with</code> block. The SeleniumBase Driver Manager will automatically make sure that your driver is compatible with your browser version. It gives you full access to customize driver options via method args or via the command-line. The driver will automatically call <code translate="no">quit()</code> after the code leaves the <code translate="no">with</code> block. Here are some examples:
874874

875875
```python
876-
"""This script can be run with pure "python". (pytest not needed)."""
877-
from seleniumbase import js_utils
878-
from seleniumbase import page_actions
876+
"""Can run with "python". (pytest not needed)."""
879877
from seleniumbase import DriverContext
880878

881-
# Driver Context Manager - (By default, browser="chrome". Lots of options)
882879
with DriverContext() as driver:
883880
driver.get("https://seleniumbase.github.io/")
884-
js_utils.highlight_with_js(driver, 'img[alt="SeleniumBase"]', loops=6)
881+
driver.highlight('img[alt="SeleniumBase"]', loops=6)
885882

886883
with DriverContext(browser="chrome", incognito=True) as driver:
887884
driver.get("https://seleniumbase.io/apps/calculator")
888-
page_actions.wait_for_element(driver, '[id="4"]').click()
889-
page_actions.wait_for_element(driver, '[id="2"]').click()
890-
page_actions.wait_for_text(driver, "42", "#output")
891-
js_utils.highlight_with_js(driver, "#output", loops=6)
885+
driver.click('[id="4"]')
886+
driver.click('[id="2"]')
887+
driver.assert_text("42", "#output")
888+
driver.highlight("#output", loops=6)
892889

893890
with DriverContext() as driver:
894891
driver.get("https://seleniumbase.github.io/demo_page")
895-
js_utils.highlight_with_js(driver, "h2", loops=5)
896-
by_css = "css selector"
897-
driver.find_element(by_css, "#myTextInput").send_keys("Automation")
898-
driver.find_element(by_css, "#checkBox1").click()
899-
js_utils.highlight_with_js(driver, "img", loops=5)
892+
driver.highlight("h2")
893+
driver.type("#myTextInput", "Automation")
894+
driver.click("#checkBox1")
895+
driver.highlight("img", loops=6)
900896
```
901897

902898
(See <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/raw_driver_context.py">examples/raw_driver_context.py</a> for an example.)
@@ -907,31 +903,48 @@ with DriverContext() as driver:
907903
Another way of running Selenium tests with pure ``python`` (as opposed to using ``pytest`` or ``pynose``) is by using this format, which bypasses [BaseCase](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/fixtures/base_case.py) methods while still giving you a flexible driver with a manager. SeleniumBase includes helper files such as [page_actions.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/fixtures/page_actions.py), which may help you get around some of the limitations of bypassing ``BaseCase``. Here's an example:
908904

909905
```python
910-
"""This script can be run with pure "python". (pytest not needed)."""
906+
"""Driver() test. Runs with "python". (pytest not needed)."""
911907
from seleniumbase import Driver
912-
from seleniumbase import js_utils
913-
from seleniumbase import page_actions
914908

915-
# Example with options. (Also accepts command-line options.)
916909
driver = Driver(browser="chrome", headless=False)
917910
try:
918911
driver.get("https://seleniumbase.io/apps/calculator")
919-
page_actions.wait_for_element(driver, '[id="4"]').click()
920-
page_actions.wait_for_element(driver, '[id="2"]').click()
921-
page_actions.wait_for_text(driver, "42", "#output")
922-
js_utils.highlight_with_js(driver, "#output", loops=6)
912+
driver.click('[id="4"]')
913+
driver.click('[id="2"]')
914+
driver.assert_text("42", "#output")
915+
driver.highlight("#output", loops=6)
923916
finally:
924917
driver.quit()
925918

926-
# Example 2 using default args or command-line options
927919
driver = Driver()
928920
try:
929921
driver.get("https://seleniumbase.github.io/demo_page")
930-
js_utils.highlight_with_js(driver, "h2", loops=5)
931-
by_css = "css selector"
932-
driver.find_element(by_css, "#myTextInput").send_keys("Automation")
933-
driver.find_element(by_css, "#checkBox1").click()
934-
js_utils.highlight_with_js(driver, "img", loops=5)
922+
driver.highlight("h2")
923+
driver.type("#myTextInput", "Automation")
924+
driver.click("#checkBox1")
925+
driver.highlight("img", loops=6)
926+
finally:
927+
driver.quit()
928+
"""Driver() test. Runs with "python". (pytest not needed)."""
929+
from seleniumbase import Driver
930+
931+
driver = Driver(browser="chrome", headless=False)
932+
try:
933+
driver.get("https://seleniumbase.io/apps/calculator")
934+
driver.click('[id="4"]')
935+
driver.click('[id="2"]')
936+
driver.assert_text("42", "#output")
937+
driver.highlight("#output", loops=6)
938+
finally:
939+
driver.quit()
940+
941+
driver = Driver()
942+
try:
943+
driver.get("https://seleniumbase.github.io/demo_page")
944+
driver.highlight("h2")
945+
driver.type("#myTextInput", "Automation")
946+
driver.click("#checkBox1")
947+
driver.highlight("img", loops=6)
935948
finally:
936949
driver.quit()
937950
```

mkdocs_build/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
regex>=2023.8.8
55
PyYAML>=6.0.1
6-
pymdown-extensions>=10.2.1
6+
pymdown-extensions>=10.3
77
pipdeptree>=2.13.0
88
python-dateutil>=2.8.2
99
Markdown==3.4.4
@@ -20,7 +20,7 @@ paginate==0.5.6
2020
pyquery==2.0.0
2121
readtime==3.0.0
2222
mkdocs==1.5.2
23-
mkdocs-material==9.2.6
23+
mkdocs-material==9.2.8
2424
mkdocs-exclude-search==0.6.5
2525
mkdocs-simple-hooks==0.1.5
2626
mkdocs-material-extensions==1.1.1

requirements.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pip>=23.2.1
22
packaging>=23.1
33
setuptools>=68.0.0;python_version<"3.8"
4-
setuptools>=68.1.2;python_version>="3.8"
4+
setuptools>=68.2.0;python_version>="3.8"
55
wheel>=0.41.2
66
attrs>=23.1.0
77
certifi>=2023.7.22
@@ -22,7 +22,7 @@ sniffio==1.3.0
2222
h11==0.14.0
2323
outcome==1.2.0
2424
trio==0.22.2
25-
trio-websocket==0.10.3
25+
trio-websocket==0.10.4
2626
wsproto==1.2.0
2727
selenium==4.11.2
2828
cssselect==1.2.0
@@ -33,7 +33,7 @@ iniconfig==2.0.0
3333
pluggy==1.2.0;python_version<"3.8"
3434
pluggy==1.3.0;python_version>="3.8"
3535
py==1.11.0
36-
pytest==7.4.0
36+
pytest==7.4.2
3737
pytest-html==2.0.1
3838
pytest-metadata==3.0.0
3939
pytest-ordering==0.6
@@ -42,12 +42,13 @@ pytest-xdist==3.3.1
4242
parameterized==0.9.0
4343
sbvirtualdisplay==1.2.0
4444
behave==1.2.6
45-
soupsieve==2.4.1
45+
soupsieve==2.4.1;python_version<"3.8"
46+
soupsieve==2.5;python_version>="3.8"
4647
beautifulsoup4==4.12.2
4748
pygments==2.16.1
4849
pyreadline3==3.4.1;platform_system=="Windows"
49-
tabcompleter==1.2.1
50-
pdbp==1.4.6
50+
tabcompleter==1.3.0
51+
pdbp==1.5.0
5152
colorama==0.4.6
5253
exceptiongroup==1.1.3
5354
importlib-metadata==4.2.0;python_version<"3.8"
@@ -62,7 +63,7 @@ rich==13.5.2
6263

6364
coverage==6.2;python_version<"3.7"
6465
coverage==7.2.7;python_version>="3.7" and python_version<"3.8"
65-
coverage==7.3.0;python_version>="3.8"
66+
coverage==7.3.1;python_version>="3.8"
6667
pytest-cov==4.0.0;python_version<"3.7"
6768
pytest-cov==4.1.0;python_version>="3.7"
6869
flake8==5.0.4;python_version<"3.9"

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.18.1"
2+
__version__ = "4.18.2"

seleniumbase/config/proxy_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
Example proxies in PROXY_LIST below are not guaranteed to be active or secure.
1616
If you don't already have a proxy server to connect to,
1717
you can try finding one from one of following sites:
18+
* https://www.sslproxies.org/
1819
* https://bit.ly/36GtZa1
1920
* https://www.us-proxy.org/
2021
* https://hidemy.name/en/proxy-list/
2122
* http://free-proxy.cz/en/proxylist/country/all/https/ping/all
22-
* https://github.com/mertguvencli/http-proxy-list
2323
"""
2424

2525
PROXY_LIST = {

0 commit comments

Comments
 (0)