Update the documentation

This commit is contained in:
Michael Mintz 2023-12-31 18:35:57 -05:00
parent c4771b17de
commit 0f9d65d3bd
4 changed files with 81 additions and 44 deletions

View File

@ -1,8 +1,8 @@
<!-- SeleniumBase Docs -->
<h3><img src="https://seleniumbase.github.io/img/green_logo.png" title="SeleniumBase" width="32" /> Using Desired Capabilities</h3>
## [<img src="https://seleniumbase.github.io/img/logo6.png" title="SeleniumBase" width="32">](https://github.com/seleniumbase/SeleniumBase/) Using Desired Capabilities
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.
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>).
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.)
@ -16,17 +16,33 @@ pytest test_demo_site.py --browser=remote --server=USERNAME:KEY@ondemand.us-east
(Parameters: ``--browser=remote``, ``--server=SERVER``, ``--port=PORT``, ``--protocol=PROTOCOL``, and ``--cap_file=CAP_FILE.py``)
Here's an example desired capabilities file for BrowserStack:
Here's an example desired capabilities file for BrowserStack using the newer SDK format in a `.yml` / `.yaml` file:
```yml
platforms:
- browserName: safari
osVersion: 17
deviceName: iPhone 15 Pro Max
buildIdentifier: ${BUILD_NUMBER}
parallelsPerPlatform: 1
projectName: My Project
browserstackLocal: true
debug: true
networkLogs: true
```
Here's an example desired capabilities file for BrowserStack using the legacy JSONWP format in a `.py` file:
```python
desired_cap = {
"os" : "Windows",
"os_version" : "11",
"browser" : "Chrome",
"browser_version" : "101.0",
"browserstack.local" : "false",
"browserstack.debug" : "true",
"browserstack.selenium_version" : "4.1.2",
"browser": "Chrome",
"os": "Windows",
"os_version": "11",
"browser_version": "latest",
"browserstack.console": "info",
"browserstack.debug": "true",
"browserstack.networkLogs": "true",
"browserstack.local": "true",
}
```
@ -41,12 +57,12 @@ capabilities = {
}
```
(Note that the browser is now being specified in the capabilities file, rather than with ``--browser=BROWSER`` when using a **remote** Selenium Grid. If using a **local** Selenium Grid, specify the browser, eg: ``--browser=chrome`` or ``--browser=firefox``.)
(Note that the browser is now being specified in the capabilities file, rather than with ``--BROWSER`` when using a **remote** Selenium Grid. If using a **local** Selenium Grid, specify the browser, eg: ``--firefox``.)
<div><b>You can generate specific desired capabilities using:</b></div>
<ul>
<li><a href="https://www.browserstack.com/automate/capabilities" target="_blank">BrowserStack desired capabilities</a></li>
<li><a href="https://www.browserstack.com/docs/automate/capabilities" target="_blank">BrowserStack desired capabilities</a></li>
<li><a href="https://saucelabs.com/products/platform-configurator" target="_blank">Sauce Labs desired capabilities</a></li>
</ul>
@ -65,7 +81,7 @@ caps['KEY'] = False
(Each pair must be on a separate line. You can interchange single and double quotes.)
You can also swap ``--browser=remote`` with an actual browser, eg ``--browser=chrome``, which will combine the default SeleniumBase desired capabilities with those that were specified in the capabilities file when using ``--cap_file=FILE.py``. Capabilities will override other parameters, so if you set the browser to one thing and the capabilities browser to another, SeleniumBase will use the capabilities browser as the browser.
You can also swap ``--browser=remote`` with an actual browser, eg ``--browser=chrome``, which will combine the default SeleniumBase desired capabilities with those that were specified in the capabilities file when using ``--cap_file=FILE.py``. Capabilities will override other parameters, so if you set the browser to one thing and the capabilities browser to another, SeleniumBase will use the capabilities browser.
You'll need default SeleniumBase capabilities for:
* Using a proxy server (not the same as a Selenium Grid server)
@ -74,8 +90,7 @@ You'll need default SeleniumBase capabilities for:
* Overriding a website's Content Security Policy on Chrome
* Other possible reasons
You can also set browser desired capabilities from a command line string:
Example:
You can also set browser desired capabilities from a command-line string. Eg:
```bash
pytest test_swag_labs.py --cap-string='{"browserName":"chrome","name":"test1"}' --server="127.0.0.1" --browser=remote
@ -83,7 +98,7 @@ pytest test_swag_labs.py --cap-string='{"browserName":"chrome","name":"test1"}'
(Enclose cap-string in single quotes. Enclose parameter keys in double quotes.)
If you pass ``"*"`` into the ``"name"`` field of ``--cap-string``, the name will become the test identifier. Example:
If you pass ``"*"`` into the ``"name"`` field of ``--cap-string``, the name will become the test identifier. Eg:
```bash
pytest my_first_test.py --cap-string='{"browserName":"chrome","name":"*"}' --server="127.0.0.1" --browser=chrome

View File

@ -114,6 +114,7 @@ pytest my_first_test.py --demo
```python
from seleniumbase import BaseCase
BaseCase.main(__name__, __file__)
class MyTestClass(BaseCase):
def test_swag_labs(self):
@ -121,20 +122,21 @@ class MyTestClass(BaseCase):
self.type("#user-name", "standard_user")
self.type("#password", "secret_sauce\n")
self.assert_element("div.inventory_list")
self.assert_text("PRODUCTS", "span.title")
self.assert_exact_text("Products", "span.title")
self.click('button[name*="backpack"]')
self.click("#shopping_cart_container a")
self.assert_text("YOUR CART", "span.title")
self.assert_exact_text("Your Cart", "span.title")
self.assert_text("Backpack", "div.cart_item")
self.click("button#checkout")
self.type("#first-name", "SeleniumBase")
self.type("#last-name", "Automation")
self.type("#postal-code", "77123")
self.click("input#continue")
self.assert_text("CHECKOUT: OVERVIEW")
self.assert_text("Checkout: Overview")
self.assert_text("Backpack", "div.cart_item")
self.assert_text("29.99", "div.inventory_item_price")
self.click("button#finish")
self.assert_exact_text("THANK YOU FOR YOUR ORDER", "h2")
self.assert_exact_text("Thank you for your order!", "h2")
self.assert_element('img[alt="Pony Express"]')
self.js_click("a#logout_sidebar_link")
self.assert_element("div#login_button_container")
@ -173,23 +175,28 @@ self.save_screenshot(FILE_NAME) # 保存当前页面的截图
```python
from seleniumbase.translate.chinese import 硒测试用例
硒测试用例.main(__name__, __file__)
class 我的测试类(硒测试用例):
def test_例子1(self):
self.开启("https://zh.wikipedia.org/wiki/")
self.断言标题("维基百科,自由的百科全书")
self.断言元素('a[title="首页"]')
self.断言元素('a[title="Wikipedia:关于"]')
self.断言元素('span:contains("创建账号")')
self.断言元素('span:contains("登录")')
self.断言文本("新闻动态", "span#新闻动态")
self.输入文本("#searchInput", "舞龍")
self.单击("#searchButton")
self.输入文本('input[name="search"]', "舞龍")
self.单击('button:contains("搜索")')
self.断言文本("舞龍", "#firstHeading")
self.断言元素('img[src*="Chinese_draak.jpg"]')
self.输入文本("#searchInput", "麻婆豆腐")
self.单击("#searchButton")
self.回去()
self.输入文本('input[name="search"]', "麻婆豆腐")
self.单击('button:contains("搜索")')
self.断言文本("麻婆豆腐", "#firstHeading")
self.断言元素('div.thumb div:contains("一家中餐館的麻婆豆腐")')
self.输入文本("#searchInput", "精武英雄")
self.单击("#searchButton")
self.断言元素('figure:contains("一家中餐館的麻婆豆腐")')
self.回去()
self.输入文本('input[name="search"]', "精武英雄")
self.单击('button:contains("搜索")')
self.断言元素('img[src*="Fist_of_legend.jpg"]')
self.断言文本("李连杰", 'li a[title="李连杰"]')
```

