Skip to content

Commit

Permalink
Merge pull request #2085 from seleniumbase/enhancements-and-bug-fixes
Browse files Browse the repository at this point in the history
Enhancements and bug fixes
  • Loading branch information
mdmintz authored Sep 10, 2023
2 parents 63d95c4 + 738e808 commit f1a86b0
Show file tree
Hide file tree
Showing 22 changed files with 976 additions and 227 deletions.
21 changes: 8 additions & 13 deletions examples/raw_browser_launcher.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
"""Driver() test. Runs with "python". (pytest not needed)."""
from seleniumbase import Driver
from seleniumbase import js_utils
from seleniumbase import page_actions

# Example with options. (Also accepts command-line options.)
driver = Driver(browser="chrome", headless=False)
try:
driver.get("https://seleniumbase.io/apps/calculator")
page_actions.wait_for_element(driver, '[id="4"]').click()
page_actions.wait_for_element(driver, '[id="2"]').click()
page_actions.wait_for_text(driver, "42", "#output")
js_utils.highlight_with_js(driver, "#output", loops=6)
driver.click('[id="4"]')
driver.click('[id="2"]')
driver.assert_text("42", "#output")
driver.highlight("#output", loops=6)
finally:
driver.quit()

# Example 2 using default args or command-line options
driver = Driver()
try:
driver.get("https://seleniumbase.github.io/demo_page")
js_utils.highlight_with_js(driver, "h2", loops=5)
by_css = "css selector"
driver.find_element(by_css, "#myTextInput").send_keys("Automation")
driver.find_element(by_css, "#checkBox1").click()
js_utils.highlight_with_js(driver, "img", loops=5)
driver.highlight("h2")
driver.type("#myTextInput", "Automation")
driver.click("#checkBox1")
driver.highlight("img", loops=6)
finally:
driver.quit()
22 changes: 9 additions & 13 deletions examples/raw_driver_context.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
"""Can run with "python". (pytest not needed)."""
from seleniumbase import js_utils
from seleniumbase import page_actions
from seleniumbase import DriverContext

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

with DriverContext(browser="chrome", incognito=True) as driver:
driver.get("https://seleniumbase.io/apps/calculator")
page_actions.wait_for_element(driver, '[id="4"]').click()
page_actions.wait_for_element(driver, '[id="2"]').click()
page_actions.wait_for_text(driver, "42", "#output")
js_utils.highlight_with_js(driver, "#output", loops=6)
driver.click('[id="4"]')
driver.click('[id="2"]')
driver.assert_text("42", "#output")
driver.highlight("#output", loops=6)

with DriverContext() as driver:
driver.get("https://seleniumbase.github.io/demo_page")
js_utils.highlight_with_js(driver, "h2", loops=5)
by_css = "css selector"
driver.find_element(by_css, "#myTextInput").send_keys("Automation")
driver.find_element(by_css, "#checkBox1").click()
js_utils.highlight_with_js(driver, "img", loops=5)
driver.highlight("h2")
driver.type("#myTextInput", "Automation")
driver.click("#checkBox1")
driver.highlight("img", loops=6)
11 changes: 6 additions & 5 deletions examples/raw_uc_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
from seleniumbase import SB

with SB(uc=True) as sb:
sb.open("https://nowsecure.nl/#relax")
sb.sleep(3)
sb.driver.get("https://nowsecure.nl/#relax")
sb.sleep(2)
if not sb.is_text_visible("OH YEAH, you passed!", "h1"):
sb.get_new_driver(undetectable=True)
sb.open("https://nowsecure.nl/#relax")
sb.sleep(3)
sb.driver.get("https://nowsecure.nl/#relax")
sb.sleep(2)
if not sb.is_text_visible("OH YEAH, you passed!", "h1"):
if sb.is_element_visible('iframe[src*="challenge"]'):
with sb.frame_switch('iframe[src*="challenge"]'):
sb.click("area")
sb.sleep(3)
sb.sleep(4)
sb.activate_demo_mode()
sb.assert_text("OH YEAH, you passed!", "h1", timeout=3)
6 changes: 3 additions & 3 deletions examples/test_repeat_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
class RepeatTests(BaseCase):
@parameterized.expand([[]] * 2)
def test_repeat_this_test_with_parameterized(self):
self.open("seleniumbase.github.io")
self.open("seleniumbase.github.io/")
self.click('a[href="help_docs/method_summary/"]')
self.assert_text("API Reference", "h1")


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


