|
| 1 | +""" |
| 2 | +A complete end-to-end test for an e-commerce website. |
| 3 | +""" |
1 | 4 | from seleniumbase import BaseCase |
2 | 5 |
|
3 | 6 |
|
4 | 7 | 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") |
19 | 29 |
|
20 | 30 | #### |
21 | 31 |
|
@@ -123,10 +133,12 @@ def test_basics(self): |
123 | 133 | # whitespace in the TEXT assertion. |
124 | 134 | # So, self.assert_exact_text("Some Text") will find [" Some Text "]. |
125 | 135 | # |
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. |
127 | 139 | # Example: [self.open("://URL")] becomes [self.open("https://URL")] |
128 | 140 | # This helps by reducing the line length by 5 characters. |
129 | 141 | # |
130 | | - # 8. For the full method list, see one of the following: |
| 142 | + # 9. For the full method list, see one of the following: |
131 | 143 | # * SeleniumBase/seleniumbase/fixtures/base_case.py |
132 | 144 | # * SeleniumBase/help_docs/method_summary.md |
0 commit comments