Skip to content

Multiple updates (options, etc.) #3159

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
Sep 23, 2024
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ pytest test_coffee_cart.py --trace
--headless2 # (Use the new headless mode, which supports extensions.)
--headed # (Run tests in headed/GUI mode on Linux OS, where not default.)
--xvfb # (Run tests using the Xvfb virtual display server on Linux OS.)
--xvfb-metrics=STRING # (Set Xvfb display size on Linux: "Width,Height".)
--locale=LOCALE_CODE # (Set the Language Locale Code for the web browser.)
--interval=SECONDS # (The autoplay interval for presentations & tour steps)
--start-page=URL # (The starting URL for the web browser when tests begin.)
Expand Down Expand Up @@ -701,6 +702,7 @@ pytest test_coffee_cart.py --trace
--rcs | --reuse-class-session # (Reuse session for tests in class.)
--crumbs # (Delete all cookies between tests reusing a session.)
--disable-beforeunload # (Disable the "beforeunload" event on Chrome.)
--window-position=X,Y # (Set the browser's starting window position.)
--window-size=WIDTH,HEIGHT # (Set the browser's starting window size.)
--maximize # (Start tests with the browser window maximized.)
--screenshot # (Save a screenshot at the end of each test.)
Expand Down Expand Up @@ -869,7 +871,7 @@ pytest test_suite.py --dashboard --html=report.html

<img src="https://seleniumbase.github.io/cdn/img/dash_report.jpg" alt="Dashboard Pytest HTML Report" title="Dashboard Pytest HTML Report" width="520" />