View File

@ -2,7 +2,7 @@
## [<img src="https://seleniumbase.github.io/img/logo6.png" title="SeleniumBase" width="32">](https://github.com/seleniumbase/SeleniumBase/) Using Desired Capabilities
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>.
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>).
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.)
@ -16,17 +16,33 @@ pytest test_demo_site.py --browser=remote --server=USERNAME:KEY@ondemand.us-east
(Parameters: ``--browser=remote``, ``--server=SERVER``, ``--port=PORT``, and ``--cap_file=CAP_FILE.py``)
Here's an example desired capabilities file for BrowserStack:
Here's an example desired capabilities file for BrowserStack using the newer SDK format in a `.yml` / `.yaml` file:
```yml
platforms:
- browserName: safari
osVersion: 17
deviceName: iPhone 15 Pro Max
buildIdentifier: ${BUILD_NUMBER}
parallelsPerPlatform: 1
projectName: My Project
browserstackLocal: true
debug: true
networkLogs: true
```
Here's an example desired capabilities file for BrowserStack using the legacy JSONWP format in a `.py` file:
```python
desired_cap = {
"os" : "Windows",
"os_version" : "11",
"browser" : "Chrome",
"browser_version" : "101.0",
"browserstack.local" : "false",
"browserstack.debug" : "true",
"browserstack.selenium_version" : "4.1.2",
"browser": "Chrome",
"os": "Windows",
"os_version": "11",
"browser_version": "latest",
"browserstack.console": "info",
"browserstack.debug": "true",
"browserstack.networkLogs": "true",
"browserstack.local": "true",
}
```
@ -46,7 +62,7 @@ capabilities = {
<div><b>You can generate specific desired capabilities using:</b></div>
<ul>
<li><a href="https://www.browserstack.com/automate/capabilities" target="_blank">BrowserStack desired capabilities</a></li>
<li><a href="https://www.browserstack.com/docs/automate/capabilities" target="_blank">BrowserStack desired capabilities</a></li>
<li><a href="https://saucelabs.com/products/platform-configurator" target="_blank">Sauce Labs desired capabilities</a></li>
</ul>
@ -82,7 +98,7 @@ pytest test_swag_labs.py --cap-string='{"browserName":"chrome","name":"test1"}'
(Enclose cap-string in single quotes. Enclose parameter keys in double quotes.)
If you pass ``"*"`` into the ``"name"`` field of ``--cap-string``, the name will become the test identifier. Example:
If you pass ``"*"`` into the ``"name"`` field of ``--cap-string``, the name will become the test identifier. Eg:
```bash
pytest my_first_test.py --cap-string='{"browserName":"chrome","name":"*"}' --server="127.0.0.1" --browser=chrome

View File

@ -1,9 +1,8 @@
# mkdocs dependencies for generating the seleniumbase.io website
# Minimum Python version: 3.8 (for generating docs only)
regex>=2023.10.3
PyYAML>=6.0.1
pymdown-extensions>=10.5
regex>=2023.12.25
pymdown-extensions>=10.7
pipdeptree>=2.13.1
python-dateutil>=2.8.2
Markdown==3.5.1
@ -17,11 +16,11 @@ cairocffi==1.6.1
pathspec==0.12.1
Babel==2.14.0
paginate==0.5.6
lxml==4.9.4
lxml==5.0.0
pyquery==2.0.0
readtime==3.0.0
mkdocs==1.5.3
mkdocs-material==9.5.2
mkdocs-material==9.5.3
mkdocs-exclude-search==0.6.6
mkdocs-simple-hooks==0.1.5
mkdocs-material-extensions==1.3.1