- Supports running on both PC and H5, fetching API data through proxies, headless mode, generating reports (including screenshots), sending emails, etc.
- Pull requests are welcome.
- 中文文档
-
Copy and modify the global configuration:
cp config.example.yaml config.yaml
. This file serves as the global configuration, and files in theconfig
directory can override it. -
Use:
python test.py filename
, wherefilename
is the name of the file in the project'sconfig
directory, e.g.,python3 test.py default
. If no filename is provided, it defaults todefault.yaml
. -
Test cases are written in YAML format. See YAML Examples for details.
-
Run existing test cases:
python3 test.py default,test1
, which opens Baidu, searches for "stingbo pystest", navigates to the GitHub directory, and finally opens the specified project.
-
View all test cases in the
config
directory:python3 test.py ls
. -
Run multiple test cases simultaneously:
python3 test.py test1,test2,test3
. -
Execute test cases from a configuration file:
python3 test.py -f /your/path/test.txt
. The file content should be like:test1,test2,test3
-
Run all test cases in the
config
directory:python3 test.py all_test
.
-
Python 3.7 or above.
-
HTMLTestRunner for generating test reports. Reports are stored in the
reports
directory. -
Selenium for browser automation.
-
WebDriver. Download from here.
-
BrowserMob Proxy for proxying API requests.
-
Framework logic:
- Retrieve and merge configurations, launch the browser.
- Check for
wait_disappear
configuration. - Check for
iframe
configuration. - Check for
wait
configuration. - Check for
listener
configuration. - Locate elements based on
type
,content
, andindex
. - Execute JavaScript if configured.
- Perform actions based on the
action
configuration.
-
Configuration sections:
- DEBUG: Boolean,
True/False
. Enable debug mode. - IMAGE: Boolean,
True/False
. Enable screenshots. - MAIL: Email configuration for sending test reports.
- BROWSER: Browser-related settings.
- WEBSITE: Settings for the starting page.
- MENU: Test case details.
- TEST: Specific test cases to execute.
- DEBUG: Boolean,
DEBUG: False
IMAGE: True
MAIL:
SEND: True
SMTP:
username: send_notice@test.com
password: xxxxxxxxxx
host: smtp.163.com
port: 25
receiver:
- receiver1@test.com
- receiver2@test.com
BROWSER:
type: Chrome
bmp_path: your/browsermob-proxy/path
proxy: True
H5: True
device_name: iPhone 7
headless: True
WEBSITE:
url: http://www.your_website_url.com
MENU:
login:
key: login
name: Login
type: xpath
content: //button[@class='btn btn-primary' and text()='Login']
index: -1
action: click
listener:
- url: login/url
code: 0
operation:
- name: Username
type: tag name
content: input
value: xxxxx
index: 2
action: sendKeys
- name: Password
type: tag name
content: input
value: xxxxx
index: 3
action: sendKeys
-
Use contents to obtain elements within the scope of the previous one, using `.(dot + double slash).
-
When matching with class, if the class contains spaces, include them in the xpath configuration, or use contains.
-
The pre-commit.sample file is a git hook. Copy it with cp pre-commit.sample .git/hooks/pre-commit. It relies on yapf and pyflakes for Python code syntax and format checking.
-
Examples of usage can be found in the files in the config directory. Feel free to use, and if you have any questions or suggestions, please open an issue.