Skip to content

Commit 47cb6e4

Browse files
authored
Merge pull request #2221 from seleniumbase/update-logging-webrtc-and-link-checking
Update logging options, WebRTC preferences, and link-checking methods
2 parents 39cf213 + 516c86b commit 47cb6e4

25 files changed

+204
-51
lines changed

examples/boilerplates/samples/google_test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
class GoogleTests(BaseCase):
77
def test_google_dot_com(self):
88
self.open("https://google.com/ncr")
9-
self.sleep(0.4)
9+
self.assert_title_contains("Google")
10+
self.sleep(0.25)
1011
self.save_screenshot_to_logs() # ("./latest_logs" folder)
11-
self.sleep(0.2)
12+
self.sleep(0.15)
13+
self.hide_elements('iframe') # Hide "Sign in" pop-up
14+
self.sleep(0.15)
15+
self.save_screenshot_to_logs()
1216
self.type(HomePage.search_box, "github.com")
1317
self.assert_element(HomePage.search_button)
1418
self.assert_element(HomePage.feeling_lucky_button)

examples/boilerplates/samples/test_page_objects.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66
class GooglePage:
77
def go_to_google(self, sb):
88
sb.open("https://google.com/ncr")
9-
sb.sleep(0.1)
10-
sb.hide_elements('iframe') # Hide "Sign in" pop-up
11-
sb.sleep(0.2)
9+
10+
def assert_google_title(self, sb):
11+
sb.assert_title_contains("Google")
12+
13+
def hide_sign_in_pop_up(self, sb):
14+
sb.sleep(0.25)
15+
sb.hide_elements('iframe')
16+
sb.sleep(0.15)
1217

1318
def do_search(self, sb, search_term):
19+
sb.sleep(0.05)
1420
sb.click('[title="Search"]')
1521
sb.type('[title="Search"]', search_term + "\n")
1622

@@ -30,6 +36,8 @@ def test_page_objects(self):
3036
search_term = "SeleniumBase.io Docs"
3137
expected_text = "SeleniumBase"
3238
GooglePage().go_to_google(self)
39+
GooglePage().assert_google_title(self)
40+
GooglePage().hide_sign_in_pop_up(self)
3341
GooglePage().do_search(self, search_term)
3442
self.assert_text(expected_text, "#search")
3543
GooglePage().click_search_result(self, expected_text)

examples/capabilities/ReadMe.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<h3><img src="https://seleniumbase.github.io/img/green_logo.png" title="SeleniumBase" width="32" /> Using Desired Capabilities</h3>
44

5-
You can specify browser capabilities when running SeleniumBase tests on a remote Selenium Grid server such as <a href="https://www.browserstack.com/automate/capabilities" target="_blank">BrowserStack</a>, <a href="https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/" target="_blank">Sauce Labs</a>, or another.
5+
You can specify browser capabilities when running SeleniumBase tests on a remote Selenium Grid server such as <a href="https://www.browserstack.com/automate/capabilities" target="_blank">BrowserStack</a>, <a href="https://saucelabs.com/products/platform-configurator" target="_blank">Sauce Labs</a>, or another.
66

77
Sample run commands may look like this when run from the [SeleniumBase/examples/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples) folder: (The browser is now specified in the capabilities file.)
88

