Skip to content

Commit 3e0b46b

Browse files
committed
Update the list of SeleniumBase Syntax Formats
1 parent 0869b11 commit 3e0b46b

File tree

2 files changed

+65
-16
lines changed

2 files changed

+65
-16
lines changed

examples/ReadMe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Chrome is the default browser if not specified.
1010
* Example tests are located in: <b>[SeleniumBase/examples/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples)</b>.
1111
* 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).
1313

1414
(NOTE: Some example tests fail on purpose to demonstrate [logging features](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/example_logs/ReadMe.md).)
1515

help_docs/syntax_formats.md

Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<h3 align="left"><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.io/cdn/img/mac_sb_logo_3.png" title="SeleniumBase" width="360" /></a></h3>
22

33
<a id="syntax_formats"></a>
4-
<h2><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> The 15 syntax formats</h2>
4+
<h2><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> The 17 syntax formats</h2>
55

66
<p>(<b><a href="https://youtu.be/VvwtS9_1m0s">Watch this tutorial on YouTube</a></b>)</p>
77

8-
[<img src="http://img.youtube.com/vi/VvwtS9_1m0s/mq1.jpg" title="15 SeleniumBase syntax formats" width="270">](https://youtu.be/VvwtS9_1m0s)
8+
[<img src="http://img.youtube.com/vi/VvwtS9_1m0s/mq1.jpg" title="17 SeleniumBase syntax formats" width="270">](https://youtu.be/VvwtS9_1m0s)
99

1010
--------
1111

12-
<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>)
1313

1414
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 1. <code>BaseCase</code> direct inheritance</h3>
1515

@@ -19,6 +19,7 @@ This format is used by most of the examples in the <a href="https://github.com/s
1919
from seleniumbase import BaseCase
2020

2121
class MyTestClass(BaseCase):
22+
2223
def test_demo_site(self):
2324
self.open("https://seleniumbase.io/demo_page")
2425
self.type("#myTextInput", "This is Automated")
@@ -67,8 +68,8 @@ class BaseTestCase(BaseCase):
6768
# <<< Placeholder. Add your code here. >>>
6869
pass
6970

70-
7171
class MyTests(BaseTestCase):
72+
7273
def test_example(self):
7374
self.login()
7475
self.example_method()
@@ -108,7 +109,55 @@ class Test_SB_Fixture():
108109

109110
(See the bottom of <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_sb_fixture.py">examples/test_sb_fixture.py</a> for the test.)
110111

111-
<h3><img src="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><img src="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+
class DataPage():
120+
121+
def go_to_data_url(self, sb):
122+
sb.open("data:text/html,<p>Hello!</p><input />")
123+
124+
def add_input_text(self, sb, text):
125+
sb.type("input", text)
126+
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!")
133+
```
134+
135+
(See <a href="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><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>
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+
class DataPage():
143+
144+
def go_to_data_url(self, sb):
145+
sb.open("data:text/html,<p>Hello!</p><input />")
146+
147+
def add_input_text(self, sb, text):
148+
sb.type("input", text)
149+
150+
class ObjTests():
151+
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!")
156+
```
157+
158+
(See <a href="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><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>
112161

113162
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:
114163

@@ -125,7 +174,7 @@ def test_request_sb_fixture(request):
125174

126175
(See the top of <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_request_sb_fixture.py">examples/test_request_sb_fixture.py</a> for the test.)
127176

128-
<h3><img src="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><img src="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>
129178

130179
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:
131180

@@ -144,7 +193,7 @@ class Test_Request_Fixture():
144193

145194
(See the bottom of <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_request_sb_fixture.py">examples/test_request_sb_fixture.py</a> for the test.)
146195

147-
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 7. SeleniumBase in Chinese</h3>
196+
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 9. SeleniumBase in Chinese</h3>
148197

149198
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:
150199

@@ -172,7 +221,7 @@ class 我的测试类(硒测试用例):
172221

173222
(See <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/translations/chinese_test_1.py">examples/translations/chinese_test_1.py</a> for the Chinese test.)
174223

175-
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 8. SeleniumBase in Dutch</h3>
224+
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 10. SeleniumBase in Dutch</h3>
176225

177226
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:
178227

@@ -200,7 +249,7 @@ class MijnTestklasse(Testgeval):
200249

201250
(See <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/translations/dutch_test_1.py">examples/translations/dutch_test_1.py</a> for the Dutch test.)
202251

203-
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 9. SeleniumBase in French</h3>
252+
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 11. SeleniumBase in French</h3>
204253

205254
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:
206255

@@ -228,7 +277,7 @@ class MaClasseDeTest(CasDeBase):
228277

229278
(See <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/translations/french_test_1.py">examples/translations/french_test_1.py</a> for the French test.)
230279

231-
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 10. SeleniumBase in Italian</h3>
280+
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 12. SeleniumBase in Italian</h3>
232281

233282
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:
234283

@@ -256,7 +305,7 @@ class MiaClasseDiTest(CasoDiProva):
256305

257306
(See <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/translations/italian_test_1.py">examples/translations/italian_test_1.py</a> for the Italian test.)
258307

259-
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 11. SeleniumBase in Japanese</h3>
308+
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 13. SeleniumBase in Japanese</h3>
260309

261310
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:
262311

@@ -285,7 +334,7 @@ class 私のテストクラス(セレニウムテストケース):
285334

286335
(See <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/translations/japanese_test_1.py">examples/translations/japanese_test_1.py</a> for the Japanese test.)
287336

288-
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 12. SeleniumBase in Korean</h3>
337+
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 14. SeleniumBase in Korean</h3>
289338

290339
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:
291340

@@ -312,7 +361,7 @@ class 테스트_클래스(셀레늄_테스트_케이스):
312361

313362
(See <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/translations/korean_test_1.py">examples/translations/korean_test_1.py</a> for the Korean test.)
314363

315-
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 13. SeleniumBase in Portuguese</h3>
364+
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 15. SeleniumBase in Portuguese</h3>
316365

317366
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:
318367

@@ -342,7 +391,7 @@ class MinhaClasseDeTeste(CasoDeTeste):
342391

343392
(See <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/translations/portuguese_test_1.py">examples/translations/portuguese_test_1.py</a> for the Portuguese test.)
344393

345-
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 14. SeleniumBase in Russian</h3>
394+
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 16. SeleniumBase in Russian</h3>
346395

347396
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:
348397

@@ -370,7 +419,7 @@ class МойТестовыйКласс(ТестНаСелен):
370419

371420
(See <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/translations/russian_test_1.py">examples/translations/russian_test_1.py</a> for the Russian test.)
372421

373-
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 15. SeleniumBase in Spanish</h3>
422+
<h3><img src="https://seleniumbase.io/img/green_logo.png" title="SeleniumBase" width="32" /> 17. SeleniumBase in Spanish</h3>
374423

375424
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:
376425

0 commit comments

Comments
 (0)