From c6d7dab27c5098f21f5f9a42d85ffbec55c1bccc Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Wed, 27 Sep 2023 01:03:41 -0400 Subject: [PATCH] Update the ReadMe --- README.md | 116 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 75 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index a806957c31a..5ce6f63dd05 100755 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ With raw Selenium, that requires more code:

💡 SeleniumBase gives you the option to generate a dashboard and reports for tests. It also saves screenshots from failing tests to the ./latest_logs/ folder. Raw Selenium does not have these options out-of-the-box.

-

💡 SeleniumBase includes desktop GUI apps for running tests, such as SeleniumBase Commander for pytest and SeleniumBase Behave GUI for behave.

+

💡 SeleniumBase includes desktop GUI apps for running tests, such as SeleniumBase Commander for pytest and SeleniumBase Behave GUI for behave.

💡 SeleniumBase has its own Recorder / Test Generator that can create tests from manual browser actions. SeleniumBase also includes other useful tools and console scripts for getting things done quickly. (See the documentation for more details!)

@@ -165,79 +165,113 @@ With raw Selenium, that requires more code:
-------- -
- ▶️ Learn about different ways of writing tests (click to expand) -
+

📚 Learn about different ways of writing tests:

-

📘📝 An example test with the BaseCase class. Runs with pytest or pynose. (Learn more)

+

📘📝 An example test using BaseCase class inheritance. Runs with pytest or pynose. (Learn more). (Use self.driver to access Selenium's raw driver.)

```python from seleniumbase import BaseCase BaseCase.main(__name__, __file__) -class TestMFALogin(BaseCase): - def test_mfa_login(self): - self.open("https://seleniumbase.io/realworld/login") +class TestSimpleLogin(BaseCase): + def test_simple_login(self): + self.open("seleniumbase.io/simple/login") self.type("#username", "demo_user") self.type("#password", "secret_pass") - self.enter_mfa_code("#totpcode", "GAXG2MTEOR3DMMDG") # 6-digit + self.click('a:contains("Sign in")') self.assert_exact_text("Welcome!", "h1") self.assert_element("img#image1") - self.click('a:contains("This Page")') - self.save_screenshot_to_logs() + self.highlight("#image1") + self.click_link("Sign out") + self.assert_text("signed out", "#top_message") ``` -

📗📝 An example test with the sb pytest fixture. Runs with pytest.

+

📗📝 An example test using the sb pytest fixture. Runs with pytest. (Use sb.driver to access Selenium's raw driver.)

```python -def test_mfa_login(sb): - sb.open("https://seleniumbase.io/realworld/login") +def test_sb_fixture_with_no_class(sb): + sb.open("seleniumbase.io/simple/login") sb.type("#username", "demo_user") sb.type("#password", "secret_pass") - sb.enter_mfa_code("#totpcode", "GAXG2MTEOR3DMMDG") # 6-digit + sb.click('a:contains("Sign in")') sb.assert_exact_text("Welcome!", "h1") sb.assert_element("img#image1") - sb.click('a:contains("This Page")') - sb.save_screenshot_to_logs() + sb.highlight("#image1") + sb.click_link("Sign out") + sb.assert_text("signed out", "#top_message") ``` -

📙📝 An example test with the SB Context Manager. Runs with pure python.

+

📙📝 An example test using the SB Context Manager. Runs with pure python. (Use sb.driver to access Selenium's raw driver.)

```python from seleniumbase import SB -with SB() as sb: # By default, browser="chrome" if not set. - sb.open("https://seleniumbase.io/realworld/login") +with SB() as sb: + sb.open("seleniumbase.io/simple/login") sb.type("#username", "demo_user") sb.type("#password", "secret_pass") - sb.enter_mfa_code("#totpcode", "GAXG2MTEOR3DMMDG") # 6-digit - sb.assert_text("Welcome!", "h1") - sb.highlight("img#image1") # A fancier assert_element() call - sb.click('a:contains("This Page")') # Use :contains() on any tag - sb.click_link("Sign out") # Link must be "a" tag. Not "button". - sb.assert_element('a:contains("Sign in")') - sb.assert_exact_text("You have been signed out!", "#top_message") + sb.click('a:contains("Sign in")') + sb.assert_exact_text("Welcome!", "h1") + sb.assert_element("img#image1") + sb.highlight("#image1") + sb.click_link("Sign out") + sb.assert_text("signed out", "#top_message") +``` + +

📔📝 An example test using the DriverContext Manager. Runs with pure python. (The driver is an improved version of Selenium's raw driver, with more methods.)

+ +```python +from seleniumbase import DriverContext + +with DriverContext() as driver: + driver.open("seleniumbase.io/simple/login") + driver.type("#username", "demo_user") + driver.type("#password", "secret_pass") + driver.click('a:contains("Sign in")') + driver.assert_exact_text("Welcome!", "h1") + driver.assert_element("img#image1") + driver.highlight("#image1") + driver.click_link("Sign out") + driver.assert_text("signed out", "#top_message") ``` -

📕📝 An example test with behave-BDD Gherkin structure. Runs with behave. (Learn more)

+

📔📝 An example test using the Driver Manager. Runs with pure python. (The driver is an improved version of Selenium's raw driver, with more methods.)

+ +```python +from seleniumbase import Driver + +driver = Driver() +try: + driver.open("seleniumbase.io/simple/login") + driver.type("#username", "demo_user") + driver.type("#password", "secret_pass") + driver.click('a:contains("Sign in")') + driver.assert_exact_text("Welcome!", "h1") + driver.assert_element("img#image1") + driver.highlight("#image1") + driver.click_link("Sign out") + driver.assert_text("signed out", "#top_message") +finally: + driver.quit() +``` + +

📕📝 An example test using behave-BDD Gherkin syntax. Runs with behave. (Learn more)

```gherkin -Feature: SeleniumBase scenarios for the RealWorld App +Feature: SeleniumBase scenarios for the Simple App - Scenario: Verify RealWorld App - Given Open "seleniumbase.io/realworld/login" - When Type "demo_user" into "#username" + Scenario: Verify the Simple App (Login / Logout) + Given Open "seleniumbase.io/simple/login" + And Type "demo_user" into "#username" And Type "secret_pass" into "#password" - And Do MFA "GAXG2MTEOR3DMMDG" into "#totpcode" - Then Assert exact text "Welcome!" in "h1" + And Click 'a:contains("Sign in")' + And Assert exact text "Welcome!" in "h1" And Assert element "img#image1" - And Click 'a:contains("This Page")' - And Save screenshot to logs + And Highlight "#image1" + And Click link "Sign out" + And Assert text "signed out" in "#top_message" ``` -
-
- -------- @@ -332,7 +366,7 @@ COMMANDS:
- ▶️ Here's output from a chromedriver download. (click to expand) + ▶️ Here's sample output from a chromedriver download. (click to expand) ```bash *** chromedriver to download = 116.0.5845.96 (Latest Stable) @@ -865,7 +899,7 @@ behave behave_bdd/features/ -D dashboard -D headless -You can also use ``--junit`` to get ``.xml`` reports for each Behave feature. Jenkins can use these files to display better reporting for your tests. +You can also use ``--junit`` to get ``.xml`` reports for each behave feature. Jenkins can use these files to display better reporting for your tests. ```bash behave behave_bdd/features/ --junit -D rs -D headless