You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/ReadMe.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@
9
9
* Chrome is the default browser if not specified.
10
10
* Example tests are located in: <b>[SeleniumBase/examples/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples)</b>.
11
11
* During test failures, logs and screenshots from the latest test run are saved to the ``latest_logs/`` folder.
12
-
* Tests can be structured using [15 unique syntax formats](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md).
12
+
* Tests can be structured using [17 unique syntax formats](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md).
13
13
14
14
(NOTE: Some example tests fail on purpose to demonstrate [logging features](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/example_logs/ReadMe.md).)
<b>SeleniumBase</b> supports 15 different syntax formats for structuring tests. (<i>The first 4 are the most common.</i>)
12
+
<b>SeleniumBase</b> supports 17 different syntax formats for structuring tests. (<i>The first 6 are the most common.</i>)
13
13
14
14
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 1. <code>BaseCase</code> direct inheritance</h3>
15
15
@@ -19,6 +19,7 @@ This format is used by most of the examples in the <a href="https://github.com/s
19
19
from seleniumbase import BaseCase
20
20
21
21
classMyTestClass(BaseCase):
22
+
22
23
deftest_demo_site(self):
23
24
self.open("https://seleniumbase.io/demo_page")
24
25
self.type("#myTextInput", "This is Automated")
@@ -67,8 +68,8 @@ class BaseTestCase(BaseCase):
67
68
# <<< Placeholder. Add your code here. >>>
68
69
pass
69
70
70
-
71
71
classMyTests(BaseTestCase):
72
+
72
73
deftest_example(self):
73
74
self.login()
74
75
self.example_method()
@@ -108,7 +109,55 @@ class Test_SB_Fixture():
108
109
109
110
(See the bottom of <ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_sb_fixture.py">examples/test_sb_fixture.py</a> for the test.)
110
111
111
-
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 5. Using the <code>request</code> fixture to get the <code>sb</code> fixture (no class)</h3>
112
+
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 5. The classic Page Object Model with <code>BaseCase</code> inheritance</h3>
113
+
114
+
With SeleniumBase, you can use Page Objects to break out code from tests, but remember, the <code>self</code> variable (from test methods that inherit <code>BaseCase</code>) contains the driver and all other framework-specific variable definitions. Therefore, that <code>self</code> must be passed as an arg into any outside class method in order to call SeleniumBase methods from there. In the example below, the <code>self</code> variable from the test method is passed into the <code>sb</code> arg of the Page Object class method because the <code>self</code> arg of the Page Object class method is already being used for its own class. Every Python class method definition must include the <code>self</code> as the first arg.
115
+
116
+
```python
117
+
from seleniumbase import BaseCase
118
+
119
+
classDataPage():
120
+
121
+
defgo_to_data_url(self, sb):
122
+
sb.open("data:text/html,<p>Hello!</p><input />")
123
+
124
+
defadd_input_text(self, sb, text):
125
+
sb.type("input", text)
126
+
127
+
classObjTests(BaseCase):
128
+
129
+
deftest_data_url_page(self):
130
+
DataPage().go_to_data_url(self)
131
+
self.assert_text("Hello!", "p")
132
+
DataPage().add_input_text(self, "Goodbye!")
133
+
```
134
+
135
+
(See <ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/boilerplates/classic_obj_test.py">examples/test_demo_site.py</a> for the full test.)
136
+
137
+
<h3><imgsrc="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>
138
+
139
+
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:
140
+
141
+
```python
142
+
classDataPage():
143
+
144
+
defgo_to_data_url(self, sb):
145
+
sb.open("data:text/html,<p>Hello!</p><input />")
146
+
147
+
defadd_input_text(self, sb, text):
148
+
sb.type("input", text)
149
+
150
+
classObjTests():
151
+
152
+
deftest_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!")
156
+
```
157
+
158
+
(See <ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/boilerplates/sb_fixture_test.py">examples/test_demo_site.py</a> for the full test.)
159
+
160
+
<h3><imgsrc="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>
112
161
113
162
The pytest <code>request</code> fixture can be used to retrieve other pytest fixtures from within tests, such as the <code>sb</code> fixture. This allows you to have more control over when fixtures get initialized because the fixture no longer needs to be loaded at the very beginning of test methods. This is done by calling <code>request.getfixturevalue('sb')</code> from the test. Here's an example of using the pytest <code>request</code> fixture to load the <code>sb</code> fixture in a test method that does not use Python classes:
(See the top of <ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_request_sb_fixture.py">examples/test_request_sb_fixture.py</a> for the test.)
127
176
128
-
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 6. Using the <code>request</code> fixture to get the <code>sb</code> fixture (in class)</h3>
177
+
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 8. Using the <code>request</code> fixture to get the <code>sb</code> fixture (in class)</h3>
129
178
130
179
The pytest <code>request</code> fixture can also be used to get the <code>sb</code> fixture from inside a Python class. Here's an example of that:
131
180
@@ -144,7 +193,7 @@ class Test_Request_Fixture():
144
193
145
194
(See the bottom of <ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_request_sb_fixture.py">examples/test_request_sb_fixture.py</a> for the test.)
146
195
147
-
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 7. SeleniumBase in Chinese</h3>
196
+
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 9. SeleniumBase in Chinese</h3>
148
197
149
198
This format is similar to the English version with <code>BaseCase</code> inheritance, but there's a different import statement, and method names have been translated into Chinese. Here's an example of that:
150
199
@@ -172,7 +221,7 @@ class 我的测试类(硒测试用例):
172
221
173
222
(See <ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/translations/chinese_test_1.py">examples/translations/chinese_test_1.py</a> for the Chinese test.)
174
223
175
-
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 8. SeleniumBase in Dutch</h3>
224
+
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 10. SeleniumBase in Dutch</h3>
176
225
177
226
This format is similar to the English version with <code>BaseCase</code> inheritance, but there's a different import statement, and method names have been translated into Dutch. Here's an example of that:
178
227
@@ -200,7 +249,7 @@ class MijnTestklasse(Testgeval):
200
249
201
250
(See <ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/translations/dutch_test_1.py">examples/translations/dutch_test_1.py</a> for the Dutch test.)
202
251
203
-
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 9. SeleniumBase in French</h3>
252
+
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 11. SeleniumBase in French</h3>
204
253
205
254
This format is similar to the English version with <code>BaseCase</code> inheritance, but there's a different import statement, and method names have been translated into French. Here's an example of that:
206
255
@@ -228,7 +277,7 @@ class MaClasseDeTest(CasDeBase):
228
277
229
278
(See <ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/translations/french_test_1.py">examples/translations/french_test_1.py</a> for the French test.)
230
279
231
-
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 10. SeleniumBase in Italian</h3>
280
+
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 12. SeleniumBase in Italian</h3>
232
281
233
282
This format is similar to the English version with <code>BaseCase</code> inheritance, but there's a different import statement, and method names have been translated into Italian. Here's an example of that:
234
283
@@ -256,7 +305,7 @@ class MiaClasseDiTest(CasoDiProva):
256
305
257
306
(See <ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/translations/italian_test_1.py">examples/translations/italian_test_1.py</a> for the Italian test.)
258
307
259
-
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 11. SeleniumBase in Japanese</h3>
308
+
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 13. SeleniumBase in Japanese</h3>
260
309
261
310
This format is similar to the English version with <code>BaseCase</code> inheritance, but there's a different import statement, and method names have been translated into Japanese. Here's an example of that:
262
311
@@ -285,7 +334,7 @@ class 私のテストクラス(セレニウムテストケース):
285
334
286
335
(See <ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/translations/japanese_test_1.py">examples/translations/japanese_test_1.py</a> for the Japanese test.)
287
336
288
-
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 12. SeleniumBase in Korean</h3>
337
+
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 14. SeleniumBase in Korean</h3>
289
338
290
339
This format is similar to the English version with <code>BaseCase</code> inheritance, but there's a different import statement, and method names have been translated into Korean. Here's an example of that:
291
340
@@ -312,7 +361,7 @@ class 테스트_클래스(셀레늄_테스트_케이스):
312
361
313
362
(See <ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/translations/korean_test_1.py">examples/translations/korean_test_1.py</a> for the Korean test.)
314
363
315
-
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 13. SeleniumBase in Portuguese</h3>
364
+
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 15. SeleniumBase in Portuguese</h3>
316
365
317
366
This format is similar to the English version with <code>BaseCase</code> inheritance, but there's a different import statement, and method names have been translated into Portuguese. Here's an example of that:
318
367
@@ -342,7 +391,7 @@ class MinhaClasseDeTeste(CasoDeTeste):
342
391
343
392
(See <ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/translations/portuguese_test_1.py">examples/translations/portuguese_test_1.py</a> for the Portuguese test.)
344
393
345
-
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 14. SeleniumBase in Russian</h3>
394
+
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 16. SeleniumBase in Russian</h3>
346
395
347
396
This format is similar to the English version with <code>BaseCase</code> inheritance, but there's a different import statement, and method names have been translated into Russian. Here's an example of that:
348
397
@@ -370,7 +419,7 @@ class МойТестовыйКласс(ТестНаСелен):
370
419
371
420
(See <ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/translations/russian_test_1.py">examples/translations/russian_test_1.py</a> for the Russian test.)
372
421
373
-
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 15. SeleniumBase in Spanish</h3>
422
+
<h3><imgsrc="https://seleniumbase.io/img/green_logo.png"title="SeleniumBase"width="32" /> 17. SeleniumBase in Spanish</h3>
374
423
375
424
This format is similar to the English version with <code>BaseCase</code> inheritance, but there's a different import statement, and method names have been translated into Spanish. Here's an example of that:
0 commit comments