@@ -47,7 +47,7 @@ capabilities = {
4747

4848
<ul>
4949
<li><a href="https://www.browserstack.com/automate/capabilities" target="_blank">BrowserStack desired capabilities</a></li>
50-
<li><a href="https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/" target="_blank">Sauce Labs desired capabilities</a></li>
50+
<li><a href="https://saucelabs.com/products/platform-configurator" target="_blank">Sauce Labs desired capabilities</a></li>
5151
</ul>
5252

5353
<div><b>Parsing desired capabilities:</b></div>

examples/capabilities/sample_cap_file_SL.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Desired capabilities example file for Sauce Labs
2-
# Generate from https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/
2+
# Generate from https://saucelabs.com/products/platform-configurator
33
capabilities = {
44
"browserName": "chrome",
55
"browserVersion": "latest",

examples/raw_parameter_script.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
sb.no_sandbox = False
7272
sb.disable_js = False
7373
sb.disable_gpu = False
74+
sb.log_cdp_events = False
7475
sb._multithreaded = False
7576
sb._reuse_session = False
7677
sb._crumbs = False

examples/test_todomvc.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ def test_todomvc(self, framework):
1010
self.clear_local_storage()
1111
self.click('a[href="examples/%s"]' % framework)
1212
self.assert_element("section.todoapp")
13+
self.assert_text("todos", "header h1")
14+
self.wait_for_ready_state_complete()
15+
title = self.get_title()
16+
self.assert_in(framework, title.lower())
1317
new_todo_input = "input.new-todo"
1418
todo_count_span = "span.todo-count"
1519
self.type(new_todo_input, "Learn Python\n")

help_docs/customizing_test_runs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ pytest --settings-file=custom_settings.py
452452

453453
<h3><img src="https://seleniumbase.github.io/img/green_logo.png" title="SeleniumBase" width="32" /> Running tests on a remote Selenium Grid:</h3>
454454

455-
🌐 SeleniumBase lets you run tests on remote Selenium Grids such as [BrowserStack](https://www.browserstack.com/automate#)'s Selenium Grid, [Sauce Labs](https://saucelabs.com/products/open-source-frameworks/selenium)'s Selenium Grid, other Grids, and even your own Grid:
455+
🌐 SeleniumBase lets you run tests on remote Selenium Grids such as [BrowserStack](https://www.browserstack.com/automate#)'s Selenium Grid, [Sauce Labs](https://saucelabs.com/products/platform-configurator)'s Selenium Grid, other Grids, and even your own Grid:
456456

457457
🌐 For setting browser desired capabilities while running Selenium remotely, see the ReadMe located here: https://github.com/seleniumbase/SeleniumBase/tree/master/examples/capabilities
458458

help_docs/desired_capabilities.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## [<img src="https://seleniumbase.github.io/img/logo6.png" title="SeleniumBase" width="32">](https://github.com/seleniumbase/SeleniumBase/) Using Desired Capabilities
44

5-
You can specify browser capabilities when running SeleniumBase tests on a remote Selenium Grid server such as <a href="https://www.browserstack.com/automate/capabilities" target="_blank">BrowserStack</a> or <a href="https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/" target="_blank">Sauce Labs</a>.
5+
You can specify browser capabilities when running SeleniumBase tests on a remote Selenium Grid server such as <a href="https://www.browserstack.com/automate/capabilities" target="_blank">BrowserStack</a> or <a href="https://saucelabs.com/products/platform-configurator" target="_blank">Sauce Labs</a>.
66

77
Sample run commands may look like this when run from the [SeleniumBase/examples/](https://github.com/seleniumbase/SeleniumBase/tree/master/examples) folder: (The browser is now specified in the capabilities file.)
88

@@ -47,7 +47,7 @@ capabilities = {
4747

4848
<ul>
4949
<li><a href="https://www.browserstack.com/automate/capabilities" target="_blank">BrowserStack desired capabilities</a></li>
50-
<li><a href="https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/" target="_blank">Sauce Labs desired capabilities</a></li>
50+
<li><a href="https://saucelabs.com/products/platform-configurator" target="_blank">Sauce Labs desired capabilities</a></li>
5151
</ul>
5252

5353
<div><b>Parsing desired capabilities:</b></div>

help_docs/how_it_works.md

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
<a id="how_seleniumbase_works"></a>
66

7-
👁️🔎 At the core, SeleniumBase works by extending [pytest](https://docs.pytest.org/en/latest/) as a direct plugin. SeleniumBase automatically spins up web browsers for tests (using [Selenium WebDriver](https://www.selenium.dev/documentation/webdriver/)), and then gives those tests access to the SeleniumBase libraries through the [BaseCase class](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/fixtures/base_case.py). Tests are also given access to [SeleniumBase command-line options](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/customizing_test_runs.md) and [SeleniumBase methods](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/method_summary.md), which provide additional functionality.
7+
👁️🔎 The primary [SeleniumBase syntax format](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md) works by extending [pytest](https://docs.pytest.org/en/latest/) as a direct plugin. SeleniumBase automatically spins up web browsers for tests (using [Selenium WebDriver](https://www.selenium.dev/documentation/webdriver/)), and then gives those tests access to the SeleniumBase libraries through the [BaseCase class](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/fixtures/base_case.py). Tests are also given access to [SeleniumBase command-line options](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/customizing_test_runs.md) and [SeleniumBase methods](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/method_summary.md), which provide additional functionality.
88

99
👁️🔎 ``pytest`` uses a feature called test discovery to automatically find and run Python methods that start with ``test_`` when those methods are located in Python files that start with ``test_`` or end with ``_test.py``.
1010

11-
👁️🔎 The most common way of using **SeleniumBase** is by importing ``BaseCase``:
11+
👁️🔎 The primary [SeleniumBase syntax format](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md) starts by importing ``BaseCase``:
1212

1313
```python
1414
from seleniumbase import BaseCase
1515
```
1616

17-
👁️🔎 This line activates ``pytest`` when a file is called directly with ``python``:
17+
👁️🔎 This next line activates ``pytest`` when a file is called directly with ``python`` by accident:
1818

1919
```python
2020
BaseCase.main(__name__, __file__)
@@ -29,12 +29,16 @@ class MyTestClass(BaseCase):
2929
👁️🔎 Test methods inside ``BaseCase`` classes become SeleniumBase tests: (These tests automatically launch a web browser before starting, and quit the web browser after ending. Default settings can be changed via command-line options.)
3030

3131
```python
32+
class MyTestClass(BaseCase):
3233
def test_abc(self):
34+
# ...
3335
```
3436

35-
👁️🔎 SeleniumBase APIs can be called from tests via ``self``:
37+
👁️🔎 [SeleniumBase APIs](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/method_summary.md) can be called from tests via ``self``:
3638

3739
```python
40+
class MyTestClass(BaseCase):
41+
def test_abc(self):
3842
self.open("https://example.com")
3943
```
4044

@@ -44,22 +48,20 @@ class MyTestClass(BaseCase):
4448
from seleniumbase import BaseCase
4549
BaseCase.main(__name__, __file__)
4650

47-
class TestMFALogin(BaseCase):
48-
def test_mfa_login(self):
49-
self.open("https://seleniumbase.io/realworld/login")
51+
class TestSimpleLogin(BaseCase):
52+
def test_simple_login(self):
53+
self.open("https://seleniumbase.io/simple/login")
5054
self.type("#username", "demo_user")
5155
self.type("#password", "secret_pass")
52-
self.enter_mfa_code("#totpcode", "GAXG2MTEOR3DMMDG") # 6-digit
53-
self.assert_text("Welcome!", "h1")
54-
self.highlight("img#image1") # A fancier assert_element() call
55-
self.click('a:contains("This Page")') # Use :contains() on any tag
56-
self.save_screenshot_to_logs() # ("./latest_logs" folder for test)
57-
self.click_link("Sign out") # Link must be "a" tag. Not "button".
58-
self.assert_element('a:contains("Sign in")')
59-
self.assert_exact_text("You have been signed out!", "#top_message")
56+
self.click('a:contains("Sign in")')
57+
self.assert_exact_text("Welcome!", "h1")
58+
self.assert_element("img#image1")
59+
self.highlight("#image1")
60+
self.click_link("Sign out")
61+
self.assert_text("signed out", "#top_message")
6062
```
6163

62-
(See the example, [test_mfa_login.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_mfa_login.py), for reference.)
64+
(See the example, [test_simple_login.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_simple_login.py), for reference.)
6365

6466
👁️🔎 Here are some examples of running tests with ``pytest``:
6567

@@ -71,7 +73,29 @@ pytest -k agent
7173
pytest offline_examples/
7274
```
7375

74-
(See <a href="https://seleniumbase.io/help_docs/syntax_formats/">Syntax_Formats</a> for more ways of structuring <b>SeleniumBase</b> tests.)
76+
👁️🔎 Here's a [SeleniumBase syntax format](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md) that uses the raw `driver`. Unlike the format mentioned earlier, it can be run with `python` instead of `pytest`. The `driver` includes original `driver` methods and new ones added by SeleniumBase:
77+
78+
```python
79+
from seleniumbase import Driver
80+
81+
driver = Driver()
82+
try:
83+
driver.get("https://seleniumbase.io/simple/login")
84+
driver.type("#username", "demo_user")
85+
driver.type("#password", "secret_pass")
86+
driver.click('a:contains("Sign in")')
87+
driver.assert_exact_text("Welcome!", "h1")
88+
driver.assert_element("img#image1")
89+
driver.highlight("#image1")
90+
driver.click_link("Sign out")
91+
driver.assert_text("signed out", "#top_message")
92+
finally:
93+
driver.quit()
94+
```
95+
96+
(See the example, [raw_login_driver.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/raw_login_driver.py), for reference.)
97+
98+
👁️🔎 Note that regular SeleniumBase formats (ones that use `BaseCase`, the `SB` context manager, or the `sb` `pytest` fixture) have more methods than the improved `driver` format. The regular formats also have more features. Some features, (such as the [SeleniumBase dashboard](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/example_logs/ReadMe.md)), require a `pytest` format.
7599

76100
--------
77101

help_docs/method_summary.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ self.get_new_driver(
282282
undetectable=None,
283283
uc_cdp_events=None,
284284
uc_subprocess=None,
285+
log_cdp_events=None,
285286
no_sandbox=None,
286287
disable_gpu=None,
287288
headless2=None,

mkdocs_build/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ paginate==0.5.6
2020
pyquery==2.0.0
2121
readtime==3.0.0
2222
mkdocs==1.5.3
23-
mkdocs-material==9.4.6
23+
mkdocs-material==9.4.7
2424
mkdocs-exclude-search==0.6.5
2525
mkdocs-simple-hooks==0.1.5
2626
mkdocs-material-extensions==1.3

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ wheel>=0.41.2
66
attrs>=23.1.0
77
certifi>=2023.7.22
88
filelock>=3.12.2;python_version<"3.8"
9-
filelock>=3.12.4;python_version>="3.8"
9+
filelock>=3.13.0;python_version>="3.8"
1010
platformdirs>=3.11.0
1111
parse>=1.19.1
1212
parse-type>=0.6.2

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.20.7"
2+
__version__ = "4.20.8"

seleniumbase/behave/behave_sb.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
-D enable-sync (Enable "Chrome Sync".)
7676
-D uc | -D undetected (Use undetected-chromedriver to evade bot-detection)
7777
-D uc-cdp-events (Capture CDP events when running in "-D undetected" mode)
78+
-D log-cdp ("goog:loggingPrefs", {"performance": "ALL", "browser": "ALL"})
7879
-D remote-debug (Sync to Chrome Remote Debugger chrome://inspect/#devices)
7980
-D dashboard (Enable the SeleniumBase Dashboard. Saved at: dashboard.html)
8081
-D dash-title=STRING (Set the title shown for the generated dashboard.)
@@ -181,6 +182,7 @@ def get_configured_sb(context):
181182
sb.undetectable = False
182183
sb.uc_cdp_events = False
183184
sb.uc_subprocess = False
185+
sb.log_cdp_events = False
184186
sb.no_sandbox = False
185187
sb.disable_gpu = False
186188
sb._multithreaded = False
@@ -549,6 +551,10 @@ def get_configured_sb(context):
549551
sb.uc_subprocess = True
550552
sb.undetectable = True
551553
continue
554+
# Handle: -D log-cdp-events / log_cdp_events / log-cdp
555+
if low_key in ["log-cdp-events", "log_cdp_events", "log-cdp"]:
556+
sb.log_cdp_events = True
557+
continue
552558
# Handle: -D no-sandbox / no_sandbox
553559
if low_key in ["no-sandbox", "no_sandbox"]:
554560
sb.no_sandbox = True

seleniumbase/config/proxy_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
PROXY_LIST = {
2626
"example1": "37.19.220.129:8443", # (Example) - set your own proxy here
2727
"example2": "socks4://104.236.32.53:8915", # (Example)
28-
"example3": "socks5://142.44.212.57:30439", # (Example)
28+
"example3": "socks5://142.44.212.57:49006", # (Example)
2929
"proxy1": None,
3030
"proxy2": None,
3131
"proxy3": None,

0 commit comments

Comments
 (0)