Skip to content

Commit b0ba92f

Browse files
committed
Update the documentation
1 parent 6e9a093 commit b0ba92f

File tree

1 file changed

+39
-24
lines changed

1 file changed

+39
-24
lines changed

help_docs/syntax_formats.md

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -832,17 +832,16 @@ This format provides a pure Python way of using SeleniumBase without a test runn
832832
```python
833833
from seleniumbase import SB
834834

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

848847
(See <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/raw_sb.py">examples/raw_sb.py</a> for the test.)
@@ -881,11 +880,11 @@ with SB(test=True, rtf=True, demo=True) as sb:
881880
This pure Python format gives you a raw <code translate="no">webdriver</code> instance in a <code translate="no">with</code> block. The SeleniumBase Driver Manager will automatically make sure that your driver is compatible with your browser version. It gives you full access to customize driver options via method args or via the command-line. The driver will automatically call <code translate="no">quit()</code> after the code leaves the <code translate="no">with</code> block. Here are some examples:
882881

883882
```python
884-
"""Can run with "python". (pytest not needed)."""
883+
"""DriverContext() example. (Runs with "python")."""
885884
from seleniumbase import DriverContext
886885

887886
with DriverContext() as driver:
888-
driver.open("seleniumbase.github.io/")
887+
driver.open("seleniumbase.io/")
889888
driver.highlight('img[alt="SeleniumBase"]', loops=6)
890889

891890
with DriverContext(browser="chrome", incognito=True) as driver:
@@ -896,7 +895,7 @@ with DriverContext(browser="chrome", incognito=True) as driver:
896895
driver.highlight("#output", loops=6)
897896

898897
with DriverContext() as driver:
899-
driver.open("seleniumbase.github.io/demo_page")
898+
driver.open("seleniumbase.io/demo_page")
900899
driver.highlight("h2")
901900
driver.type("#myTextInput", "Automation")
902901
driver.click("#checkBox1")
@@ -911,9 +910,19 @@ with DriverContext() as driver:
911910
Another way of running Selenium tests with pure ``python`` (as opposed to using ``pytest`` or ``pynose``) is by using this format, which bypasses [BaseCase](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/fixtures/base_case.py) methods while still giving you a flexible driver with a manager. SeleniumBase includes helper files such as [page_actions.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/fixtures/page_actions.py), which may help you get around some of the limitations of bypassing ``BaseCase``. Here's an example:
912911

913912
```python
914-
"""Driver() test. Runs with "python". (pytest not needed)."""
913+
"""Driver() example. (Runs with "python")."""
915914
from seleniumbase import Driver
916915

916+
driver = Driver()
917+
try:
918+
driver.open("seleniumbase.io/demo_page")
919+
driver.highlight("h2")
920+
driver.type("#myTextInput", "Automation")
921+
driver.click("#checkBox1")
922+
driver.highlight("img", loops=6)
923+
finally:
924+
driver.quit()
925+
917926
driver = Driver(browser="chrome", headless=False)
918927
try:
919928
driver.open("seleniumbase.io/apps/calculator")
@@ -923,19 +932,9 @@ try:
923932
driver.highlight("#output", loops=6)
924933
finally:
925934
driver.quit()
926-
927-
driver = Driver()
928-
try:
929-
driver.open("seleniumbase.github.io/demo_page")
930-
driver.highlight("h2")
931-
driver.type("#myTextInput", "Automation")
932-
driver.click("#checkBox1")
933-
driver.highlight("img", loops=6)
934-
finally:
935-
driver.quit()
936935
```
937936

938-
(From <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/raw_browser_launcher.py">examples/raw_browser_launcher.py</a>)
937+
(From <a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/raw_driver_manager.py">examples/raw_driver_manager.py</a>)
939938

940939
Here's how the [selenium-wire](https://github.com/wkeeling/selenium-wire) integration may look when using the ``Driver()`` format:
941940

@@ -951,6 +950,22 @@ finally:
951950
driver.quit()
952951
```
953952

953+
Here's another `selenium-wire` example with the `Driver()` format:
954+
955+
```python
956+
from seleniumbase import Driver
957+
958+
def intercept_response(request, response):
959+
print(request.headers)
960+
961+
driver = Driver(wire=True)
962+
try:
963+
driver.response_interceptor = intercept_response
964+
driver.get("https://wikipedia.org")
965+
finally:
966+
driver.quit()
967+
```
968+
954969
Here's an example of basic login with the ``Driver()`` format:
955970

956971
```python

0 commit comments

Comments
 (0)