From a719eebc711c82da421c332326df73c9af87fa8e Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 18 Dec 2020 01:25:31 -0500 Subject: [PATCH] Update examples --- examples/ReadMe.md | 4 +-- examples/chart_maker/ReadMe.md | 2 +- examples/chart_maker/test_area_chart.py | 2 +- examples/chart_maker/test_line_chart.py | 2 +- examples/chart_maker/test_multi_series.py | 2 +- examples/decryption_test.py | 2 +- examples/example_logs/ReadMe.md | 42 +++++++++++++++++++---- examples/github_test.py | 7 ++-- examples/presenter/ReadMe.md | 2 +- examples/presenter/py_virtual_envs.py | 10 +++--- examples/rate_limiting_test.py | 10 +++--- examples/test_apple_site.py | 4 +-- examples/tour_examples/ReadMe.md | 2 +- 13 files changed, 60 insertions(+), 31 deletions(-) diff --git a/examples/ReadMe.md b/examples/ReadMe.md index 3289b709..138fa5ae 100755 --- a/examples/ReadMe.md +++ b/examples/ReadMe.md @@ -1,6 +1,6 @@ -

Running Example Tests:

+

Running Example Tests:

SeleniumBase

@@ -12,7 +12,7 @@ (NOTE: Some example tests fail on purpose to demonstrate [logging features](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/example_logs/ReadMe.md).) -

Example run commands to help you get started:

+

Example run commands to help you get started:

Run an example test in Chrome: (Default: ``--browser=chrome``) diff --git a/examples/chart_maker/ReadMe.md b/examples/chart_maker/ReadMe.md index 3f293b7c..956961d6 100755 --- a/examples/chart_maker/ReadMe.md +++ b/examples/chart_maker/ReadMe.md @@ -1,4 +1,4 @@ -

SeleniumBase

+

SeleniumBase

📊 ChartMaker 📈

