Skip to content

Commit 4ed6d18

Browse files
authored
Merge pull request #1193 from seleniumbase/grid-capabilities-and-more
Improvements to Grid capabilities, Safari automation, Shadow-DOM support, and more
2 parents 6cbaaf3 + dd60a75 commit 4ed6d18

24 files changed

+360
-121
lines changed

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,36 @@ pytest my_first_test.py --demo
149149
150150
> (Chrome is the default browser if not specified with ``--browser``. On Linux, ``--headless`` is the default behavior.)
151151
152-
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py"><img src="https://seleniumbase.io/cdn/gif/my_first_test_2.gif" alt="SeleniumBase Test" title="SeleniumBase Demo Mode" width="400" /></a>
152+
<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py"><img src="https://seleniumbase.io/cdn/gif/swag_labs_4.gif" alt="SeleniumBase Test" title="SeleniumBase Test" width="400" /></a>
153+
154+
<p align="left"><b>Here's the code for <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py">my_first_test.py</a>:</b></p>
155+
156+
```python
157+
from seleniumbase import BaseCase
158+
159+
class MyTestClass(BaseCase):
160+
def test_swag_labs(self):
161+
self.open("https://www.saucedemo.com")
162+
self.type("#user-name", "standard_user")
163+
self.type("#password", "secret_sauce\n")
164+
self.assert_element("#inventory_container")
165+
self.assert_text("PRODUCTS", "span.title")
166+
self.click('button[name*="backpack"]')
167+
self.click("#shopping_cart_container a")
168+
self.assert_text("YOUR CART", "span.title")
169+
self.assert_text("Backpack", "div.cart_item")
170+
self.click("button#checkout")
171+
self.type("#first-name", "SeleniumBase")
172+
self.type("#last-name", "Automation")
173+
self.type("#postal-code", "77123")
174+
self.click("input#continue")
175+
self.assert_text("CHECKOUT: OVERVIEW")
176+
self.assert_text("Backpack", "div.cart_item")
177+
self.click("button#finish")
178+
self.assert_exact_text("THANK YOU FOR YOUR ORDER", "h2")
179+
self.assert_element('img[alt="Pony Express"]')
180+
self.js_click("a#logout_sidebar_link")
181+
```
153182
154183
* By default, **[CSS Selectors](https://www.w3schools.com/cssref/css_selectors.asp)** are used for finding page elements.
155184
* If you're new to CSS Selectors, games like [CSS Diner](http://flukeout.github.io/) can help you learn.

examples/ReadMe.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Run an example test in Chrome: (Default: ``--browser=chrome``)
2121
pytest my_first_test.py
2222
```
2323

24+
<img src="https://seleniumbase.io/cdn/gif/swag_labs_4.gif" /><br />
25+
2426
Run an example test in Firefox:
2527

2628
```bash
@@ -29,14 +31,6 @@ pytest my_first_test.py --browser=firefox
2931

3032
Run an example test in Demo Mode: (highlight assertions)
3133

32-
```bash
33-
pytest my_first_test.py --demo
34-
```
35-
36-
<img src="https://seleniumbase.io/cdn/gif/my_first_test_2.gif" title="SeleniumBase Demo Mode" /><br />
37-
38-
Run a different example in Demo Mode:
39-
4034
```bash
4135
pytest test_swag_labs.py --demo
4236
```

examples/basic_test.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
"""
2+
Add an item to a shopping cart, and verify.
3+
"""
14
from seleniumbase import BaseCase
25

36

47
class MyTestClass(BaseCase):
58
def test_basics(self):
6-
self.open("https://store.xkcd.com/search")
7-
self.type('input[name="q"]', "xkcd book\n")
8-
self.assert_text("xkcd book", "div.results")
9-
self.open("https://xkcd.com/353/")
10-
self.click('a[rel="license"]')
11-
self.go_back()
12-
self.click_link("About")
13-
self.click_link("comic #249")
14-
self.assert_element('img[alt*="Chess"]')
9+
self.open("https://www.saucedemo.com")
10+
self.type("#user-name", "standard_user")
11+
self.type("#password", "secret_sauce\n")
12+
self.assert_element("#inventory_container")
13+
self.assert_exact_text("PRODUCTS", "span.title")
14+
self.click('button[name*="backpack"]')
15+
self.click("#shopping_cart_container a")
16+
self.assert_exact_text("YOUR CART", "span.title")
17+
self.assert_text("Backpack", "div.cart_item")
18+
self.js_click("a#logout_sidebar_link")

examples/list_assert_test.py

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

88
class MyTestClass(BaseCase):
99
def test_assert_list_of_elements(self):
10-
self.open("https://store.xkcd.com/collections/posters")
10+
self.open("https://seleniumbase.io/demo_page")
1111
self.assert_elements_present("head", "style", "script")
1212
self.assert_elements("h1", "h2", "h3")
13-
my_list = ["#top-menu", "#col-main", "#col-widgets"]
13+
my_list = ["#myDropdown", "#myButton", "#svgRect"]
1414
self.assert_elements(my_list)

examples/my_first_test.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
1+
"""
2+
A complete end-to-end test for an e-commerce website.
3+
"""
14
from seleniumbase import BaseCase
25

36

47
class MyTestClass(BaseCase):
5-
def test_basics(self):
6-
url = "https://store.xkcd.com/collections/posters"
7-
self.open(url)
8-
self.type('input[name="q"]', "xkcd book")
9-
self.click('input[value="Search"]')
10-
self.assert_text("xkcd: volume 0", "h3")
11-
self.open("https://xkcd.com/353/")
12-
self.assert_title("xkcd: Python")
13-
self.assert_element('img[alt="Python"]')
14-
self.click('a[rel="license"]')
15-
self.assert_text("free to copy and reuse")
16-
self.go_back()
17-
self.click_link("About")
18-
self.assert_exact_text("xkcd.com", "h2")
8+
def test_swag_labs(self):
9+
self.open("https://www.saucedemo.com")
10+
self.type("#user-name", "standard_user")
11+
self.type("#password", "secret_sauce\n")
12+
self.assert_element("#inventory_container")
13+
self.assert_text("PRODUCTS", "span.title")
14+
self.click('button[name*="backpack"]')
15+
self.click("#shopping_cart_container a")
16+
self.assert_text("YOUR CART", "span.title")
17+
self.assert_text("Backpack", "div.cart_item")
18+
self.click("button#checkout")
19+
self.type("#first-name", "SeleniumBase")
20+
self.type("#last-name", "Automation")
21+
self.type("#postal-code", "77123")
22+
self.click("input#continue")
23+
self.assert_text("CHECKOUT: OVERVIEW")
24+
self.assert_text("Backpack", "div.cart_item")
25+
self.click("button#finish")
26+
self.assert_exact_text("THANK YOU FOR YOUR ORDER", "h2")
27+
self.assert_element('img[alt="Pony Express"]')
28+
self.js_click("a#logout_sidebar_link")
1929

2030
####
2131

@@ -123,10 +133,12 @@ def test_basics(self):
123133
# whitespace in the TEXT assertion.
124134
# So, self.assert_exact_text("Some Text") will find [" Some Text "].
125135
#
126-
# 7. If a URL starts with "://", then "https://" is automatically used.
136+
# 7. self.js_click(SELECTOR) can be used to click on hidden elements.
137+
#
138+
# 8. If a URL starts with "://", then "https://" is automatically used.
127139
# Example: [self.open("://URL")] becomes [self.open("https://URL")]
128140
# This helps by reducing the line length by 5 characters.
129141
#
130-
# 8. For the full method list, see one of the following:
142+
# 9. For the full method list, see one of the following:
131143
# * SeleniumBase/seleniumbase/fixtures/base_case.py
132144
# * SeleniumBase/help_docs/method_summary.md

examples/swag_labs_suite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_swag_labs_basic_flow(self, username):
4545
self.assert_exact_text("1", "span.shopping_cart_badge")
4646

4747
# Verify your cart
48-
self.click("#shopping_cart_container")
48+
self.click("#shopping_cart_container a")
4949
self.assert_element('span:contains("Your Cart")')
5050
self.assert_text(item_name, "div.inventory_item_name")
5151
self.assert_exact_text("1", "div.cart_quantity")

examples/test_download_files.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ def test_download_files(self):
6060

6161
# Get file sizes in kB to compare actual values with displayed values
6262
whl_file_kb = whl_file_bytes / 1000.0
63-
whl_line_fi = self.get_text('a[href$=".whl"]')
64-
whl_line = self.get_text('tbody th:contains("%s")' % whl_line_fi)
63+
whl_line_fi = self.get_text('a[href$=".whl"]').strip()
64+
whl_line = self.get_text('div.file:contains("%s")' % whl_line_fi)
6565
whl_display_kb = float(whl_line.split("(")[1].split(" ")[0])
6666
tar_gz_file_kb = tar_gz_file_bytes / 1000.0
67-
tar_gz_line_fi = self.get_text('a[href$=".tar.gz"]')
68-
tar_gz_line = self.get_text('tbody th:contains("%s")' % tar_gz_line_fi)
67+
tar_gz_line_fi = self.get_text('a[href$=".tar.gz"]').strip()
68+
tar_gz_line = self.get_text('div.file:contains("%s")' % tar_gz_line_fi)
6969
tar_gz_display_kb = float(tar_gz_line.split("(")[1].split(" ")[0])
7070

7171
# Verify downloaded files are the correct size (account for rounding)

examples/test_event_firing.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def test_event_firing_webdriver(self):
3131
print("\n* EventFiringWebDriver example *")
3232
self.open("https://xkcd.com/1862/")
3333
self.click("link=About")
34-
self.open("https://store.xkcd.com/search")
35-
self.type('input[name="q"]', "xkcd book\n")
36-
self.open("https://xkcd.com/1822/")
34+
self.open("https://xkcd.com/1820/")
35+
self.assert_text("Security Advice", "#ctitle")
36+
self.click('a:contains("Next >")')
37+
self.assert_text("Incinerator", "#ctitle")
38+
self.click('a[rel="next"]')
39+
self.assert_text("Existential Bug Reports", "#ctitle")

examples/test_swag_labs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_swag_labs_basic_flow(self):
3434
self.assert_exact_text("1", "span.shopping_cart_badge")
3535

3636
# Verify your cart
37-
self.click("#shopping_cart_container")
37+
self.click("#shopping_cart_container a")
3838
self.assert_element('span:contains("Your Cart")')
3939
self.assert_text(item_name, "div.inventory_item_name")
4040
self.assert_exact_text("1", "div.cart_quantity")
@@ -60,7 +60,7 @@ def test_swag_labs_basic_flow(self):
6060
# Finish Checkout and verify that the cart is now empty
6161
self.click("button#finish")
6262
self.assert_exact_text("THANK YOU FOR YOUR ORDER", "h2")
63-
self.click("#shopping_cart_container")
63+
self.click("#shopping_cart_container a")
6464
self.assert_element_absent("div.inventory_item_name")
6565
self.click("button#continue-shopping")
6666
self.assert_element_absent("span.shopping_cart_badge")

examples/test_xkcd.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from seleniumbase import BaseCase
2+
3+
4+
class MyTestClass(BaseCase):
5+
def test_xkcd(self):
6+
self.open("https://xkcd.com/353/")
7+
self.assert_title("xkcd: Python")
8+
self.assert_element('img[alt="Python"]')
9+
self.click('a[rel="license"]')
10+
self.assert_text("free to copy and reuse")
11+
self.go_back()
12+
self.click_link("About")
13+
self.assert_exact_text("xkcd.com", "h2")
14+
self.click_link("comic #249")
15+
self.assert_element('img[alt*="Chess"]')

0 commit comments

Comments
 (0)