Skip to content

Commit 481adff

Browse files
committed
Update the docs
1 parent dc38cdd commit 481adff

File tree

4 files changed

+55
-51
lines changed

4 files changed

+55
-51
lines changed

README.md

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ The code above will leave your browser window open in case there's a failure. (i
411411
412412
(For more details, see the full list of command-line options **[here](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/pytest_plugin.py)**.)
413413
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.
415415
416416
```bash
417417
cd examples/
@@ -426,15 +426,15 @@ Here's the command-line option to add to tests: (See [examples/custom_settings.p
426426
``--settings_file=custom_settings.py``
427427
(Settings include default timeout values, a two-factor auth key, DB credentials, S3 credentials, and other important settings used by tests.)
428428
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"``.
430430
Inside your tests, you can use ``self.data`` to access that.
431431
432432
433433
<h3><img src="https://seleniumbase.io/img/logo6.png" title="SeleniumBase" width="32" /> Test Directory Customization:</h3>
434434
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]``)
436436
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.
438438
439439
```bash
440440
sbase mkdir ui_tests
@@ -465,29 +465,29 @@ You can run it from the ``examples`` folder like this:
465465
pytest test_fail.py
466466
```
467467
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.
469469
470470
--------
471471
472472
<h3><img src="https://seleniumbase.io/img/logo6.png" title="SeleniumBase" width="32" /> The SeleniumBase Dashboard:</h3>
473473
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:
475475
476476
```bash
477477
pytest --dashboard --rs --headless
478478
```
479479
480480
<img src="https://seleniumbase.io/cdn/img/dashboard_1.png" alt="The SeleniumBase Dashboard" title="The SeleniumBase Dashboard" width="360" />
481481
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``:
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``:
483483
484484
```bash
485485
python -m http.server 1948
486486
```
487487
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.)
489489
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:
491491
492492
```bash
493493
pytest test_suite.py --dashboard --rs --headless
@@ -502,17 +502,17 @@ pytest test_suite.py --dashboard --rs --headless
502502
503503
<h4><b>Pytest Reports:</b></h4>
504504
505-
Using ``--html=report.html`` gives you a fancy report of the name specified after your test suite completes.
505+
🔵 Using ``--html=report.html`` gives you a fancy report of the name specified after your test suite completes.
506506
507507
```bash
508508
pytest test_suite.py --html=report.html
509509
```
510510
511511
<img src="https://seleniumbase.io/cdn/img/html_report.png" alt="Example Pytest Report" title="Example Pytest Report" width="520" />
512512
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.
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.
514514
515-
Here's an example of an upgraded html report:
515+
🔵 Here's an example of an upgraded html report:
516516
517517
```bash
518518
pytest test_suite.py --dashboard --html=report.html
@@ -572,7 +572,7 @@ pytest proxy_test.py --proxy=proxy1
572572
573573
<h3><img src="https://seleniumbase.io/img/logo6.png" title="SeleniumBase" width="32" /> Changing the User-Agent:</h3>
574574
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.
576576
577577
```bash
578578
pytest user_agent_test.py --agent="Mozilla/5.0 (Nintendo 3DS; U; ; en) Version/1.7412.EU"
@@ -581,7 +581,7 @@ pytest user_agent_test.py --agent="Mozilla/5.0 (Nintendo 3DS; U; ; en) Version/1
581581
582582
<h3><img src="https://seleniumbase.io/img/logo6.png" title="SeleniumBase" width="32" /> Building Guided Tours for Websites:</h3>
583583
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.
585585
586586
587587
<a id="utilizing_advanced_features"></a>
@@ -608,7 +608,7 @@ pytest [YOUR_TEST_FILE.py] --with-db-reporting --with-s3-logging
608608
<a id="detailed_method_specifications"></a>
609609
<h3><img src="https://seleniumbase.io/img/logo6.png" title="SeleniumBase" width="32" /> Detailed Method Specifications and Examples:</h3>
610610
611-
<h4>Navigating to a web page (and related commands)</h4>
611+
🔵 Navigating to a web page: (and related commands)
612612
613613
```python
614614
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.
624624
self.get_page_source() # This method returns the current page source.
625625
```
626626
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.)
628628
629629
```python
630630
source = self.get_page_source()
@@ -633,7 +633,7 @@ head_close_tag = source.find('</head>', head_open_tag)
633633
everything_inside_head = source[head_open_tag+len('<head>'):head_close_tag]
634634
```
635635
636-
<h4>Clicking</h4>
636+
🔵 Clicking:
637637
638638
To click an element on the page:
639639
@@ -643,45 +643,47 @@ self.click("div#my_id")
643643
644644
**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.
645645
646-
<h4>Typing Text</h4>
646+
🔵 Typing Text:
647647
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:
649649
650650
```python
651651
self.type("input#id_value", "2012")
652652
```
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.
654655
If you want to type in special keys, that's easy too. Here's an example:
655656
656657
```python
657658
from selenium.webdriver.common.keys import Keys
658659
self.find_element("textarea").send_keys(Keys.SPACE + Keys.BACK_SPACE + '\n') # The backspace should cancel out the space, leaving you with the newline
659660
```
660661
661-
<h4>Getting the text from an element on a page</h4>
662+
🔵 Getting the text from an element on a page:
662663
663664
```python
664665
text = self.get_text("header h2")
665666
```
666667
667-
<h4>Getting the attribute value from an element on a page</h4>
668+
🔵 Getting the attribute value from an element on a page:
668669
669670
```python
670671
attribute = self.get_attribute("#comic img", "title")
671672
```
672673
673-
<h4>Asserting existance of an element on a page within some number of seconds:</h4>
674+
🔵 Asserting existance of an element on a page within some number of seconds:
674675
675676
```python
676677
self.wait_for_element_present("div.my_class", timeout=10)
677678
```
678679
(NOTE: You can also use: ``self.assert_element_present(ELEMENT)``)
679680
680-
<h4>Asserting visibility of an element on a page within some number of seconds:</h4>
681+
🔵 Asserting visibility of an element on a page within some number of seconds:
681682
682683
```python
683684
self.wait_for_element_visible("a.my_class", timeout=5)
684685
```
686+
685687
(NOTE: The short versions of this are ``self.find_element(ELEMENT)`` and ``self.assert_element(ELEMENT)``. The find_element() version returns the element)
686688
687689
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
702704
self.click('a[name*="partial_name"]')
703705
```
704706
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:
706708
707709
```python
708710
self.assert_text("Make it so!", "div#trek div.picard div.quotes")
709711
self.assert_text("Tea. Earl Grey. Hot.", "div#trek div.picard div.quotes", timeout=3)
710712
```
711713
(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.)
712714
713-
<h4>Asserting Anything</h4>
715+
🔵 Asserting Anything:
714716
715717
```python
716718
self.assert_true(myvar1 == something)
717719
718720
self.assert_equal(var1, var2)
719721
```
720722
721-
<h4>Useful Conditional Statements (with creative examples in action)</h4>
723+
🔵 Useful Conditional Statements: (with creative examples in action)
722724
723725
is_element_visible(selector) # is an element visible on a page
724726
@@ -818,7 +820,7 @@ self.activate_jquery()
818820
819821
🔵 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.
820822
821-
Here are some examples of using jQuery in your scripts:
823+
🔵 Here are some examples of using jQuery in your scripts:
822824
823825
```python
824826
self.execute_script('jQuery, window.scrollTo(0, 600)') # Scrolling the page
@@ -874,8 +876,8 @@ class MyTestClass(BaseCase):
874876
self.process_deferred_asserts()
875877
```
876878
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.
879881
880882
🔵 Accessing Raw WebDriver
881883

0 commit comments

Comments
 (0)