diff --git a/examples/chart_maker/test_area_chart.py b/examples/chart_maker/test_area_chart.py index 61e422fb..1be1cada 100755 --- a/examples/chart_maker/test_area_chart.py +++ b/examples/chart_maker/test_area_chart.py @@ -3,7 +3,7 @@ from seleniumbase import BaseCase class MyChartMakerClass(BaseCase): - def test_chart_maker(self): + def test_area_chart(self): self.create_presentation(theme="moon") self.create_area_chart( title="Time Outside", subtitle="Last Week", unit="Minutes") diff --git a/examples/chart_maker/test_line_chart.py b/examples/chart_maker/test_line_chart.py index 7f062e13..1a8aa310 100755 --- a/examples/chart_maker/test_line_chart.py +++ b/examples/chart_maker/test_line_chart.py @@ -3,7 +3,7 @@ from seleniumbase import BaseCase class MyChartMakerClass(BaseCase): - def test_chart_maker(self): + def test_line_chart(self): self.create_presentation() self.create_line_chart( title="Time Outside", subtitle="Last Week", unit="Minutes") diff --git a/examples/chart_maker/test_multi_series.py b/examples/chart_maker/test_multi_series.py index 859f895a..4e284cd9 100755 --- a/examples/chart_maker/test_multi_series.py +++ b/examples/chart_maker/test_multi_series.py @@ -3,7 +3,7 @@ from seleniumbase import BaseCase class MyChartMakerClass(BaseCase): - def test_multi_series_chart(self): + def test_multi_series(self): self.create_presentation(theme="league") self.create_line_chart( diff --git a/examples/decryption_test.py b/examples/decryption_test.py index 09fcc9e6..b06fe87f 100755 --- a/examples/decryption_test.py +++ b/examples/decryption_test.py @@ -9,7 +9,7 @@ from seleniumbase import encryption class MyTestClass(BaseCase): - def test_rate_limited_printing(self): + def test_decrypt_password(self): self.open("https://www.saucedemo.com/") self.type("#user-name", "standard_user") diff --git a/examples/example_logs/ReadMe.md b/examples/example_logs/ReadMe.md index 893d0f6d..cbfd2810 100755 --- a/examples/example_logs/ReadMe.md +++ b/examples/example_logs/ReadMe.md @@ -1,8 +1,8 @@ - + -### Logging, Screenshots, and Reports: +

Logging, Dashboards, and Reports:

-Log files in [SeleniumBase/examples/example_logs](https://github.com/seleniumbase/SeleniumBase/tree/master/examples/example_logs) were generated when [test_fail.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_fail.py) ran and failed. During test failures, logs and screenshots get saved to the ``latest_logs/`` folder. If ``--archive-logs`` is set, test logs will get archived to the ``archived_logs/`` folder. +Log files in [SeleniumBase/examples/example_logs](https://github.com/seleniumbase/SeleniumBase/tree/master/examples/example_logs) were generated when [test_fail.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_fail.py) ran and failed. During test failures, logs and screenshots from the latest run will get saved to the ``latest_logs/`` folder. If ``--archive-logs`` is set, test logs will get archived to the ``archived_logs/`` folder (otherwise they will be cleaned out when the next test run begins). ```bash pytest test_fail.py --browser=chrome @@ -17,28 +17,56 @@ nosetests test_fail.py --browser=firefox
  • screenshot.png
  • +In addition to log files, you can also generate a dashboard and test reports. + -------- -In addition to logging, you can also generate test reports: +

    The SeleniumBase Dashboard:

    -Reports are most useful when running large test suites. Pytest and Nosetest reports are handled differently. +The ``--dashboard`` option for pytest generates a SeleniumBase Dashboard located at ``dashboard.html``, which updates automatically as tests run and produce results. -### Pytest Reports: +The SeleniumBase Dashboard + +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``: + +```bash +python -m http.server 1948 +``` + +Now you can navigate to ``http://localhost:1948/dashboard.html`` in order to view the served dashboard from a web browser. (Be sure to run that command in the same directory where you ran your tests.) + +Here's a full example of what the SeleniumBase Dashboard may look like: + +```bash +pytest test_suite.py --dashboard --rs --headless +``` + +The SeleniumBase Dashboard + +-------- + +

    Pytest Reports:

    Using ``--html=report.html`` gives you a fancy report of the name specified after your test suite completes. ```bash pytest test_suite.py --html=report.html ``` + Example Pytest Report -### Nosetest Reports: +If viewing pytest html reports in [Jenkins](https://www.jenkins.io/), you may need to [configure Jenkins settings](https://stackoverflow.com/a/46197356) for the html to render correctly. This is due to [Jenkins CSP changes](https://www.jenkins.io/doc/book/system-administration/security/configuring-content-security-policy/). + +-------- + +

    Nosetest Reports:

    The ``--report`` option gives you a fancy report after your test suite completes. ```bash nosetests test_suite.py --report --browser=chrome ``` + Example Nosetest Report (NOTE: You can add ``--show-report`` to immediately display Nosetest reports after the test suite completes. Only use ``--show-report`` when running tests locally because it pauses the test run.) diff --git a/examples/github_test.py b/examples/github_test.py index 91e759d4..5be20751 100755 --- a/examples/github_test.py +++ b/examples/github_test.py @@ -14,11 +14,10 @@ class GitHubTests(BaseCase): if self.headless and ( self.browser == "chrome" or self.browser == "edge"): self.get_new_driver( - agent="""Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) """ + agent="""Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) """ """AppleWebKit/537.36 (KHTML, like Gecko) """ - """Chrome/75.0.3770.100 Safari/537.36""") - self.open("https://github.com/") - self.type("input.header-search-input", "SeleniumBase\n") + """Chrome/86.0.4240.198 Safari/537.36""") + self.open("https://github.com/search?q=SeleniumBase") self.slow_click('a[href="/seleniumbase/SeleniumBase"]') self.click_if_visible('[data-action="click:signup-prompt#dismiss"]') self.assert_element("div.repository-content") diff --git a/examples/presenter/ReadMe.md b/examples/presenter/ReadMe.md index 19e36c28..5ef11247 100755 --- a/examples/presenter/ReadMe.md +++ b/examples/presenter/ReadMe.md @@ -1,4 +1,4 @@ -

    SeleniumBase

    +

    SeleniumBase

    📰 Presenter 📑

    diff --git a/examples/presenter/py_virtual_envs.py b/examples/presenter/py_virtual_envs.py index 838f79d7..b6ebcf21 100755 --- a/examples/presenter/py_virtual_envs.py +++ b/examples/presenter/py_virtual_envs.py @@ -110,9 +110,9 @@ class PythonVirtualEnvPresentation(BaseCase): code=( '# Create a virtual environment:\n' 'mkvirtualenv ENV_NAME\n\n' - '# Leave your virtual environment:\n' + '# Exit your virtual environment:\n' 'deactivate\n\n' - '# Return to a virtual environment:\n' + '# Re-enter a virtual environment:\n' 'workon ENV_NAME\n\n' '# List all virtual environments:\n' 'workon\n\n' @@ -158,11 +158,11 @@ class PythonVirtualEnvPresentation(BaseCase): '

    Where to find me:

    ' '') self.begin_presentation( filename="py_virtual_envs.html", show_notes=False, interval=0) diff --git a/examples/rate_limiting_test.py b/examples/rate_limiting_test.py index 07e4cec2..2dbe3b44 100755 --- a/examples/rate_limiting_test.py +++ b/examples/rate_limiting_test.py @@ -3,17 +3,19 @@ This test demonstrates the use of the "rate_limited" decorator. You can use this decorator on any method to rate-limit it. """ -import unittest +from seleniumbase import BaseCase from seleniumbase import decorators -class MyTestClass(unittest.TestCase): +class MyTestClass(BaseCase): - @decorators.rate_limited(3.5) # The arg is max calls per second + @decorators.rate_limited(4.2) # The arg is max calls per second def print_item(self, item): print(item) def test_rate_limited_printing(self): - print("\nRunning rate-limited print test:") + message = "Running rate-limited print() on the command line" + self.open("data:text/html,

    %s

    " % message) + print("\n%s:" % message) for item in range(1, 11): self.print_item(item) diff --git a/examples/test_apple_site.py b/examples/test_apple_site.py index 1f245f41..9c9678ec 100755 --- a/examples/test_apple_site.py +++ b/examples/test_apple_site.py @@ -11,9 +11,9 @@ class AppleTestClass(BaseCase): if self.headless and ( self.browser == "chrome" or self.browser == "edge"): self.get_new_driver( - agent="""Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) """ + agent="""Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) """ """AppleWebKit/537.36 (KHTML, like Gecko) """ - """Chrome/75.0.3770.100 Safari/537.36""") + """Chrome/86.0.4240.198 Safari/537.36""") self.open("https://developer.apple.com/search/") title = "Testing with WebDriver in Safari" self.type('[placeholder*="developer.apple.com"]', title + "\n") diff --git a/examples/tour_examples/ReadMe.md b/examples/tour_examples/ReadMe.md index d72a6545..af7fe1be 100755 --- a/examples/tour_examples/ReadMe.md +++ b/examples/tour_examples/ReadMe.md @@ -1,4 +1,4 @@ -

    SeleniumBase

    +

    SeleniumBase

    ## Website Tours