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
+32-30Lines changed: 32 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -411,7 +411,7 @@ The code above will leave your browser window open in case there's a failure. (i
411
411
412
412
(For more details, see the full list of command-line options **[here](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/pytest_plugin.py)**.)
413
413
414
-
During test failures, logs and screenshots from the most recent test run will get saved to the ``latest_logs/`` folder. Those logs will get moved to ``archived_logs/``if you add --archive_logs to command-line options, or have ARCHIVE_EXISTING_LOGS set to True in [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py), otherwise log files with be cleaned up at the start of the next test run. The ``test_suite.py`` collection contains tests that fail on purpose so that you can see how logging works.
414
+
🔵 During test failures, logs and screenshots from the most recent test run will get saved to the ``latest_logs/`` folder. Those logs will get moved to ``archived_logs/``if you add --archive_logs to command-line options, or have ARCHIVE_EXISTING_LOGS set to True in [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py), otherwise log files with be cleaned up at the start of the next test run. The ``test_suite.py`` collection contains tests that fail on purpose so that you can see how logging works.
415
415
416
416
```bash
417
417
cd examples/
@@ -426,15 +426,15 @@ Here's the command-line option to add to tests: (See [examples/custom_settings.p
426
426
``--settings_file=custom_settings.py``
427
427
(Settings include default timeout values, a two-factor auth key, DB credentials, S3 credentials, and other important settings used by tests.)
428
428
429
-
To pass additional data from the command-line to tests, add ``--data="ANY STRING"``.
429
+
🔵 To pass additional data from the command-line to tests, add ``--data="ANY STRING"``.
430
430
Inside your tests, you can use ``self.data`` to access that.
431
431
432
432
433
433
<h3><img src="https://seleniumbase.io/img/logo6.png" title="SeleniumBase" width="32" /> Test Directory Customization:</h3>
434
434
435
-
For running tests outside of the SeleniumBase repo with **Pytest**, you'll want a copy of **[pytest.ini](https://github.com/seleniumbase/SeleniumBase/blob/master/pytest.ini)** on the root folder. For running tests outside of the SeleniumBase repo with **Nosetests**, you'll want a copy of **[setup.cfg](https://github.com/seleniumbase/SeleniumBase/blob/master/setup.cfg)** on the root folder. (Subfolders should include a blank ``__init__.py`` file.) These files specify default configuration details for tests. (For nosetest runs, you can also specify a .cfg file by using ``--config``. Example ``nosetests [MY_TEST.py] --config=[MY_CONFIG.cfg]``)
435
+
🔵 For running tests outside of the SeleniumBase repo with **pytest**, you'll want a copy of **[pytest.ini](https://github.com/seleniumbase/SeleniumBase/blob/master/pytest.ini)** on the root folder. For running tests outside of the SeleniumBase repo with **nosetests**, you'll want a copy of **[setup.cfg](https://github.com/seleniumbase/SeleniumBase/blob/master/setup.cfg)** on the root folder. (Subfolders should include a blank ``__init__.py`` file.) These files specify default configuration details for tests. (For nosetest runs, you can also specify a .cfg file by using ``--config``. Example ``nosetests [MY_TEST.py] --config=[MY_CONFIG.cfg]``)
436
436
437
-
As a shortcut, you'll be able to run ``sbase mkdir [DIRECTORY]`` to create a new folder that already contains necessary files and some example tests that you can run.
437
+
🔵 As a shortcut, you'll be able to run ``sbase mkdir [DIRECTORY]`` to create a new folder that already contains necessary files and some example tests that you can run.
438
438
439
439
```bash
440
440
sbase mkdir ui_tests
@@ -465,29 +465,29 @@ You can run it from the ``examples`` folder like this:
465
465
pytest test_fail.py
466
466
```
467
467
468
-
You'll notice that a logs folder, "latest_logs", was created to hold information about the failing test, and screenshots. During test runs, past results get moved to the archived_logs folder if you have ARCHIVE_EXISTING_LOGS set to True in [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py), or if your run tests with ``--archive-logs``. If you choose not to archive existing logs, they will be deleted and replaced by the logs of the latest test run.
468
+
🔵 You'll notice that a logs folder, "latest_logs", was created to hold information about the failing test, and screenshots. During test runs, past results get moved to the archived_logs folder if you have ARCHIVE_EXISTING_LOGS set to True in [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py), or if your run tests with ``--archive-logs``. If you choose not to archive existing logs, they will be deleted and replaced by the logs of the latest test run.
469
469
470
470
--------
471
471
472
472
<h3><img src="https://seleniumbase.io/img/logo6.png" title="SeleniumBase" width="32" /> The SeleniumBase Dashboard:</h3>
473
473
474
-
The ``--dashboard`` option for pytest generates a SeleniumBase Dashboard located at ``dashboard.html``, which updates automatically as tests run and produce results. Example:
474
+
🔵 The ``--dashboard`` option for pytest generates a SeleniumBase Dashboard located at ``dashboard.html``, which updates automatically as tests run and produce results. Example:
Additionally, you can host your own SeleniumBase Dashboard Server on a port of your choice. Here's an example of that using Python 3's ``http.server``:
482
+
🔵 Additionally, you can host your own SeleniumBase Dashboard Server on a port of your choice. Here's an example of that using Python 3's ``http.server``:
483
483
484
484
```bash
485
485
python -m http.server 1948
486
486
```
487
487
488
-
Now you can navigate to ``http://localhost:1948/dashboard.html``in order to view the dashboard as a web app. This requires two different terminal windows: one for running the server, and another for running the tests, which should be run from the same directory. (Use ``CTRL-C`` to stop the http server.)
488
+
🔵 Now you can navigate to ``http://localhost:1948/dashboard.html``in order to view the dashboard as a web app. This requires two different terminal windows: one for running the server, and another for running the tests, which should be run from the same directory. (Use ``CTRL-C`` to stop the http server.)
489
489
490
-
Here's a full example of what the SeleniumBase Dashboard may look like:
490
+
🔵 Here's a full example of what the SeleniumBase Dashboard may look like:
When combining pytest html reports with SeleniumBase Dashboard usage, the pie chart from the Dashboard will get added to the html report. Additionally, if you set the html report URL to be the same as the Dashboard URL when also using the dashboard, (example: ``--dashboard --html=dashboard.html``), then the Dashboard will become an advanced html report when all the tests complete.
513
+
🔵 When combining pytest html reports with SeleniumBase Dashboard usage, the pie chart from the Dashboard will get added to the html report. Additionally, if you set the html report URL to be the same as the Dashboard URL when also using the dashboard, (example: ``--dashboard --html=dashboard.html``), then the Dashboard will become an advanced html report when all the tests complete.
<h3><img src="https://seleniumbase.io/img/logo6.png" title="SeleniumBase" width="32" /> Changing the User-Agent:</h3>
574
574
575
-
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.
575
+
🔵 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.io/img/logo6.png" title="SeleniumBase" width="32" /> Building Guided Tours for Websites:</h3>
583
583
584
-
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.
584
+
🔵 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.
<h3><img src="https://seleniumbase.io/img/logo6.png" title="SeleniumBase" width="32" /> Detailed Method Specifications and Examples:</h3>
610
610
611
-
<h4>Navigating to a web page (and related commands)</h4>
611
+
🔵 Navigating to a web page: (and related commands)
612
612
613
613
```python
614
614
self.open("https://xkcd.com/378/") # This method opens the specified page.
@@ -624,7 +624,7 @@ self.get_current_url() # This method returns the current page URL.
624
624
self.get_page_source() # This method returns the current page source.
625
625
```
626
626
627
-
<b>ProTip™:</b> You may need to use the get_page_source() method along with Python's find() command to parse through the source to find something that Selenium wouldn't be able to. (You may want to brush up on your Python programming skills for that.)
627
+
<b>ProTip™:</b> You may need to use the <code>self.get_page_source()</code> method along with Python's <code>find()</code>command to parse through the source to find something that Selenium wouldn't be able to. (You may want to brush up on your Python programming skills for that.)
**ProTip™:** In most web browsers, you can right-click on a page and select ``Inspect Element`` to see the CSS selector details that you'll need to create your own scripts.
645
645
646
-
<h4>Typing Text</h4>
646
+
🔵 Typing Text:
647
647
648
-
self.type(selector, text) # updates the text from the specified element with the specified value. An exception is raised if the element is missing or if the text field is not editable. Example:
648
+
<code>self.type(selector, text)</code># updates the text from the specified element with the specified value. An exception is raised if the element is missing or if the text field is not editable. Example:
649
649
650
650
```python
651
651
self.type("input#id_value", "2012")
652
652
```
653
-
You can also use self.add_text() or the WebDriver .send_keys() command, but those won't clear the text box first if there's already text inside.
653
+
654
+
You can also use <code>self.add_text()</code> or the WebDriver <code>.send_keys()</code> command, but those won't clear the text box first if there's already text inside.
654
655
If you want to typein special keys, that's easy too. Here's an example:
655
656
656
657
```python
657
658
from selenium.webdriver.common.keys import Keys
658
659
self.find_element("textarea").send_keys(Keys.SPACE + Keys.BACK_SPACE + '\n') # The backspace should cancel out the space, leaving you with the newline
659
660
```
660
661
661
-
<h4>Getting the text from an element on a page</h4>
662
+
🔵 Getting the text from an element on a page:
662
663
663
664
```python
664
665
text = self.get_text("header h2")
665
666
```
666
667
667
-
<h4>Getting the attribute value from an element on a page</h4>
668
+
🔵 Getting the attribute value from an element on a page:
(NOTE: The short versions of this are ``self.find_element(ELEMENT)`` and ``self.assert_element(ELEMENT)``. The find_element() version returns the element)
686
688
687
689
Since the line above returns the element, you can combine that with .click() as shown below:
@@ -702,23 +704,23 @@ You can also use ``*=`` to search for any partial value in a CSS selector as sho
702
704
self.click('a[name*="partial_name"]')
703
705
```
704
706
705
-
<h4>Asserting visibility of text inside an element on a page within some number of seconds:</h4>
707
+
🔵 Asserting visibility of text inside an element on a page within some number of seconds:
706
708
707
709
```python
708
710
self.assert_text("Make it so!", "div#trek div.picard div.quotes")
(NOTE: ``self.find_text(TEXT, ELEMENT)`` and ``self.wait_for_text(TEXT, ELEMENT)`` also do this. For backwords compatibility, older method names were kept, but the default timeout may be different.)
712
714
713
-
<h4>Asserting Anything</h4>
715
+
🔵 Asserting Anything:
714
716
715
717
```python
716
718
self.assert_true(myvar1 == something)
717
719
718
720
self.assert_equal(var1, var2)
719
721
```
720
722
721
-
<h4>Useful Conditional Statements (with creative examples in action)</h4>
723
+
🔵 Useful Conditional Statements: (with creative examples in action)
722
724
723
725
is_element_visible(selector) # is an element visible on a page
724
726
@@ -818,7 +820,7 @@ self.activate_jquery()
818
820
819
821
🔵 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`` on the command-line.
820
822
821
-
Here are some examples of using jQuery in your scripts:
823
+
🔵 Here are some examples of using jQuery in your scripts:
822
824
823
825
```python
824
826
self.execute_script('jQuery, window.scrollTo(0, 600)') # Scrolling the page
@@ -874,8 +876,8 @@ class MyTestClass(BaseCase):
874
876
self.process_deferred_asserts()
875
877
```
876
878
877
-
``deferred_assert_element()`` and ``deferred_assert_text()`` will save any exceptions that would be raised.
878
-
To flush out all the failed deferred asserts into a single exception, make sure to call ``self.process_deferred_asserts()`` at the end of your test method. If your test hits multiple pages, you can call ``self.process_deferred_asserts()`` before navigating to a new page so that the screenshot from your log files matches the URL where the deferred asserts were made.
879
+
<code>deferred_assert_element()</code> and <code>deferred_assert_text()</code> will save any exceptions that would be raised.
880
+
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.
0 commit comments