|
1 |
| -""" |
2 |
| -A complete end-to-end test for an e-commerce website. |
3 |
| -""" |
| 1 | +"""A complete end-to-end test for an e-commerce website.""" |
4 | 2 | from seleniumbase import BaseCase
|
5 | 3 |
|
6 | 4 |
|
@@ -29,115 +27,121 @@ def test_swag_labs(self):
|
29 | 27 | self.js_click("a#logout_sidebar_link")
|
30 | 28 | self.assert_element("div#login_button_container")
|
31 | 29 |
|
32 |
| - #### |
33 | 30 |
|
34 |
| - ####################################################################### |
35 |
| - # |
36 |
| - # **** NOTES / USEFUL INFO **** |
37 |
| - # |
38 |
| - # 1. By default, page elements are identified by "css selector". |
39 |
| - # CSS Guide: "https://www.w3schools.com/cssref/css_selectors.asp". |
40 |
| - # Other selectors include: "link text", "partial link text", "name", |
41 |
| - # "class name", and "id", but most of those can be expressed as CSS. |
42 |
| - # |
43 |
| - # Here's an example of changing the "by": |
44 |
| - # [ |
45 |
| - # self.click('Next', by="partial link text") |
46 |
| - # ] |
47 |
| - # |
48 |
| - # XPath is used by default if the arg starts with "/", "./", or "(": |
49 |
| - # [ |
50 |
| - # self.click('/html/body/div[3]/div[4]/p[2]/a') |
51 |
| - # ] |
52 |
| - # |
53 |
| - # If you're completely new to CSS selectors, right-click on a |
54 |
| - # web page and select "Inspect" to see the CSS in the html. |
55 |
| - # |
56 |
| - # 2. Most methods have the optional "timeout" argument. |
57 |
| - # Here's an example of changing the "timeout": |
58 |
| - # [ |
59 |
| - # self.assert_element('img[alt="Python"]', timeout=15) |
60 |
| - # ] |
61 |
| - # The "timeout" argument tells the method how many seconds to wait |
62 |
| - # for an element to appear before failing the test. This is |
63 |
| - # useful if a web page needs additional time to load an element. |
64 |
| - # If you don't specify a "timeout", a default timeout is used. |
65 |
| - # Default timeouts are configured in seleniumbase/config/settings.py |
66 |
| - # |
67 |
| - # 3. SeleniumBase methods often perform multiple actions. For example, |
68 |
| - # self.type(SELECTOR, TEXT) will do the following: |
69 |
| - # * Wait for the element to be visible |
70 |
| - # * Wait for the element to be interactive |
71 |
| - # * Clear the text field |
72 |
| - # * Type in the new text |
73 |
| - # * Press Enter/Return if the text ends in "\n": {element.submit()} |
74 |
| - # |
75 |
| - # 4. Duplicate method names may exist for the same method: |
76 |
| - # (This makes it easier to switch over from other test frameworks.) |
77 |
| - # Example: |
78 |
| - # self.open() = self.visit() = self.open_url() = self.goto() |
79 |
| - # self.type() = self.update_text() = self.input() = self.fill() |
80 |
| - # self.send_keys() = self.add_text() |
81 |
| - # self.get_element() = self.wait_for_element_present() |
82 |
| - # self.find_element() = self.wait_for_element_visible() |
83 |
| - # = self.wait_for_element() |
84 |
| - # self.assert_element() = self.assert_element_visible() |
85 |
| - # self.assert_text() = self.assert_text_visible() |
86 |
| - # self.find_text() = self.wait_for_text_visible() |
87 |
| - # = self.wait_for_text() |
88 |
| - # self.click_link("LinkText") = self.click("link=LinkText") |
89 |
| - # = self.click_link_text("LinkText") |
90 |
| - # = self.click('a:contains("LinkText")') |
91 |
| - # * self.get(url) is SPECIAL: * |
92 |
| - # If {url} is a valid URL, self.get() works just like self.open() |
93 |
| - # Otherwise {url} becomes a selector for calling self.get_element() |
94 |
| - # |
95 |
| - # 5. There's usually more than one way to do the same thing. |
96 |
| - # Example 1: |
97 |
| - # [ |
98 |
| - # self.assert_text("xkcd: volume 0", "h3") |
99 |
| - # ] |
100 |
| - # Is the same as: |
101 |
| - # [ |
102 |
| - # text = self.get_text("h3") |
103 |
| - # self.assert_true("xkcd: volume 0" in text) |
104 |
| - # ] |
105 |
| - # Is also the same as: |
106 |
| - # [ |
107 |
| - # element = self.find_element("h3") |
108 |
| - # text = element.text |
109 |
| - # self.assert_true("xkcd: volume 0" in text) |
110 |
| - # ] |
111 |
| - # |
112 |
| - # Example 2: |
113 |
| - # [ |
114 |
| - # self.assert_exact_text("xkcd.com", "h2") |
115 |
| - # ] |
116 |
| - # Is the same as: |
117 |
| - # [ |
118 |
| - # text = self.get_text("h2").strip() |
119 |
| - # self.assert_true("xkcd.com".strip() == text) |
120 |
| - # ] |
121 |
| - # |
122 |
| - # Example 3: |
123 |
| - # [ |
124 |
| - # title = self.get_attribute("#comic img", "title") |
125 |
| - # ] |
126 |
| - # Is the same as: |
127 |
| - # [ |
128 |
| - # element = self.find_element("#comic img") |
129 |
| - # title = element.get_attribute("title") |
130 |
| - # ] |
131 |
| - # |
132 |
| - # 6. self.assert_exact_text(TEXT) ignores leading and trailing |
133 |
| - # whitespace in the TEXT assertion. |
134 |
| - # So, self.assert_exact_text("Some Text") will find [" Some Text "]. |
135 |
| - # |
136 |
| - # 7. self.js_click(SELECTOR) can be used to click on hidden elements. |
137 |
| - # |
138 |
| - # 8. self.open(URL) will automatically complete URLs missing a prefix. |
139 |
| - # Example: google.com will become https://google.com before opened. |
140 |
| - # |
141 |
| - # 9. For the full method list, see one of the following: |
142 |
| - # * SeleniumBase/seleniumbase/fixtures/base_case.py |
143 |
| - # * SeleniumBase/help_docs/method_summary.md |
| 31 | +if __name__ == "__main__": |
| 32 | + from pytest import main |
| 33 | + main([__file__]) |
| 34 | + |
| 35 | + |
| 36 | +####################################################################### |
| 37 | +# |
| 38 | +# **** NOTES / USEFUL INFO **** |
| 39 | +# |
| 40 | +# 1. By default, page elements are identified by "css selector". |
| 41 | +# CSS Guide: "https://www.w3schools.com/cssref/css_selectors.asp". |
| 42 | +# Other selectors include: "link text", "partial link text", "name", |
| 43 | +# "class name", and "id", but most of those can be expressed as CSS. |
| 44 | +# |
| 45 | +# Here's an example of changing the "by": |
| 46 | +# [ |
| 47 | +# self.click('Next', by="partial link text") |
| 48 | +# ] |
| 49 | +# |
| 50 | +# XPath is used by default if the arg starts with "/", "./", or "(": |
| 51 | +# [ |
| 52 | +# self.click('/html/body/div[3]/div[4]/p[2]/a') |
| 53 | +# ] |
| 54 | +# |
| 55 | +# If you're completely new to CSS selectors, right-click on a |
| 56 | +# web page and select "Inspect" to see the CSS in the html. |
| 57 | +# |
| 58 | +# 2. Most methods have the optional "timeout" argument. |
| 59 | +# Here's an example of changing the "timeout": |
| 60 | +# [ |
| 61 | +# self.assert_element('img[alt="Python"]', timeout=15) |
| 62 | +# ] |
| 63 | +# The "timeout" argument tells the method how many seconds to wait |
| 64 | +# for an element to appear before failing the test. This is |
| 65 | +# useful if a web page needs additional time to load an element. |
| 66 | +# If you don't specify a "timeout", a default timeout is used. |
| 67 | +# Default timeouts are configured in seleniumbase/config/settings.py |
| 68 | +# |
| 69 | +# 3. SeleniumBase methods often perform multiple actions. For example, |
| 70 | +# self.type(SELECTOR, TEXT) will do the following: |
| 71 | +# * Wait for the element to be visible |
| 72 | +# * Wait for the element to be interactive |
| 73 | +# * Clear the text field |
| 74 | +# * Type in the new text |
| 75 | +# * Press Enter/Return if the text ends in "\n": {element.submit()} |
| 76 | +# |
| 77 | +# 4. Duplicate method names may exist for the same method: |
| 78 | +# (This makes it easier to switch over from other test frameworks.) |
| 79 | +# Example: |
| 80 | +# self.open() = self.visit() = self.open_url() = self.goto() |
| 81 | +# self.type() = self.update_text() = self.input() = self.fill() |
| 82 | +# self.send_keys() = self.add_text() |
| 83 | +# self.get_element() = self.wait_for_element_present() |
| 84 | +# self.find_element() = self.wait_for_element_visible() |
| 85 | +# = self.wait_for_element() |
| 86 | +# self.assert_element() = self.assert_element_visible() |
| 87 | +# self.assert_text() = self.assert_text_visible() |
| 88 | +# self.find_text() = self.wait_for_text_visible() |
| 89 | +# = self.wait_for_text() |
| 90 | +# self.click_link("LinkText") = self.click("link=LinkText") |
| 91 | +# = self.click_link_text("LinkText") |
| 92 | +# = self.click('a:contains("LinkText")') |
| 93 | +# * self.get(url) is SPECIAL: * |
| 94 | +# If {url} is a valid URL, self.get() works just like self.open() |
| 95 | +# Otherwise {url} becomes a selector for calling self.get_element() |
| 96 | +# |
| 97 | +# 5. There's usually more than one way to do the same thing. |
| 98 | +# Example 1: |
| 99 | +# [ |
| 100 | +# self.assert_text("xkcd: volume 0", "h3") |
| 101 | +# ] |
| 102 | +# Is the same as: |
| 103 | +# [ |
| 104 | +# text = self.get_text("h3") |
| 105 | +# self.assert_true("xkcd: volume 0" in text) |
| 106 | +# ] |
| 107 | +# Is also the same as: |
| 108 | +# [ |
| 109 | +# element = self.find_element("h3") |
| 110 | +# text = element.text |
| 111 | +# self.assert_true("xkcd: volume 0" in text) |
| 112 | +# ] |
| 113 | +# |
| 114 | +# Example 2: |
| 115 | +# [ |
| 116 | +# self.assert_exact_text("xkcd.com", "h2") |
| 117 | +# ] |
| 118 | +# Is the same as: |
| 119 | +# [ |
| 120 | +# text = self.get_text("h2").strip() |
| 121 | +# self.assert_true("xkcd.com".strip() == text) |
| 122 | +# ] |
| 123 | +# |
| 124 | +# Example 3: |
| 125 | +# [ |
| 126 | +# title = self.get_attribute("#comic img", "title") |
| 127 | +# ] |
| 128 | +# Is the same as: |
| 129 | +# [ |
| 130 | +# element = self.find_element("#comic img") |
| 131 | +# title = element.get_attribute("title") |
| 132 | +# ] |
| 133 | +# |
| 134 | +# 6. self.assert_exact_text(TEXT) ignores leading and trailing |
| 135 | +# whitespace in the TEXT assertion. |
| 136 | +# So, self.assert_exact_text("Some Text") will find [" Some Text "]. |
| 137 | +# |
| 138 | +# 7. self.js_click(SELECTOR) can be used to click on hidden elements. |
| 139 | +# |
| 140 | +# 8. self.open(URL) will automatically complete URLs missing a prefix. |
| 141 | +# Example: google.com will become https://google.com before opened. |
| 142 | +# |
| 143 | +# 9. For the full method list, see one of the following: |
| 144 | +# * SeleniumBase/seleniumbase/fixtures/base_case.py |
| 145 | +# * SeleniumBase/help_docs/method_summary.md |
| 146 | +# |
| 147 | +# 10. pytest.main([__file__]) lets you run with "python" (vs. "pytest") |
0 commit comments