class RepeatTestsWithPytest:
@pytest.mark.parametrize("", [[]] * 2)
def test_repeat_test_with_pytest_parametrize(self, sb):
sb.open("seleniumbase.github.io")
sb.open("seleniumbase.github.io/")
sb.click('a[href="help_docs/customizing_test_runs/"]')
sb.assert_text("Command Line Options", "h1")
4 changes: 2 additions & 2 deletions examples/test_url_asserts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class URLTestClass(BaseCase):
def test_url_asserts(self):
self.open("https://seleniumbase.io/")
self.assert_url("https://seleniumbase.io/")
self.open("https://seleniumbase.github.io/")
self.assert_url("https://seleniumbase.github.io/")
self.assert_title_contains("SeleniumBase")
self.js_click('nav a:contains("Coffee Cart")')
self.assert_url_contains("/coffee")
Expand Down
4 changes: 2 additions & 2 deletions examples/uc_cdp_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ def fail_me(self):
def test_display_cdp_events(self):
if not (self.undetectable and self.uc_cdp_events):
self.get_new_driver(undetectable=True, uc_cdp_events=True)
self.open("https://nowsecure.nl/#relax")
self.driver.get("https://nowsecure.nl/#relax")
try:
self.verify_success()
except Exception:
self.clear_all_cookies()
self.get_new_driver(undetectable=True, uc_cdp_events=True)
self.open("https://nowsecure.nl/#relax")
self.driver.get("https://nowsecure.nl/#relax")
try:
self.verify_success()
except Exception:
Expand Down
4 changes: 2 additions & 2 deletions examples/verify_undetected.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def fail_me(self):
def test_browser_is_undetected(self):
if not (self.undetectable):
self.get_new_driver(undetectable=True)
self.open("https://nowsecure.nl/#relax")
self.driver.get("https://nowsecure.nl/#relax")
try:
self.verify_success()
except Exception:
self.clear_all_cookies()
self.get_new_driver(undetectable=True)
self.open("https://nowsecure.nl/#relax")
self.driver.get("https://nowsecure.nl/#relax")
try:
self.verify_success()
except Exception:
Expand Down
7 changes: 7 additions & 0 deletions help_docs/method_summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ self.hover(selector, by="css selector", timeout=None)
# self.hover_over_element(selector, by="css selector", timeout=None)

self.hover_and_click(
hover_selector, click_selector,
hover_by="css selector", click_by="css selector",
timeout=None, js_click=False)

self.hover_and_js_click(
hover_selector, click_selector,
hover_by="css selector", click_by="css selector",
timeout=None)
Expand Down Expand Up @@ -418,6 +423,8 @@ self.disable_beforeunload()

self.get_domain_url(url)

self.get_active_element_css()

self.get_beautiful_soup(source=None)

self.get_unique_links()
Expand Down
73 changes: 43 additions & 30 deletions help_docs/syntax_formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

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

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

<h3>SeleniumBase supports multiple ways of structuring tests:</h3>
<h3>🔡 SeleniumBase supports multiple ways of structuring tests:</h3>

<blockquote>
<p dir="auto"></p>
Expand Down Expand Up @@ -873,30 +873,26 @@ with SB(test=True, rtf=True, demo=True) as sb:
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:

```python
"""This script can be run with pure "python". (pytest not needed)."""
from seleniumbase import js_utils
from seleniumbase import page_actions
"""Can run with "python". (pytest not needed)."""
from seleniumbase import DriverContext

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

with DriverContext(browser="chrome", incognito=True) as driver:
driver.get("https://seleniumbase.io/apps/calculator")
page_actions.wait_for_element(driver, '[id="4"]').click()
page_actions.wait_for_element(driver, '[id="2"]').click()
page_actions.wait_for_text(driver, "42", "#output")
js_utils.highlight_with_js(driver, "#output", loops=6)
driver.click('[id="4"]')
driver.click('[id="2"]')
driver.assert_text("42", "#output")
driver.highlight("#output", loops=6)

with DriverContext() as driver:
driver.get("https://seleniumbase.github.io/demo_page")
js_utils.highlight_with_js(driver, "h2", loops=5)
by_css = "css selector"
driver.find_element(by_css, "#myTextInput").send_keys("Automation")
driver.find_element(by_css, "#checkBox1").click()
js_utils.highlight_with_js(driver, "img", loops=5)
driver.highlight("h2")
driver.type("#myTextInput", "Automation")
driver.click("#checkBox1")
driver.highlight("img", loops=6)
```

