Skip to content

Commit c567b5a

Browse files
committed
Update the documentation
1 parent 5d40cf2 commit c567b5a

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,19 @@ pytest test_demo_site.py --chrome
5757
<summary> ▶️ How is SeleniumBase different from raw Selenium? (<b><u>click to expand</u></b>)</summary>
5858
<div>
5959

60-
<p>💡 SeleniumBase is a Python test framework for the <a href="https://www.w3.org/TR/webdriver2/#endpoints" target="_blank">Selenium/WebDriver</a> browser automation library. This framework incorporates test-runners such as <code>pytest</code>, <code>nosetests</code>, and <code>behave</code> to provide organized structure, test discovery, test execution, test state (<i>eg. passed, failed, or skipped</i>), and command-line options for changing default settings (<i>such as which browser to use</i>). With raw Selenium, you would need to set up your own options-parser for configuring tests from the command-line.</p>
60+
<p>💡 SeleniumBase is a Python test framework for the <a href="https://www.w3.org/TR/webdriver2/#endpoints" target="_blank">Selenium/WebDriver</a> browser automation library. This framework incorporates test-runners such as <code>pytest</code>, <code>nosetests</code>, and <code>behave</code> to provide organized structure, test discovery, test execution, test state (<i>eg. passed, failed, or skipped</i>), and command-line options for changing default settings (<i>such as choosing the browser to use</i>). With raw Selenium, you would need to set up your own options-parser for configuring tests from the command-line.</p>
6161

6262
<p>💡 With raw Selenium, you have to manually download drivers (<i>eg. chromedriver</i>) before running tests. With SeleniumBase's driver manager, that's done automatically for you if the required driver isn't already on your PATH. There are also console scripts available for more control (eg. <code>sbase install chromedriver latest</code> to download the latest version of chromedriver to a local SeleniumBase directory).</p>
6363

64-
<p>💡 With raw Selenium, commands that use selectors need to specify the type of selector (eg. <code>"css selector", "button#myButton"</code>). With SeleniumBase, there's auto-detection between CSS Selectors and XPath, so you don't need to specify the type of selector in your commands (<i>but optionally you could</i>).</p>
64+
<p>💡 With raw Selenium, commands that use selectors need to specify the type of selector (eg. <code>"css selector", "button#myButton"</code>). With SeleniumBase, there's auto-detection between CSS Selectors and XPath, which means you don't need to specify the type of selector in your commands (<i>but optionally you could</i>).</p>
6565

6666
<p>💡 SeleniumBase methods often perform multiple actions in a single method call. For example, <code>self.type(selector,text)</code> does the following:<br />1. Waits for the element to be visible.<br />2. Waits for the element to be interactive.<br />3. Clears the text field.<br />4. Types in the new text.<br />5. Presses Enter/Submit if the text ends in "\n".<br />With raw Selenium, those actions require multiple method calls.</p>
6767

6868
<p>💡 SeleniumBase uses default timeout values when not set, which means that methods automatically wait for elements to appear (<i>up to the timeout limit</i>) before failing:<br />✅<code>self.click("button")</code><br />With raw Selenium, methods would fail instantly (<i>by default</i>) if an element needed more time to load:<br />❌<code>self.driver.find_element(by="css selector", value="button").click()</code><br />(Reliable code is better than unreliable code.)</p>
6969

70-
<p>💡 SeleniumBase lets you change the explicit timeout values of methods:<br />✅<code>self.click("button",timeout=12)</code><br />With raw Selenium, that requires more code:<br />❌<code>WebDriverWait(driver,12).until(EC.element_to_be_clickable("css selector", "button")).click()</code><br />(Simple code is better than complex code.)</p>
70+
<p>💡 SeleniumBase lets you change the explicit timeout values of methods:<br />✅<code>self.click("button",timeout=10)</code><br />With raw Selenium, that requires more code:<br />❌<code>WebDriverWait(driver,10).until(EC.element_to_be_clickable("css selector", "button")).click()</code><br />(Simple code is better than complex code.)</p>
71+
72+
<p>💡 SeleniumBase gives you clean error output when a test fails. With raw Selenium, error messages can get very messy.</p>
7173

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

