Update examples

This commit is contained in:
Michael Mintz 2024-02-23 00:18:46 -05:00
parent 4e903a37f8
commit 6e9a093e80
9 changed files with 47 additions and 73 deletions

View File

@ -7,16 +7,16 @@ BaseCase.main(__name__, __file__, "--uc", "-n3")
@pytest.mark.parametrize("", [[]] * 3)
def test_multi_threaded(sb):
sb.driver.uc_open_with_tab("https://nowsecure.nl/#relax")
sb.driver.uc_open_with_reconnect("https://top.gg/", 5)
sb.set_window_rect(randint(0, 755), randint(38, 403), 700, 500)
try:
sb.assert_text("OH YEAH, you passed!", "h1", timeout=4)
sb.assert_text("Discord Bots", "h1", timeout=2)
sb.post_message("Selenium wasn't detected!", duration=4)
sb._print("\n Success! Website did not detect Selenium! ")
except Exception:
sb.driver.uc_open_with_tab("https://nowsecure.nl/#relax")
sb.driver.uc_open_with_reconnect("https://top.gg/", 5)
try:
sb.assert_text("OH YEAH, you passed!", "h1", timeout=4)
sb.assert_text("Discord Bots", "h1", timeout=2)
sb.post_message("Selenium wasn't detected!", duration=4)
sb._print("\n Success! Website did not detect Selenium! ")
except Exception:

View File

@ -30,17 +30,16 @@ class UCPresentationClass(BaseCase):
self.get_new_driver(undetectable=True)
try:
self.driver.uc_open_with_reconnect(
"https://nowsecure.nl/#relax", reconnect_time=3
"https://top.gg/", reconnect_time=4
)
try:
self.assert_text("OH YEAH, you passed!", "h1", timeout=4)
self.assert_text("Discord Bots", "h1", timeout=3)
self.post_message("Selenium wasn't detected!", duration=4)
except Exception:
self.clear_all_cookies()
self.driver.uc_open_with_reconnect(
"https://nowsecure.nl/#relax", reconnect_time=3
"https://top.gg/", reconnect_time=5
)
self.assert_text("OH YEAH, you passed!", "h1", timeout=4)
self.assert_text("Discord Bots", "h1", timeout=2)
self.post_message("Selenium wasn't detected!", duration=4)
finally:
self.quit_extra_driver()

View File

@ -0,0 +1,10 @@
from rich.pretty import pprint
from seleniumbase import Driver
driver = Driver(uc=True, log_cdp=True)
try:
driver.get("https://seleniumbase.io/apps/invisible_recaptcha")
driver.sleep(3)
pprint(driver.get_log("performance"))
finally:
driver.quit()

View File

@ -1,8 +1,8 @@
"""Can run with "python". (pytest not needed)."""
"""DriverContext() example. (Runs with "python")."""
from seleniumbase import DriverContext
with DriverContext() as driver:
driver.open("seleniumbase.github.io/")
driver.open("seleniumbase.io/")
driver.highlight('img[alt="SeleniumBase"]', loops=6)
with DriverContext(browser="chrome", incognito=True) as driver:
@ -13,7 +13,7 @@ with DriverContext(browser="chrome", incognito=True) as driver:
driver.highlight("#output", loops=6)
with DriverContext() as driver:
driver.open("seleniumbase.github.io/demo_page")
driver.open("seleniumbase.io/demo_page")
driver.highlight("h2")
driver.type("#myTextInput", "Automation")
driver.click("#checkBox1")

View File

@ -1,6 +1,16 @@
"""Driver() test. Runs with "python". (pytest not needed)."""
"""Driver() manager example. (Runs with "python")."""
from seleniumbase import Driver
driver = Driver()
try:
driver.open("seleniumbase.io/demo_page")
driver.highlight("h2")
driver.type("#myTextInput", "Automation")
driver.click("#checkBox1")
driver.highlight("img", loops=6)
finally:
driver.quit()
driver = Driver(browser="chrome", headless=False)
try:
driver.open("seleniumbase.io/apps/calculator")
@ -10,13 +20,3 @@ try:
driver.highlight("#output", loops=6)
finally:
driver.quit()
driver = Driver()
try:
driver.open("seleniumbase.github.io/demo_page")
driver.highlight("h2")
driver.type("#myTextInput", "Automation")
driver.click("#checkBox1")
driver.highlight("img", loops=6)
finally:
driver.quit()

