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: README.md
+51-18Lines changed: 51 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -217,7 +217,7 @@ with SB() as sb: # By default, browser="chrome" if not set.
217
217
sb.assert_exact_text("You have been signed out!", "#top_message")
218
218
```
219
219
220
-
<palign="left">📕📝 An example test with <b>behave-BDD</b> <ahref="https://behave.readthedocs.io/en/stable/gherkin.html"target="_blank">Gherkin</a> structure. Runs with <b><code>behave</code></b>. (<ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/behave_bdd/ReadMe.md">Learn more</a>)</p>
220
+
<palign="left">📕📝 An example test with <b>behave-BDD</b> <ahref="https://behave.readthedocs.io/en/stable/gherkin.html#features"target="_blank">Gherkin</a> structure. Runs with <b><code>behave</code></b>. (<ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/behave_bdd/ReadMe.md">Learn more</a>)</p>
221
221
222
222
```gherkin
223
223
Feature: SeleniumBase scenarios for the RealWorld App
@@ -252,7 +252,7 @@ Feature: SeleniumBase scenarios for the RealWorld App
252
252
253
253
**You can install ``seleniumbase`` from [PyPI](https://pypi.org/project/seleniumbase/) or [GitHub](https://github.com/seleniumbase/SeleniumBase):**
254
254
255
-
🔵 **Installing``seleniumbase`` from PyPI:**
255
+
🔵 **How to install``seleniumbase`` from PyPI:**
256
256
257
257
```bash
258
258
pip install seleniumbase
@@ -262,22 +262,22 @@ pip install seleniumbase
262
262
* (Add ``--force-reinstall`` to upgrade indirect packages.)
263
263
* (Use ``pip3`` if multiple versions of Python are present.)
264
264
265
-
🔵 **Installing``seleniumbase`` from a GitHub clone:**
265
+
🔵 **How to install``seleniumbase`` from a GitHub clone:**
Making [chromedriver 114.0.5735.90] executable ...
349
+
[chromedriver 114.0.5735.90] is now ready for use!
350
+
```
351
+
352
+
</details>
353
+
332
354
✅ To manually download a webdriver, see [Console Scripts](https://seleniumbase.io/seleniumbase/console_scripts/ReadMe/) OR [Webdriver Installation](https://seleniumbase.io/help_docs/webdriver_installation/).
333
355
334
356
@@ -441,7 +463,7 @@ self.assert_no_js_errors() # Verify there are no JS errors.
441
463
self.type("input", "dogs\n")
442
464
```
443
465
444
-
Most SeleniumBase scripts can be run with <code>pytest</code>, <code>pynose</code>, or pure <code>python</code>. Not all test runners can run all test formats. For example, tests that use the ``sb`` pytest fixture can only be run with ``pytest``. (See <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md">Syntax Formats</a>) There's also a <a href="https://behave.readthedocs.io/en/stable/gherkin.html" target="_blank">Gherkin</a>test format that runs with <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/behave_bdd/ReadMe.md">behave</a>.
466
+
Most SeleniumBase scripts can be run with <code>pytest</code>, <code>pynose</code>, or pure <code>python</code>. Not all test runners can run all test formats. For example, tests that use the ``sb`` pytest fixture can only be run with ``pytest``. (See <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md">Syntax Formats</a>) There's also a <a href="https://behave.readthedocs.io/en/stable/gherkin.html#features" target="_blank">Gherkin</a> test format that runs with <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/behave_bdd/ReadMe.md">behave</a>.
445
467
446
468
```bash
447
469
pytest test_sb_fixture.py
@@ -1120,16 +1142,27 @@ if self.is_link_text_visible("Stop! Hammer time!"):
1120
1142
self.switch_to_window(1) # This switches to the new tab (0 is the first one)
1121
1143
```
1122
1144
1123
-
🔵 <b>ProTip™:</b> iframes follow the same principle as new windows - you need to specify the iframe if you want to take action on something in there
1145
+
<h3>🔵 How to handle iframes:</h3>
1146
+
1147
+
🔵 <b>ProTip™:</b> iframes follow the same principle as new windows: You must first switch to the iframe if you want to perform actions in there:
1148
+
1149
+
```python
1150
+
self.switch_to_frame("iframe")
1151
+
# ... Now perform actions inside the iframe
1152
+
self.switch_to_parent_frame() # Exit the current iframe
1153
+
```
1154
+
1155
+
To exit from multiple iframes, use ``self.switch_to_default_content()``. If inside a single iframe, this has the same effect as ``self.switch_to_parent_frame()``.
1156
+
1157
+
🔵 You can also use a context manager to act inside iframes:
🛑 Some websites have a restrictive [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) to prevent users from loading jQuery and other external libraries onto their websites. If you need to use jQuery or another JS library on such a website, add ``--disable-csp`` as a ``pytest`` command-line option.
1179
1212
@@ -1196,7 +1229,7 @@ self.click("a.analytics") # Clicks the generated button
1196
1229
1197
1230
</details>
1198
1231
1199
-
<h3>🔵 Using deferred asserts:</h3>
1232
+
<h3>🔵 How to use deferred asserts:</h3>
1200
1233
1201
1234
<p>Let's say you want to verify multiple different elements on a web page in a single test, but you don't want the test to fail until you verified several elements at once so that you don't have to rerun the test to find more missing elements on the same page. That's where deferred asserts come in. Here's the example:</p>
1202
1235
@@ -1220,7 +1253,7 @@ class MyTestClass(BaseCase):
1220
1253
<code>deferred_assert_element()</code> and <code>deferred_assert_text()</code> will save any exceptions that would be raised.
1221
1254
To flush out all the failed deferred asserts into a single exception, make sure to call <code>self.process_deferred_asserts()</code> at the end of your test method. If your test hits multiple pages, you can call <code>self.process_deferred_asserts()</code> before navigating to a new page so that the screenshot from your log files matches the URL where the deferred asserts were made.
<h3>🔵 How to access raw<a href="https://www.selenium.dev/documentation/webdriver/" target="_blank">WebDriver</a>:</h3>
1224
1257
1225
1258
<p>If you need access to any commands that come with standard <a href="https://www.selenium.dev/documentation/webdriver/" target="_blank">WebDriver</a>, you can call them directly like this:</p>
1226
1259
@@ -1234,7 +1267,7 @@ self.driver.find_elements("partial link text", "GitHub")
1234
1267
1235
1268
<h3>🔵 How to retry failing tests automatically:</h3>
1236
1269
1237
-
<p>You can use <code>--reruns=NUM</code> to retry failing tests that many times. Use <code>--reruns-delay=SECONDS</code> to wait that many seconds between retries. Example:</p>
1270
+
<p>You can use <code>pytest --reruns=NUM</code> to retry failing tests that many times. Add <code>--reruns-delay=SECONDS</code> to wait that many seconds between retries. Example:</p>
0 commit comments