@@ -468,6 +470,7 @@ The code above will leave your browser window open in case there's a failure. (i
468470
--recorder # (Enables the Recorder for turning browser actions into code.)
469471
--rec-behave # (Same as Recorder Mode, but also generates behave-gherkin.)
470472
--rec-sleep # (If the Recorder is enabled, also records self.sleep calls.)
473+
--rec-print # (If the Recorder is enabled, prints output after tests end.)
471474
--disable-csp # (Disable the Content Security Policy of websites.)
472475
--disable-ws # (Disable Web Security on Chromium-based browsers.)
473476
--enable-ws # (Enable Web Security on Chromium-based browsers.)

help_docs/customizing_test_runs.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ pytest my_first_test.py --settings-file=custom_settings.py
150150
--recorder # (Enables the Recorder for turning browser actions into code.)
151151
--rec-behave # (Same as Recorder Mode, but also generates behave-gherkin.)
152152
--rec-sleep # (If the Recorder is enabled, also records self.sleep calls.)
153+
--rec-print # (If the Recorder is enabled, prints output after tests end.)
153154
--disable-csp # (Disable the Content Security Policy of websites.)
154155
--disable-ws # (Disable Web Security on Chromium-based browsers.)
155156
--enable-ws # (Enable Web Security on Chromium-based browsers.)
@@ -469,4 +470,6 @@ pytest test_swag_labs.py --mobile --metrics="411,731,3"
469470
pytest test_swag_labs.py --mobile --agent="Mozilla/5.0 (Linux; Android 9; Pixel 3 XL)"
470471
```
471472

472-
[<img src="https://seleniumbase.io/cdn/img/fancy_logo_14.png" title="SeleniumBase" width="290">](https://github.com/seleniumbase/SeleniumBase/blob/master/README.md)
473+
--------
474+
475+
[<img src="https://seleniumbase.io/cdn/img/fancy_logo_14.png" title="SeleniumBase" width="290">](https://github.com/seleniumbase/SeleniumBase)

help_docs/syntax_formats.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class LoginPage:
115115
class MyTests(BaseCase):
116116
def test_swag_labs_login(self):
117117
LoginPage().login_to_swag_labs(self, "standard_user")
118-
self.assert_element("#inventory_container")
118+
self.assert_element("div.inventory_list")
119119
self.assert_element('div:contains("Sauce Labs Backpack")')
120120
```
121121

@@ -136,7 +136,7 @@ class LoginPage:
136136
class MyTests:
137137
def test_swag_labs_login(self, sb):
138138
LoginPage().login_to_swag_labs(sb, "standard_user")
139-
sb.assert_element("#inventory_container")
139+
sb.assert_element("div.inventory_list")
140140
sb.assert_element('div:contains("Sauce Labs Backpack")')
141141
```
142142

@@ -190,8 +190,9 @@ class OverrideDriverTest(BaseCase):
190190
def get_new_driver(self, *args, **kwargs):
191191
"""This method overrides get_new_driver() from BaseCase."""
192192
options = webdriver.ChromeOptions()
193-
options.add_experimental_option("excludeSwitches", ["enable-automation"])
194-
options.add_experimental_option("useAutomationExtension", False)
193+
options.add_experimental_option(
194+
"excludeSwitches", ["enable-automation"]
195+
)
195196
if self.headless:
196197
options.add_argument("--headless")
197198
return webdriver.Chrome(options=options)
@@ -232,18 +233,15 @@ from seleniumbase import get_driver
232233
from seleniumbase import js_utils
233234
from seleniumbase import page_actions
234235

235-
success = False
236+
driver = get_driver("chrome", headless=False)
236237
try:
237-
driver = get_driver("chrome", headless=False)
238238
driver.get("https://seleniumbase.io/apps/calculator")
239239
page_actions.wait_for_element_visible(driver, "4", "id").click()
240240
page_actions.wait_for_element_visible(driver, "2", "id").click()
241241
page_actions.wait_for_text_visible(driver, "42", "output", "id")
242242
js_utils.highlight_with_js(driver, "#output", 6, "")
243-
success = True
244243
finally:
245244
driver.quit()
246-
assert success
247245
```
248246

249247
(From <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/raw_browser_launcher.py">examples/raw_browser_launcher.py</a>)

0 commit comments

Comments
 (0)