View File

@ -1,4 +1,4 @@
"""Context Manager Test. Runs with "python". (pytest not needed)."""
"""SB() context manager example. (Runs with "python")."""
from seleniumbase import SB
with SB() as sb: # By default, browser="chrome" if not set.

View File

@ -2,18 +2,9 @@
from seleniumbase import SB
with SB(uc=True, test=True) as sb:
sb.driver.uc_open_with_tab("https://nowsecure.nl/#relax")
sb.sleep(1.2)
if not sb.is_text_visible("OH YEAH, you passed!", "h1"):
sb.driver.uc_open_with_reconnect("https://top.gg/", 4)
if not sb.is_text_visible("Discord Bots", "h1"):
sb.get_new_driver(undetectable=True)
sb.driver.uc_open_with_reconnect(
"https://nowsecure.nl/#relax", reconnect_time=3
)
sb.sleep(1.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("span.mark")
sb.sleep(2)
sb.activate_demo_mode()
sb.assert_text("OH YEAH, you passed!", "h1", timeout=3)
sb.driver.uc_open_with_reconnect("https://top.gg/", 5)
sb.activate_demo_mode() # Highlight + show assertions
sb.assert_text("Discord Bots", "h1", timeout=3)

View File

@ -1,4 +1,4 @@
from pprint import pformat
from rich.pretty import pprint
from seleniumbase import BaseCase
BaseCase.main(__name__, __file__, "--uc", "--uc-cdp", "-s")
@ -9,38 +9,18 @@ class CDPTests(BaseCase):
# self.driver.add_cdp_listener("*", lambda data: print(pformat(data)))
self.driver.add_cdp_listener(
"Network.requestWillBeSentExtraInfo",
lambda data: print(pformat(data))
lambda data: pprint(data)
)
def verify_success(self):
self.assert_text("OH YEAH, you passed!", "h1", timeout=6.25)
self.sleep(1)
def fail_me(self):
self.fail('Selenium was detected! Try using: "pytest --uc"')
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.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.driver.get("https://nowsecure.nl/#relax")
try:
self.verify_success()
except Exception:
if self.is_element_visible('iframe[src*="challenge"]'):
with self.frame_switch('iframe[src*="challenge"]'):
self.click("span.mark")
else:
self.fail_me()
try:
self.verify_success()
except Exception:
self.fail_me()
self.driver.uc_open_with_tab("https://nowsecure.nl/#relax")
self.verify_success()
self.add_cdp_listener()
self.refresh()
self.sleep(1)

View File

@ -10,20 +10,14 @@ class UndetectedTest(BaseCase):
if not self.undetectable:
self.get_new_driver(undetectable=True)
self.driver.uc_open_with_reconnect(
"https://nowsecure.nl/#relax", reconnect_time=3
"https://top.gg/", reconnect_time=4
)
self.sleep(1.2)
if not self.is_text_visible("OH YEAH, you passed!", "h1"):
if not self.is_text_visible("Discord Bots", "h1"):
self.get_new_driver(undetectable=True)
self.driver.uc_open_with_reconnect(
"https://nowsecure.nl/#relax", reconnect_time=3
"https://top.gg/", reconnect_time=5
)
self.sleep(1.2)
if not self.is_text_visible("OH YEAH, you passed!", "h1"):
if self.is_element_visible('iframe[src*="challenge"]'):
with self.frame_switch('iframe[src*="challenge"]'):
self.click("span.mark")
self.sleep(2)
self.assert_text("OH YEAH, you passed!", "h1", timeout=3)
self.assert_text("Discord Bots", "h1", timeout=3)
self.set_messenger_theme(theme="air", location="top_center")
self.post_message("Selenium wasn't detected!", duration=2.8)
self._print("\n Success! Website did not detect Selenium! ")