Skip to content

Commit 532cc63

Browse files
committed
Refactor code, examples, and docs
1 parent 7f93736 commit 532cc63

273 files changed

Lines changed: 665 additions & 636 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
from seleniumbase import sb_cdp
6767

6868
sb = sb_cdp.Chrome()
69-
sb.open("https://browserscan.net/bot-detection")
69+
sb.goto("https://browserscan.net/bot-detection")
7070
sb.sleep(3)
7171
sb.quit()
7272
```
@@ -105,7 +105,7 @@ with sync_playwright() as p:
105105
from seleniumbase import sb_cdp
106106

107107
sb = sb_cdp.Chrome(locale="en", ad_block=True)
108-
sb.open("https://browserscan.net/bot-detection")
108+
sb.goto("https://browserscan.net/bot-detection")
109109
sb.flash("Test Results", duration=1.5, pause=0.5)
110110
sb.assert_element('strong:contains("Normal")')
111111
print("Bot Not Detected")
@@ -242,7 +242,7 @@ BaseCase.main(__name__, __file__) # Call pytest
242242

243243
class MyTestClass(BaseCase):
244244
def test_swag_labs(self):
245-
self.open("https://www.saucedemo.com")
245+
self.goto("https://www.saucedemo.com")
246246
self.type("#user-name", "standard_user")
247247
self.type("#password", "secret_sauce\n")
248248
self.assert_element("div.inventory_list")
@@ -362,7 +362,7 @@ BaseCase.main(__name__, __file__)
362362

363363
class TestSimpleLogin(BaseCase):
364364
def test_simple_login(self):
365-
self.open("seleniumbase.io/simple/login")
365+
self.goto("seleniumbase.io/simple/login")
366366
self.type("#username", "demo_user")
367367
self.type("#password", "secret_pass")
368368
self.click('a:contains("Sign in")')
@@ -379,7 +379,7 @@ class TestSimpleLogin(BaseCase):
379379
from seleniumbase import SB
380380

381381
with SB() as sb:
382-
sb.open("seleniumbase.io/simple/login")
382+
sb.goto("seleniumbase.io/simple/login")
383383
sb.type("#username", "demo_user")
384384
sb.type("#password", "secret_pass")
385385
sb.click('a:contains("Sign in")')
@@ -397,7 +397,7 @@ from seleniumbase import Driver
397397

398398
driver = Driver()
399399
try:
400-
driver.open("seleniumbase.io/simple/login")
400+
driver.goto("seleniumbase.io/simple/login")
401401
driver.type("#username", "demo_user")
402402
driver.type("#password", "secret_pass")
403403
driver.click('a:contains("Sign in")')
@@ -549,7 +549,7 @@ BaseCase.main(__name__, __file__)
549549
550550
class MyTestClass(BaseCase):
551551
def test_swag_labs(self):
552-
self.open("https://www.saucedemo.com")
552+
self.goto("https://www.saucedemo.com")
553553
self.type("#user-name", "standard_user")
554554
self.type("#password", "secret_sauce\n")
555555
self.assert_element("div.inventory_list")
@@ -582,7 +582,8 @@ class MyTestClass(BaseCase):
582582
<h3><img src="https://seleniumbase.github.io/img/logo7.png" title="SeleniumBase" width="32" /> Here are some common SeleniumBase methods:</h3>
583583

584584
```python
585-
self.open(url) # Navigate the browser window to the URL.
585+
self.goto(url) # Navigate the browser window to the URL.
586+
self.open(url) # Same as `self.goto(url)`
586587
self.activate_cdp_mode() # Activate CDP Mode from UC Mode.
587588
self.type(selector, text) # Update the field with the text.
588589
self.click(selector) # Click the element with the selector.
@@ -958,7 +959,7 @@ BaseCase.main(__name__, __file__)
958959
class MyTestClass(BaseCase):
959960
960961
def test_find_army_of_robots_on_xkcd_desert_island(self):
961-
self.open("https://xkcd.com/731/")
962+
self.goto("https://xkcd.com/731/")
962963
self.assert_element("div#ARMY_OF_ROBOTS", timeout=1) # This should fail
963964
```
964965
@@ -1162,7 +1163,7 @@ pytest [YOUR_TEST_FILE.py] --with-db-reporting --with-s3-logging
11621163
🔵 **Navigating to a web page: (and related commands)**
11631164
11641165
```python
1165-
self.open("https://xkcd.com/378/") # This method opens the specified page.
1166+
self.goto("https://xkcd.com/378/") # This method opens the specified page.
11661167
11671168
self.go_back() # This method navigates the browser to the previous page.
11681169
@@ -1299,7 +1300,7 @@ def is_there_a_cloaked_klingon_ship_on_this_page():
12991300
13001301
```python
13011302
if self.is_text_visible("You Shall Not Pass!", "h1"):
1302-
self.open("https://www.youtube.com/watch?v=3xYXUeSmb-Y")
1303+
self.goto("https://www.youtube.com/watch?v=3xYXUeSmb-Y")
13031304
```
13041305
13051306
<div></div>
@@ -1444,7 +1445,7 @@ self.execute_script("return jQuery('textarea')[2].value") # Returns the css "va
14441445
```python
14451446
start_page = "https://xkcd.com/465/"
14461447
destination_page = "https://github.com/seleniumbase/SeleniumBase"
1447-
self.open(start_page)
1448+
self.goto(start_page)
14481449
referral_link = '''<a class='analytics test' href='%s'>Free-Referral Button!</a>''' % destination_page
14491450
self.execute_script('''document.body.innerHTML = \"%s\"''' % referral_link)
14501451
self.click("a.analytics") # Clicks the generated button
@@ -1464,7 +1465,7 @@ BaseCase.main(__name__, __file__)
14641465
14651466
class DeferredAssertTests(BaseCase):
14661467
def test_deferred_asserts(self):
1467-
self.open("https://xkcd.com/993/")
1468+
self.goto("https://xkcd.com/993/")
14681469
self.wait_for_element("#comic")
14691470
self.deferred_assert_element('img[alt="Brand Identity"]')
14701471
self.deferred_assert_element('img[alt="Rocket Ship"]') # Will Fail

examples/basic_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class MyTestClass(BaseCase):
77
def test_basics(self):
8-
self.open("https://www.saucedemo.com")
8+
self.goto("https://www.saucedemo.com")
99
self.type("#user-name", "standard_user")
1010
self.type("#password", "secret_sauce\n")
1111
self.assert_element("div.inventory_list")

examples/behave_bdd/ReadMe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ from behave import step
121121
@step("Open the Swag Labs Login Page")
122122
def go_to_swag_labs(context):
123123
sb = context.sb
124-
sb.open("https://www.saucedemo.com")
124+
sb.goto("https://www.saucedemo.com")
125125
sb.clear_local_storage()
126126

127127

examples/behave_bdd/features/steps/calculator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
@step("Open the Calculator App")
55
def go_to_calculator(context):
6-
context.sb.open("https://seleniumbase.io/apps/calculator")
6+
context.sb.goto("https://seleniumbase.io/apps/calculator")
77

88

99
@step("Press C")

examples/behave_bdd/features/steps/fail_page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
@step("Open the Fail Page")
55
def go_to_error_page(context):
6-
context.sb.open("https://seleniumbase.io/error_page/")
6+
context.sb.goto("https://seleniumbase.io/error_page/")
77

88

99
@step("Fail test on purpose")

examples/behave_bdd/features/steps/swag_labs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@step("Open the Swag Labs Login Page")
55
def go_to_swag_labs(context):
66
sb = context.sb
7-
sb.open("https://www.saucedemo.com")
7+
sb.goto("https://www.saucedemo.com")
88
sb.clear_local_storage()
99

1010

examples/boilerplates/classic_obj_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class DataPage:
77
def go_to_data_url(self, sb):
8-
sb.open("data:text/html,<p>Hello!</p><input />")
8+
sb.goto("data:text/html,<p>Hello!</p><input />")
99

1010
def add_input_text(self, sb, text):
1111
sb.type("input", text)

examples/boilerplates/samples/google_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010
class GoogleTests(BaseCase):
1111
def test_google_dot_com(self):
1212
if self.headless:
13-
self.open_if_not_url("about:blank")
13+
self.goto_if_not_url("about:blank")
1414
print("\n Skipping test in headless mode.")
1515
self.skip("Skipping test in headless mode.")
1616
if not self.undetectable:
1717
self.get_new_driver(undetectable=True)
18-
self.driver.get("https://google.com/ncr")
18+
self.goto("https://google.com/ncr")
1919
self.click_if_visible('button:contains("Accept all")')
2020
self.assert_title_contains("Google")
2121
self.sleep(0.05)
2222
self.save_screenshot_to_logs() # ("./latest_logs" folder)
23-
self.type(HomePage.search_box, "github.com")
23+
self.type(HomePage.search_box, "GitHub")
2424
self.assert_element(HomePage.search_button)
2525
self.assert_element(HomePage.feeling_lucky_button)
2626
self.click(HomePage.search_button)
27+
self.sleep(1)
2728
self.assert_text("github.com", ResultsPage.search_results)

examples/boilerplates/samples/sb_swag_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class LoginPage:
77
def login_to_swag_labs(self, sb: BaseCase, username):
8-
sb.open("https://www.saucedemo.com")
8+
sb.goto("https://www.saucedemo.com")
99
sb.type("#user-name", username)
1010
sb.type("#password", "secret_sauce")
1111
sb.click('input[type="submit"]')

examples/boilerplates/samples/swag_labs_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class LoginPage:
77
def login_to_swag_labs(self, sb: BaseCase, username):
8-
sb.open("https://www.saucedemo.com")
8+
sb.goto("https://www.saucedemo.com")
99
sb.type("#user-name", username)
1010
sb.type("#password", "secret_sauce")
1111
sb.click('input[type="submit"]')

0 commit comments

Comments
 (0)