Skip to content

Commit ab314e6

Browse files
committed
Update examples of SeleniumBase Syntax Formats
1 parent 9122869 commit ab314e6

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

help_docs/syntax_formats.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -116,46 +116,46 @@ With SeleniumBase, you can use Page Objects to break out code from tests, but re
116116
```python
117117
from seleniumbase import BaseCase
118118

119-
class DataPage():
119+
class LoginPage():
120120

121-
def go_to_data_url(self, sb):
122-
sb.open("data:text/html,<p>Hello!</p><input />")
121+
def login_to_swag_labs(self, sb, username):
122+
sb.open("https://www.saucedemo.com/")
123+
sb.type("#user-name", username)
124+
sb.type("#password", "secret_sauce")
125+
sb.click('input[type="submit"]')
123126

124-
def add_input_text(self, sb, text):
125-
sb.type("input", text)
127+
class MyTests(BaseCase):
126128

127-
class ObjTests(BaseCase):
128-
129-
def test_data_url_page(self):
130-
DataPage().go_to_data_url(self)
131-
self.assert_text("Hello!", "p")
132-
DataPage().add_input_text(self, "Goodbye!")
129+
def test_swag_labs_login(self):
130+
LoginPage().login_to_swag_labs(self, "standard_user")
131+
self.assert_element("#inventory_container")
132+
self.assert_text("Products", "div.product_label")
133133
```
134134

135-
(See <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/boilerplates/classic_obj_test.py">examples/boilerplates/classic_obj_test.py</a> for the full test.)
135+
(See <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/boilerplates/samples/swag_labs_test.py">examples/boilerplates/samples/swag_labs_test.py</a> for the full test.)
136136

137137
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 6. The classic Page Object Model with the <code>sb</code> pytest fixture</h3>
138138

139139
This is similar to the classic Page Object Model with <code>BaseCase</code> inheritance, except that this time we pass the <code>sb</code> pytest fixture from the test into the <code>sb</code> arg of the page object class method, (instead of passing <code>self</code>). Now that you're using <code>sb</code> as a pytest fixture, you no longer need to import <code>BaseCase</code> anywhere in your code. See the example below:
140140

141141
```python
142-
class DataPage():
143-
144-
def go_to_data_url(self, sb):
145-
sb.open("data:text/html,<p>Hello!</p><input />")
142+
class LoginPage():
146143

147-
def add_input_text(self, sb, text):
148-
sb.type("input", text)
144+
def login_to_swag_labs(self, sb, username):
145+
sb.open("https://www.saucedemo.com/")
146+
sb.type("#user-name", username)
147+
sb.type("#password", "secret_sauce")
148+
sb.click('input[type="submit"]')
149149

150-
class ObjTests():
150+
class MyTests():
151151

152-
def test_data_url_page(self, sb):
153-
DataPage().go_to_data_url(sb)
154-
sb.assert_text("Hello!", "p")
155-
DataPage().add_input_text(sb, "Goodbye!")
152+
def test_swag_labs_login(self, sb):
153+
LoginPage().login_to_swag_labs(sb, "standard_user")
154+
sb.assert_element("#inventory_container")
155+
sb.assert_text("Products", "div.product_label")
156156
```
157157

158-
(See <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/boilerplates/sb_fixture_test.py">examples/boilerplates/sb_fixture_test.py</a> for the full test.)
158+
(See <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/boilerplates/samples/sb_swag_test.py">examples/boilerplates/samples/sb_swag_test.py</a> for the full test.)
159159

160160
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 7. Using the <code>request</code> fixture to get the <code>sb</code> fixture (no class)</h3>
161161

0 commit comments

Comments
 (0)