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
<h4>Here are a few scripts to test that app with SeleniumBase:</h4>
125
125
126
-
<palign="left">📘📝 An example test with the <b>BaseCase</b> class. Runs with <code>pytest</code> or <code>nosetests</code>. (<ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/ReadMe.md">Learn more</a>)</p>
126
+
<palign="left">📘📝 An example test with the <b>BaseCase</b> class. Runs with <b><ahref="https://docs.pytest.org/en/latest/how-to/usage.html">pytest</a></b> or <b>nosetests</b>. (<ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/ReadMe.md">Learn more</a>)</p>
127
127
128
128
```python
129
129
from seleniumbase import BaseCase
@@ -140,7 +140,7 @@ class TestMFALogin(BaseCase):
140
140
self.save_screenshot_to_logs()
141
141
```
142
142
143
-
<palign="left">📗📝 An example test with the <b>sb</b> <code>pytest</code> fixture. Runs with <code>pytest</code>.</p>
143
+
<palign="left">📗📝 An example test with the <b><code>sb</code></b> <code>pytest</code> fixture. Runs with <b><ahref="https://docs.pytest.org/en/latest/how-to/usage.html">pytest</a></b>.</p>
144
144
145
145
```python
146
146
deftest_mfa_login(sb):
@@ -154,7 +154,25 @@ def test_mfa_login(sb):
154
154
sb.save_screenshot_to_logs()
155
155
```
156
156
157
-
<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 <code>behave</code>. (<ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/behave_bdd/ReadMe.md">Learn more</a>)</p>
157
+
<palign="left">📙📝 An example test with the <b><code>SB</code></b> Context Manager. Runs with pure <b><code>python</code></b>.</p>
158
+
159
+
```python
160
+
from seleniumbase importSB
161
+
162
+
with SB() as sb: # By default, browser="chrome" if not set.
sb.highlight("img#image1") # A fancier assert_element() call
169
+
sb.click('a:contains("This Page")') # Use :contains() on any tag
170
+
sb.click_link("Sign out") # Link must be "a" tag. Not "button".
171
+
sb.assert_element('a:contains("Sign in")')
172
+
sb.assert_exact_text("You have been signed out!", "#top_message")
173
+
```
174
+
175
+
<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>
158
176
159
177
```gherkin
160
178
Feature: SeleniumBase scenarios for the RealWorld App
@@ -178,7 +196,7 @@ Feature: SeleniumBase scenarios for the RealWorld App
178
196
🔵 Using a <ahref="https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/virtualenv_instructions.md">Python virtual env</a> is recommended.
**You can install ``seleniumbase`` from [GitHub](https://github.com/seleniumbase/SeleniumBase) or [PyPI](https://pypi.org/project/seleniumbase/):**
184
202
@@ -261,15 +279,15 @@ COMMANDS:
261
279
```
262
280
263
281
264
-
<h3><img src="https://seleniumbase.github.io/img/green_logo2.png" title="SeleniumBase" width="32" /> Downloading web drivers:</h3>
282
+
<h3><img src="https://seleniumbase.github.io/img/logo3b.png" title="SeleniumBase" width="32" /> Downloading web drivers:</h3>
265
283
266
284
✅ SeleniumBase automatically downloads web drivers as needed, such as ``chromedriver`` and ``geckodriver`` (Firefox).
267
285
268
286
✅ 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/).
269
287
270
288
271
289
<a id="basic_example_and_usage"></a>
272
-
<h3><img src="https://seleniumbase.github.io/img/green_logo2.png" title="SeleniumBase" width="32" /> Basic Example & Usage:</h3>
290
+
<h3><img src="https://seleniumbase.github.io/img/logo3b.png" title="SeleniumBase" width="32" /> Basic Example & Usage:</h3>
273
291
274
292
🔵 If you've cloned SeleniumBase, you can run tests from the [examples/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples) folder.
275
293
@@ -320,7 +338,7 @@ class MyTestClass(BaseCase):
320
338
321
339
322
340
<a id="common_methods"></a>
323
-
<h3><img src="https://seleniumbase.github.io/img/green_logo2.png" title="SeleniumBase" width="32" /> Here are some common SeleniumBase methods that you might find in tests:</h3>
341
+
<h3><img src="https://seleniumbase.github.io/img/logo3b.png" title="SeleniumBase" width="32" /> Here are some common SeleniumBase methods that you might find in tests:</h3>
324
342
325
343
```python
326
344
self.open(url) # Navigate the browser window to the URL.
@@ -361,7 +379,7 @@ self.assert_no_js_errors() # Verify there are no JS errors.
361
379
362
380
363
381
<a id="fun_facts"></a>
364
-
<h2><img src="https://seleniumbase.github.io/img/green_logo2.png" title="SeleniumBase" width="32" /> Fun Facts / Learn More:</h2>
382
+
<h2><img src="https://seleniumbase.github.io/img/logo3b.png" title="SeleniumBase" width="32" /> Fun Facts / Learn More:</h2>
365
383
366
384
<p>✅ SeleniumBase automatically handles common WebDriver actions such as launching web browsers before tests, saving screenshots during failures, and closing web browsers after tests.</p>
🔵 <b>Demo Mode</b> helps you see what a test is doing. If a test is moving too fast for your eyes, run it in <b>Demo Mode</b>, which pauses the browser briefly between actions, highlights page elements being acted on, and displays assertions:
@@ -528,7 +546,8 @@ pytest my_first_test.py --pdb
528
546
--enable-ws # (Enable Web Security on Chromium-based browsers.)
529
547
--enable-sync # (Enable "Chrome Sync" on websites.)
--undetected | --uc # (Use undetected-chromedriver to evade bot-detection.)
549
+
--uc | --undetected # (Use undetected-chromedriver to evade bot-detection.)
550
+
--uc-sub | --uc-subprocess # (Use undetected-chromedriver as a subprocess.)
532
551
--remote-debug # (Enable Chrome's Remote Debugger on http://localhost:9222)
533
552
--final-debug # (Enter Debug Mode after each test ends. Don't use with CI!)
534
553
--dashboard # (Enable the SeleniumBase Dashboard. Saved at: dashboard.html)
@@ -570,7 +589,7 @@ Here's the command-line option to add to tests: (See [examples/custom_settings.p
570
589
Inside your tests, you can use ``self.data`` to access that.
571
590
572
591
573
-
<h3><img src="https://seleniumbase.github.io/img/green_logo2.png" title="SeleniumBase" width="32" /> Test Directory Configuration:</h3>
592
+
<h3><img src="https://seleniumbase.github.io/img/logo3b.png" title="SeleniumBase" width="32" /> Test Directory Configuration:</h3>
574
593
575
594
🔵 When running tests with **pytest**, you'll want a copy of **[pytest.ini](https://github.com/seleniumbase/SeleniumBase/blob/master/pytest.ini)**in your root folders. When running tests with **nosetests**, you'll want a copy of **[setup.cfg](https://github.com/seleniumbase/SeleniumBase/blob/master/setup.cfg)** in your root folders. These files specify default configuration details for tests. Folders should also include a blank ``__init__.py`` file, which allows your tests to import files from that folder.
576
595
@@ -626,7 +645,7 @@ Of those files, the ``pytest.ini`` config file is the most important, followed b
626
645
627
646
--------
628
647
629
-
<h3><img src="https://seleniumbase.github.io/img/green_logo2.png" title="SeleniumBase" width="32" /> Log files from failed tests:</h3>
648
+
<h3><img src="https://seleniumbase.github.io/img/logo3b.png" title="SeleniumBase" width="32" /> Log files from failed tests:</h3>
630
649
631
650
Let's try an example of a test that fails:
632
651
@@ -651,7 +670,7 @@ pytest test_fail.py
651
670
652
671
--------
653
672
654
-
<h3><img src="https://seleniumbase.github.io/img/green_logo2.png" title="SeleniumBase" width="32" /> The SeleniumBase Dashboard:</h3>
673
+
<h3><img src="https://seleniumbase.github.io/img/logo3b.png" title="SeleniumBase" width="32" /> The SeleniumBase Dashboard:</h3>
655
674
656
675
🔵 The ``--dashboard`` option for pytest generates a SeleniumBase Dashboard located at ``dashboard.html``, which updates automatically as tests run and produce results. Example:
<h3><img src="https://seleniumbase.github.io/img/green_logo2.png" title="SeleniumBase" width="32" /> Using a Proxy Server:</h3>
777
+
<h3><img src="https://seleniumbase.github.io/img/logo3b.png" title="SeleniumBase" width="32" /> Using a Proxy Server:</h3>
759
778
760
779
If you wish to use a proxy server for your browser tests (Chromium or Firefox), you can add ``--proxy=IP_ADDRESS:PORT`` as an argument on the command line.
<h3><img src="https://seleniumbase.github.io/img/green_logo2.png" title="SeleniumBase" width="32" /> Changing the User-Agent:</h3>
806
+
<h3><img src="https://seleniumbase.github.io/img/logo3b.png" title="SeleniumBase" width="32" /> Changing the User-Agent:</h3>
788
807
789
808
🔵 If you wish to change the User-Agent for your browser tests (Chromium and Firefox only), you can add ``--agent="USER AGENT STRING"`` as an argument on the command-line.
<h3><img src="https://seleniumbase.github.io/img/green_logo2.png" title="SeleniumBase" width="32" /> Handling Pop-Up / Pop Up Alerts:</h3>
815
+
<h3><img src="https://seleniumbase.github.io/img/logo3b.png" title="SeleniumBase" width="32" /> Handling Pop-Up / Pop Up Alerts:</h3>
797
816
798
817
🔵 <code>self.accept_alert()</code> automatically waits for and accepts alert pop-ups. <code>self.dismiss_alert()</code> automatically waits for and dismisses alert pop-ups. On occasion, some methods like <code>self.click(SELECTOR)</code> might dismiss a pop-up on its own because they call JavaScript to make sure that the <code>readyState</code> of the page is <code>complete</code> before advancing. If you're trying to accept a pop-up that got dismissed this way, use this workaround: Call <code>self.find_element(SELECTOR).click()</code> instead, (which will let the pop-up remain on the screen), and then use <code>self.accept_alert()</code> to accept the pop-up (<a href="https://github.com/seleniumbase/SeleniumBase/issues/600#issuecomment-647270426">more on that here</a>). If pop-ups are intermittent, wrap code in a try/except block.
799
818
800
819
801
-
<h3><img src="https://seleniumbase.github.io/img/green_logo2.png" title="SeleniumBase" width="32" /> Building Guided Tours for Websites:</h3>
820
+
<h3><img src="https://seleniumbase.github.io/img/logo3b.png" title="SeleniumBase" width="32" /> Building Guided Tours for Websites:</h3>
802
821
803
822
🔵 Learn about <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/tour_examples/ReadMe.md">SeleniumBase Interactive Walkthroughs</a> (in the ``examples/tour_examples/`` folder). It's great for prototyping a website onboarding experience.
<p>You can use the <code>@retry_on_exception()</code> decorator to retry failing methods. (First import: <code>from seleniumbase import decorators</code>). To learn more about SeleniumBase decorators, <a href="https://github.com/seleniumbase/SeleniumBase/tree/master/seleniumbase/common">click here</a>.</p>
0 commit comments