If viewing pytest html reports in [Jenkins](https://www.jenkins.io/), you may need to [configure Jenkins settings](https://stackoverflow.com/a/46197356) for the html to render correctly. This is due to [Jenkins CSP changes](https://www.jenkins.io/doc/book/system-administration/security/configuring-content-security-policy/).
If viewing pytest html reports in [Jenkins](https://www.jenkins.io/), you may need to [configure Jenkins settings](https://stackoverflow.com/a/46197356/7058266) for the html to render correctly. This is due to [Jenkins CSP changes](https://www.jenkins.io/doc/book/system-administration/security/configuring-content-security-policy/).

You can also use ``--junit-xml=report.xml`` to get an xml report instead. Jenkins can use this file to display better reporting for your tests.

Expand Down
4 changes: 4 additions & 0 deletions examples/custom_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
# If True and --proxy=IP_ADDRESS:PORT is invalid, then error immediately.
RAISE_INVALID_PROXY_STRING_EXCEPTION = True

# Default browser coordinates when opening new windows for tests.
WINDOW_START_X = 20
WINDOW_START_Y = 54

# Default browser resolutions when opening new windows for tests.
# (Headless resolutions take priority, and include all browsers.)
# (Firefox starts maximized by default when running in GUI Mode.)
Expand Down
4 changes: 3 additions & 1 deletion examples/dialog_boxes/dialog_box_tour.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ def test_dialog_boxes(self):
self.highlight_type('input[aria-label="Search"]', text + "\n")
else:
self.open("https://en.wikipedia.org/wiki/Special:Search")
self.highlight_type('input[id*="search"]', text + "\n")
self.highlight_type('input[id*="search"]', text)
self.sleep(1)
self.click("#searchform button")
self.wait_for_ready_state_complete()
self.sleep(1)
self.highlight("body")
Expand Down
4 changes: 2 additions & 2 deletions examples/example_logs/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ pytest test_suite.py --dashboard --html=report.html

--------

If viewing ``pytest-html`` reports in [Jenkins](https://www.jenkins.io/), you may need to [configure Jenkins settings](https://stackoverflow.com/a/46197356) for the HTML to render correctly. This is due to [Jenkins CSP changes](https://www.jenkins.io/doc/book/security/configuring-content-security-policy/). That setting can be changed from ``Manage Jenkins`` > ``Script Console`` by running:
If viewing ``pytest-html`` reports in [Jenkins](https://www.jenkins.io/), you may need to [configure Jenkins settings](https://stackoverflow.com/a/46197356/7058266) for the HTML to render correctly. This is due to [Jenkins CSP changes](https://www.jenkins.io/doc/book/security/configuring-content-security-policy/). That setting can be changed from ``Manage Jenkins`` > ``Script Console`` by running:

```
```js
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")
```

Expand Down
47 changes: 20 additions & 27 deletions examples/presenter/uc_presentation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import subprocess
from contextlib import suppress
from seleniumbase import BaseCase
from seleniumbase import SB
BaseCase.main(__name__, __file__)
Expand All @@ -8,6 +9,7 @@
class UCPresentationClass(BaseCase):
def test_presentation(self):
self.open("data:,")
self._output_file_saves = False
self.create_presentation(theme="beige", transition="fade")
self.add_slide(
"<p>A deep dive into <b>undetectable automation</b>, with:</p>"
Expand Down Expand Up @@ -235,7 +237,8 @@ def test_presentation(self):
"<mk-2>from seleniumbase import Driver</mk-2>\n\n"
"<mk-3>driver = Driver(uc=True)</mk-3>\n"
"<mk-4>try:</mk-4>\n"
' <mk-5>driver.get("https://nowsecure.nl/#relax")</mk-5>\n'
' <mk-5>driver.get("https://gitlab.com/users/sign_in")'
'</mk-5>\n'
" <mk-1><mk-6>driver.sleep(4)</mk-6></mk-1>\n"
" <mk-7># DO MORE STUFF</mk-7>\n"
"<mk-4>finally:</mk-4>\n"
Expand Down Expand Up @@ -263,7 +266,7 @@ def test_presentation(self):
)
self.begin_presentation(filename="uc_presentation.html")

try:
with suppress(Exception):
with SB(uc=True) as sb:
sb.get("https://seleniumbase.io/simple/login")
sb.type("#username", "demo_user")
Expand All @@ -274,8 +277,6 @@ def test_presentation(self):
sb.highlight("#image1")
sb.click_link("Sign out")
sb.assert_text("signed out", "#top_message")
except Exception:
pass

self.create_presentation(theme="serif", transition="fade")
self.add_slide(
Expand All @@ -298,7 +299,7 @@ def test_presentation(self):
)
self.begin_presentation(filename="uc_presentation.html")

try:
with suppress(Exception):
with SB(uc=True, demo=True) as sb:
sb.get("https://seleniumbase.io/simple/login")
sb.type("#username", "demo_user")
Expand All @@ -309,8 +310,6 @@ def test_presentation(self):
sb.highlight("#image1")
sb.click_link("Sign out")
sb.assert_text("signed out", "#top_message")
except Exception:
pass

self.create_presentation(theme="serif", transition="fade")
self.add_slide(
Expand Down Expand Up @@ -339,29 +338,22 @@ def test_presentation(self):
code=(
"from seleniumbase import SB\n\n"
"with SB(uc=True) as sb:\n"
' sb.get("https://nowsecure.nl/#relax")\n'
" sb.sleep(1)\n"
' if not sb.is_text_visible("OH YEAH, you passed", "h1"):\n'
" sb.get_new_driver(undetectable=True)\n"
' sb.get("https://nowsecure.nl/#relax")\n'
" sb.sleep(1)\n"
' sb.activate_demo_mode()\n'
' sb.assert_text("OH YEAH, you passed!", "h1", timeout=3)\n'
' url = "https://gitlab.com/users/sign_in"\n'
" sb.uc_open_with_reconnect(url, 4)\n\n"
" ...\n"
),
)
self.begin_presentation(filename="uc_presentation.html")

try:
with suppress(Exception):
with SB(uc=True) as sb:
sb.uc_open_with_tab("https://nowsecure.nl/#relax")
sb.sleep(1)
if not sb.is_text_visible("OH YEAH, you passed", "h1"):
sb.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)
except Exception:
pass
url = "https://gitlab.com/users/sign_in"
sb.uc_open_with_reconnect(url, 4)
sb.assert_text("Username", '[for="user_login"]', timeout=3)
sb.assert_element('[for="user_login"]')
sb.highlight('button:contains("Sign in")')
sb.highlight('h1:contains("GitLab.com")')
sb.post_message("SeleniumBase wasn't detected", duration=4)

self.create_presentation(theme="serif", transition="fade")
self.add_slide(
Expand Down Expand Up @@ -495,11 +487,12 @@ def test_presentation(self):
code=(
"# Example:\n"
"<mk-1>driver.uc_open_with_reconnect(\n"
' "https://nowsecure.nl/#relax", reconnect_time=6\n)</mk-1>'
' "https://steamdb.info/login/", reconnect_time=6\n)'
"</mk-1>"
"\n\n"
"# Short form example:\n"
"<mk-2>driver.uc_open_with_reconnect("
'"https://nowsecure.nl/#relax", 6)</mk-2>\n'
'"https://steamdb.info/login/", 6)</mk-2>\n'
),
)
self.add_slide(
Expand Down
33 changes: 9 additions & 24 deletions examples/presenter/uc_presentation_3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
from contextlib import suppress
from seleniumbase import BaseCase
from seleniumbase import SB
BaseCase.main(__name__, __file__)
Expand Down Expand Up @@ -54,7 +55,7 @@ def test_presentation_3(self):
)
self.begin_presentation(filename="uc_presentation.html")

try:
with suppress(Exception):
with SB(uc=True) as sb:
url = "https://gitlab.com/users/sign_in"
sb.uc_open_with_reconnect(url, 4)
Expand All @@ -63,8 +64,6 @@ def test_presentation_3(self):
sb.highlight('button:contains("Sign in")')
sb.highlight('h1:contains("GitLab.com")')
sb.post_message("SeleniumBase wasn't detected", duration=4)
except Exception:
pass

self.create_presentation(theme="serif", transition="none")
self.add_slide(
Expand Down Expand Up @@ -151,16 +150,14 @@ def test_presentation_3(self):
if "linux" in sys.platform or "win32" in sys.platform:
agent = None # Use the default UserAgent

try:
with suppress(Exception):
with SB(uc=True, test=True, agent=agent) as sb:
url = "https://gitlab.com/users/sign_in"
sb.uc_open_with_reconnect(url, 4)
sb.uc_gui_handle_captcha() # Only if needed
sb.assert_element('label[for="user_login"]')
sb.set_messenger_theme(location="bottom_center")
sb.post_message("SeleniumBase wasn't detected!")
except Exception:
pass

self.create_presentation(theme="serif", transition="none")
self.add_slide(
Expand Down Expand Up @@ -201,16 +198,14 @@ def test_presentation_3(self):
)
self.begin_presentation(filename="uc_presentation.html")

try:
with suppress(Exception):
with SB(uc=True, test=True, agent=agent) as sb:
url = "https://gitlab.com/users/sign_in"
sb.uc_open_with_reconnect(url, 4)
sb.uc_gui_click_captcha() # Only if needed
sb.assert_element('label[for="user_login"]')
sb.set_messenger_theme(location="bottom_center")
sb.post_message("SeleniumBase wasn't detected!")
except Exception:
pass

self.create_presentation(theme="serif", transition="none")
self.add_slide(
Expand Down Expand Up @@ -276,7 +271,7 @@ def test_presentation_3(self):
)
self.begin_presentation(filename="uc_presentation.html")

try:
with suppress(Exception):
with SB(uc=True, incognito=True, locale_code="en") as sb:
url = "https://ahrefs.com/website-authority-checker"
input_field = 'input[placeholder="Enter domain"]'
Expand All @@ -291,8 +286,6 @@ def test_presentation_3(self):
sb.highlight('a:contains("Top 100 backlinks")')
sb.set_messenger_theme(location="bottom_center")
sb.post_message("SeleniumBase wasn't detected!")
except Exception:
pass

self.create_presentation(theme="serif", transition="none")
self.add_slide(
Expand All @@ -312,7 +305,7 @@ def test_presentation_3(self):
)
self.begin_presentation(filename="uc_presentation.html")

try:
with suppress(Exception):
with SB(uc=True, test=True, disable_csp=True) as sb:
url = "https://steamdb.info/"
sb.uc_open_with_reconnect(url, 3)
Expand All @@ -324,8 +317,6 @@ def test_presentation_3(self):
sb.highlight('button:contains("Sign in")', scroll=False)
sb.set_messenger_theme(location="top_center")
sb.post_message("SeleniumBase wasn't detected", duration=4)
except Exception:
pass

self.create_presentation(theme="serif", transition="none")
self.add_slide(
Expand Down Expand Up @@ -405,16 +396,14 @@ def test_presentation_3(self):
)
self.begin_presentation(filename="uc_presentation.html")

try:
with suppress(Exception):
with SB(uc=True, test=True) as sb:
url = "https://seleniumbase.io/apps/recaptcha"
sb.uc_open_with_reconnect(url)
sb.uc_gui_click_captcha() # Try with PyAutoGUI Click
sb.assert_element("img#captcha-success", timeout=3)
sb.set_messenger_theme(location="top_left")
sb.post_message("SeleniumBase wasn't detected")
except Exception:
pass

self.create_presentation(theme="serif", transition="none")
self.add_slide(
Expand Down Expand Up @@ -673,7 +662,7 @@ def test_presentation_3(self):
)
self.begin_presentation(filename="uc_presentation.html")

try:
with suppress(Exception):
with SB(test=True) as sb:
url = "https://seleniumbase.io/hobbit/login"
sb.open(url)
Expand All @@ -682,8 +671,6 @@ def test_presentation_3(self):
sb.click("img")
sb.highlight("h1")
sb.sleep(3) # Gandalf: "You Shall Not Pass!"
except Exception:
pass

self.create_presentation(theme="serif", transition="none")
self.add_slide(
Expand All @@ -692,7 +679,7 @@ def test_presentation_3(self):
)
self.begin_presentation(filename="uc_presentation.html")

try:
with suppress(Exception):
with SB(uc=True, test=True) as sb:
url = "https://seleniumbase.io/hobbit/login"
sb.uc_open_with_disconnect(url, 2.2)
Expand All @@ -703,8 +690,6 @@ def test_presentation_3(self):
sb.post_message("SeleniumBase wasn't detected!")
sb.click("img")
sb.sleep(5.888) # Cool animation happening now!
except Exception:
pass

self.create_presentation(theme="serif", transition="none")
self.add_slide(
Expand Down
5 changes: 3 additions & 2 deletions examples/test_hack_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ def test_hack_search(self):
self.highlight_click('[href*="github.com/seleniumbase/SeleniumBase"]')
self.highlight_click('[href="/seleniumbase/SeleniumBase"]')
self.assert_text("SeleniumBase", "strong a")
self.highlight("strong a")
self.js_click('a[title="examples"]')
self.highlight('td[class*="large"] a[title="test_hack_search.py"]')
self.click('td[class*="large"] a[title="test_hack_search.py"]')
self.highlight('#repo-content-turbo-frame')
self.js_click('a[title="test_hack_search.py"]')
self.assert_text("test_hack_search.py", "#file-name-id-wide")
self.highlight("#file-name-id-wide")
3 changes: 3 additions & 0 deletions examples/test_parse_soup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def click_menu_item(self, text):
self.click("#%s" % the_id)

def test_beautiful_soup_parsing(self):
if self.headless:
self.open_if_not_url("about:blank")
self.skip("Skip this test in headless mode!")
self.open("https://seleniumbase.io/tinymce/")
self.wait_for_element("div.mce-container-body")
self.click_menu_item("File")
Expand Down
2 changes: 1 addition & 1 deletion examples/test_shadow_dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_shadow_dom(self):
)
remove_button = (
"downloads-manager::shadow #downloadsList"
" downloads-item::shadow #remove-old"
" downloads-item::shadow #quick-remove"
)
no_downloads_area = "downloads-manager::shadow #no-downloads"

Expand Down
3 changes: 3 additions & 0 deletions examples/test_tinymce.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

class TinyMceTests(BaseCase):
def test_tinymce(self):
if self.headless:
self.open_if_not_url("about:blank")
self.skip("Skip this test in headless mode!")
self.open("https://seleniumbase.io/tinymce/")
self.wait_for_element("div.mce-container-body")
self.click('span:contains("File")')
Expand Down
13 changes: 6 additions & 7 deletions examples/youtube_search_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@ def test_youtube_autocomplete_results(self):
self.open("https://www.youtube.com/c/MichaelMintz")
search_term = "seleniumbase"
search_selector = "input#search"
result_selector = 'li[role="presentation"]'
results_selector = '[role="listbox"]'
self.click_if_visible('button[aria-label="Close"]')
self.double_click(search_selector)
self.sleep(0.15)
self.type(search_selector, search_term)
self.sleep(0.15)
# First verify that an autocomplete result exists
self.assert_element(result_selector)
top_result = self.get_text(result_selector)
self.assert_element(results_selector)
top_results = self.get_text(results_selector)
# Now verify that the autocomplete result is good
self.assert_true(
search_term in top_result,
'Expected text "%s" not found in top result! '
'Actual text was "%s"!' % (search_term, top_result),
search_term in top_results,
'Expected text "%s" not found in top results! '
'Actual text was "%s"!' % (search_term, top_results),
)
self.click(result_selector)
self.sleep(1)
Loading