(See <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/raw_driver_context.py">examples/raw_driver_context.py</a> for an example.)
Expand All @@ -907,31 +903,48 @@ with DriverContext() as driver:
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:

```python
"""This script can be run with pure "python". (pytest not needed)."""
"""Driver() test. Runs with "python". (pytest not needed)."""
from seleniumbase import Driver
from seleniumbase import js_utils
from seleniumbase import page_actions

# Example with options. (Also accepts command-line options.)
driver = Driver(browser="chrome", headless=False)
try:
driver.get("https://seleniumbase.io/apps/calculator")
page_actions.wait_for_element(driver, '[id="4"]').click()
page_actions.wait_for_element(driver, '[id="2"]').click()
page_actions.wait_for_text(driver, "42", "#output")
js_utils.highlight_with_js(driver, "#output", loops=6)
driver.click('[id="4"]')
driver.click('[id="2"]')
driver.assert_text("42", "#output")
driver.highlight("#output", loops=6)
finally:
driver.quit()

# Example 2 using default args or command-line options
driver = Driver()
try:
driver.get("https://seleniumbase.github.io/demo_page")
js_utils.highlight_with_js(driver, "h2", loops=5)
by_css = "css selector"
driver.find_element(by_css, "#myTextInput").send_keys("Automation")
driver.find_element(by_css, "#checkBox1").click()
js_utils.highlight_with_js(driver, "img", loops=5)
driver.highlight("h2")
driver.type("#myTextInput", "Automation")
driver.click("#checkBox1")
driver.highlight("img", loops=6)
finally:
driver.quit()
"""Driver() test. Runs with "python". (pytest not needed)."""
from seleniumbase import Driver

driver = Driver(browser="chrome", headless=False)
try:
driver.get("https://seleniumbase.io/apps/calculator")
driver.click('[id="4"]')
driver.click('[id="2"]')
driver.assert_text("42", "#output")
driver.highlight("#output", loops=6)
finally:
driver.quit()

driver = Driver()
try:
driver.get("https://seleniumbase.github.io/demo_page")
driver.highlight("h2")
driver.type("#myTextInput", "Automation")
driver.click("#checkBox1")
driver.highlight("img", loops=6)
finally:
driver.quit()
```
Expand Down
4 changes: 2 additions & 2 deletions mkdocs_build/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

regex>=2023.8.8
PyYAML>=6.0.1
pymdown-extensions>=10.2.1
pymdown-extensions>=10.3
pipdeptree>=2.13.0
python-dateutil>=2.8.2
Markdown==3.4.4
Expand All @@ -20,7 +20,7 @@ paginate==0.5.6
pyquery==2.0.0
readtime==3.0.0
mkdocs==1.5.2
mkdocs-material==9.2.6
mkdocs-material==9.2.8
mkdocs-exclude-search==0.6.5
mkdocs-simple-hooks==0.1.5
mkdocs-material-extensions==1.1.1
15 changes: 8 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pip>=23.2.1
packaging>=23.1
setuptools>=68.0.0;python_version<"3.8"
setuptools>=68.1.2;python_version>="3.8"
setuptools>=68.2.0;python_version>="3.8"
wheel>=0.41.2
attrs>=23.1.0
certifi>=2023.7.22
Expand All @@ -22,7 +22,7 @@ sniffio==1.3.0
h11==0.14.0
outcome==1.2.0
trio==0.22.2
trio-websocket==0.10.3
trio-websocket==0.10.4
wsproto==1.2.0
selenium==4.11.2
cssselect==1.2.0
Expand All @@ -33,7 +33,7 @@ iniconfig==2.0.0
pluggy==1.2.0;python_version<"3.8"
pluggy==1.3.0;python_version>="3.8"
py==1.11.0
pytest==7.4.0
pytest==7.4.2
pytest-html==2.0.1
pytest-metadata==3.0.0
pytest-ordering==0.6
Expand All @@ -42,12 +42,13 @@ pytest-xdist==3.3.1
parameterized==0.9.0
sbvirtualdisplay==1.2.0
behave==1.2.6
soupsieve==2.4.1
soupsieve==2.4.1;python_version<"3.8"
soupsieve==2.5;python_version>="3.8"
beautifulsoup4==4.12.2
pygments==2.16.1
pyreadline3==3.4.1;platform_system=="Windows"
tabcompleter==1.2.1
pdbp==1.4.6
tabcompleter==1.3.0
pdbp==1.5.0
colorama==0.4.6
exceptiongroup==1.1.3
importlib-metadata==4.2.0;python_version<"3.8"
Expand All @@ -62,7 +63,7 @@ rich==13.5.2

coverage==6.2;python_version<"3.7"
coverage==7.2.7;python_version>="3.7" and python_version<"3.8"
coverage==7.3.0;python_version>="3.8"
coverage==7.3.1;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.18.1"
__version__ = "4.18.2"
2 changes: 1 addition & 1 deletion seleniumbase/config/proxy_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
Example proxies in PROXY_LIST below are not guaranteed to be active or secure.
If you don't already have a proxy server to connect to,
you can try finding one from one of following sites:
* https://www.sslproxies.org/
* https://bit.ly/36GtZa1
* https://www.us-proxy.org/
* https://hidemy.name/en/proxy-list/
* http://free-proxy.cz/en/proxylist/country/all/https/ping/all
* https://github.com/mertguvencli/http-proxy-list
"""

PROXY_LIST = {
Expand Down
Loading

0 comments on commit f1a86b0

Please sign in to comment.