## Contents
- [Installation](#Installation)
- [Usage](#Usage)
- [Report](#Report)
- [Docker](#Docker)
- [DevOps](#DevOps)
## Installation
```commandline
pip install xiaoli-autotest-pytest
```
## Usage
#### 1. cli-run
```
pytest --csv=script/test_hello.csv --slowtime=1000 --headless
cases/test_main.py::test_http_api[Print hello]
Test Case => {'case_id': '0001', 'case_name': 'Test hello', 'step_name': 'Print hello', 'protocols': 'http_api', 'route': 'mods.hello.hello.print_hello', 'parameter': '', 'scope': 'dev'}
=> Load route mods.hello.hello success
=> Load class Hello success
=> Load cases print_hello success
hello
PASSED
```
#### 2. Parameter Description
| Parameters | Type | Required | Description |
|:-----------|:-------:|:--------:|:----------------------------------------------------------------------------------------|
| --csv | str | Yes | Your script file name |
| --slowtime | int | No | The interval of each step of the UI test, in milliseconds, the default 1000ms is 1 second|
| --headless | boolean | No | Whether to enable headless mode (no browser mode) during UI test|
#### 3. Test Case Script
Create a csv script file in the script directory, e.g. <test_hello.csv>
```Excel
case_id,case_name,step_id,step_name,method,route,parameter,hard_assert,scope
0001,Test hello,1,Print hello,test_http_api,hello.hello.print_hello,,false,dev
```
> Note: It can be created or opened in Excel, and must be saved in "CSV UTF-8(Comma delimited)" format to avoid garbled Chinese characters. Save as "UTF-8" when using other text tools
#### 4. Test Case Field Description
| Parameters | Type | Required | Description |
|:-----------|:-----|:--------:|:-------------------------------------------------------------------------------|
| case_id | str | Yes | Test case number, unique |
| case_name | str | Yes | Test case name |
| step_name | str | Yes | Test case step |
| protocols | str | Yes | Test Protocol<br/>http_api: http interface test<br/>playwright: UI test driven |
| route | str | Yes | Test class-to-method routing, all lowercase underscores |
| parameter | str | No | Test parameter |
| scope | str | Yes | Test scope, default: smoke, dev, test, stage, etc. |
## Report
allure-results is generated by default under the project root directory. The development environment does not automatically generate Allure Report HTML, you need to manually generate and open the html report:
```commandline
allure serve allure-results
```
## Docker
#### 1. docker pull
```commandline
docker push roger813/xiaoli-autotest-pytest:tag
```
#### 2. rename image
> Note: This step is optional, if you do not change the name, then the image name in the next step needs to be replaced with the full name
```commandline
docker tag roger813/xiaoli-autotest-pytest:tag xiaoli-autotest-pytest
```
#### 3. verify image
```commandline
docker run -d --name pytest -p 8080:8080 xiaoli-autotest-pytest
```
- Open the container and the log is displayed: Report successfully generated to allure-report, Images are available.
- Open your browser to access the allure report: http://localhost:8080
- If the following page is displayed, the image is successfully pulled
![allure_demo.png](xiaoli-autotest-pytest/assets/allure_demo.png)
#### 4. business Test
```text
cd your-project-directory
docker run -d --name pytest -p 8080:8080 -v %cd%\assets:/work/assets -v %cd%\confs:/work/confs -v %cd%\mods:/work/mods -v %cd%\script:/work/script -e csv=custom.csv swpic-autotest-pytest
```
- Go to your project directory
- Mount the assets, confs, mods, and script directories in the service project
- Add environmental parameters
- -e csv=your_script_file.csv(required)
- -e scope=dev(optional), Determine your test scope, default to full environment testing
- Open your browser to access the allure report: http://localhost:8080
## DevOps
#### Jenkins Pipeline
```groovy
parameters {
string(
name: 'SCRIPT',
defaultValue: 'your_test_script.csv',
description: '测试脚本CSV文件, 描述测试业务逻辑(必须)')
string(
name: 'TEST_SCOPE',
defaultValue: 'dev,test,stage,smoke,regress',
description: '测试范围, 默认全范围测试. 选择需要测试的用例范围(可选)')
// string(
// name: 'SLOW_TIME',
// defaultValue: '1000',
// description: '测试间隔, UI测试中每一步操作间隔时间, 单位毫秒(可选)')
string(
name: 'BUSINESS_BRANCH',
defaultValue: 'dev',
description: '测试代码仓库分支(可选)')
booleanParam(
name: 'PARALLEL_TEST',
defaultValue: false,
description: '是否多线程, 默认关闭. 适用于没有依赖关系的用例集(可选)')
}
```
| Parameters | Description | Required | Proposal |
|:----------------|:--------------------------------|:---------|:---------------------------------------------------------------------------------|
| SCRIPT | your_script_file | Yes | |
| TEST_SCOPE | test scope | Yes | |
| SLOW_TIME | test interval | No | If it is not a UI test project, you do not need it |
| BUSINESS_BRANCH | Branch of the business repo | Yes | Quickly verify branch correctness and avoid unnecessary merging efforts |
| PARALLEL_TEST | Whether to enable multithreading| No | Enable this, speed up the test, use cases have dependencies and use with caution |
#### run with parameter
![jenkins_run_entry.png](xiaoli-autotest-pytest/assets/jenkins_run_entry.png)
![jenkins_run_config.png](xiaoli-autotest-pytest/assets/jenkins_run_config.png)
#### view logs & reports
![jenkins_run_logs.png](xiaoli-autotest-pytest/assets/jenkins_run_logs.png)
![jenkins_report_entry.png](xiaoli-autotest-pytest/assets/jenkins_report_entry.png)
![jenkins_allure_report.png](xiaoli-autotest-pytest/assets/jenkins_allure_report.png)
## End
Raw data
{
"_id": null,
"home_page": "https://gitee.com/roger813/xiaoli-autotest-pytest.git",
"name": "xiaoli-autotest-pytest",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "example project",
"author": "Li wenhuan",
"author_email": "roger813@163.com",
"download_url": "https://files.pythonhosted.org/packages/de/03/1cb3ffb00721955a7db4f894965ba41c8d5a795ce35c9f0fad9a3cff5dc2/xiaoli_autotest_pytest-1.0.1.tar.gz",
"platform": null,
"description": "\r\n\r\n## Contents\r\n\r\n- [Installation](#Installation)\r\n- [Usage](#Usage)\r\n- [Report](#Report)\r\n- [Docker](#Docker)\r\n- [DevOps](#DevOps)\r\n\r\n## Installation\r\n\r\n```commandline\r\npip install xiaoli-autotest-pytest\r\n```\r\n\r\n## Usage\r\n#### 1. cli-run\r\n```\r\npytest --csv=script/test_hello.csv --slowtime=1000 --headless\r\n\r\ncases/test_main.py::test_http_api[Print hello]\r\nTest Case => {'case_id': '0001', 'case_name': 'Test hello', 'step_name': 'Print hello', 'protocols': 'http_api', 'route': 'mods.hello.hello.print_hello', 'parameter': '', 'scope': 'dev'}\r\n => Load route mods.hello.hello success\r\n => Load class Hello success\r\n => Load cases print_hello success\r\nhello\r\nPASSED\r\n```\r\n\r\n#### 2. Parameter Description\r\n| Parameters | Type | Required | Description |\r\n|:-----------|:-------:|:--------:|:----------------------------------------------------------------------------------------|\r\n| --csv | str | Yes | Your script file name |\r\n| --slowtime | int | No | The interval of each step of the UI test, in milliseconds, the default 1000ms is 1 second|\r\n| --headless | boolean | No | Whether to enable headless mode (no browser mode) during UI test|\r\n\r\n#### 3. Test Case Script\r\nCreate a csv script file in the script directory, e.g. <test_hello.csv>\r\n```Excel\r\ncase_id,case_name,step_id,step_name,method,route,parameter,hard_assert,scope\r\n0001,Test hello,1,Print hello,test_http_api,hello.hello.print_hello,,false,dev\r\n```\r\n\r\n> Note: It can be created or opened in Excel, and must be saved in \"CSV UTF-8(Comma delimited)\" format to avoid garbled Chinese characters. Save as \"UTF-8\" when using other text tools\r\n\r\n#### 4. Test Case Field Description\r\n| Parameters | Type | Required | Description |\r\n|:-----------|:-----|:--------:|:-------------------------------------------------------------------------------|\r\n| case_id | str | Yes | Test case number, unique |\r\n| case_name | str | Yes | Test case name |\r\n| step_name | str | Yes | Test case step |\r\n| protocols | str | Yes | Test Protocol<br/>http_api: http interface test<br/>playwright: UI test driven |\r\n| route | str | Yes | Test class-to-method routing, all lowercase underscores |\r\n| parameter | str | No | Test parameter |\r\n| scope | str | Yes | Test scope, default: smoke, dev, test, stage, etc. |\r\n\r\n## Report\r\nallure-results is generated by default under the project root directory. The development environment does not automatically generate Allure Report HTML, you need to manually generate and open the html report:\r\n\r\n```commandline\r\nallure serve allure-results\r\n```\r\n\r\n## Docker\r\n\r\n#### 1. docker pull\r\n```commandline\r\ndocker push roger813/xiaoli-autotest-pytest:tag\r\n```\r\n\r\n#### 2. rename image\r\n> Note: This step is optional, if you do not change the name, then the image name in the next step needs to be replaced with the full name\r\n\r\n```commandline\r\ndocker tag roger813/xiaoli-autotest-pytest:tag xiaoli-autotest-pytest\r\n```\r\n\r\n#### 3. verify image \r\n```commandline\r\ndocker run -d --name pytest -p 8080:8080 xiaoli-autotest-pytest\r\n```\r\n- Open the container and the log is displayed: Report successfully generated to allure-report, Images are available.\r\n- Open your browser to access the allure report: http://localhost:8080\r\n- If the following page is displayed, the image is successfully pulled\r\n\r\n![allure_demo.png](xiaoli-autotest-pytest/assets/allure_demo.png)\r\n\r\n#### 4. business Test\r\n```text\r\ncd your-project-directory\r\ndocker run -d --name pytest -p 8080:8080 -v %cd%\\assets:/work/assets -v %cd%\\confs:/work/confs -v %cd%\\mods:/work/mods -v %cd%\\script:/work/script -e csv=custom.csv swpic-autotest-pytest\r\n```\r\n- Go to your project directory\r\n- Mount the assets, confs, mods, and script directories in the service project\r\n- Add environmental parameters\r\n - -e csv=your_script_file.csv(required)\r\n - -e scope=dev(optional), Determine your test scope, default to full environment testing\r\n- Open your browser to access the allure report: http://localhost:8080\r\n\r\n## DevOps\r\n#### Jenkins Pipeline\r\n```groovy\r\nparameters {\r\n string(\r\n name: 'SCRIPT',\r\n defaultValue: 'your_test_script.csv',\r\n description: '\u6d4b\u8bd5\u811a\u672cCSV\u6587\u4ef6, \u63cf\u8ff0\u6d4b\u8bd5\u4e1a\u52a1\u903b\u8f91(\u5fc5\u987b)')\r\n string(\r\n name: 'TEST_SCOPE',\r\n defaultValue: 'dev,test,stage,smoke,regress',\r\n description: '\u6d4b\u8bd5\u8303\u56f4, \u9ed8\u8ba4\u5168\u8303\u56f4\u6d4b\u8bd5. \u9009\u62e9\u9700\u8981\u6d4b\u8bd5\u7684\u7528\u4f8b\u8303\u56f4(\u53ef\u9009)')\r\n // string(\r\n // name: 'SLOW_TIME',\r\n // defaultValue: '1000',\r\n // description: '\u6d4b\u8bd5\u95f4\u9694, UI\u6d4b\u8bd5\u4e2d\u6bcf\u4e00\u6b65\u64cd\u4f5c\u95f4\u9694\u65f6\u95f4, \u5355\u4f4d\u6beb\u79d2(\u53ef\u9009)')\r\n string(\r\n name: 'BUSINESS_BRANCH',\r\n defaultValue: 'dev',\r\n description: '\u6d4b\u8bd5\u4ee3\u7801\u4ed3\u5e93\u5206\u652f(\u53ef\u9009)')\r\n booleanParam(\r\n name: 'PARALLEL_TEST',\r\n defaultValue: false,\r\n description: '\u662f\u5426\u591a\u7ebf\u7a0b, \u9ed8\u8ba4\u5173\u95ed. \u9002\u7528\u4e8e\u6ca1\u6709\u4f9d\u8d56\u5173\u7cfb\u7684\u7528\u4f8b\u96c6(\u53ef\u9009)')\r\n }\r\n```\r\n\r\n| Parameters | Description | Required | Proposal |\r\n|:----------------|:--------------------------------|:---------|:---------------------------------------------------------------------------------|\r\n| SCRIPT | your_script_file | Yes | |\r\n| TEST_SCOPE | test scope | Yes | |\r\n| SLOW_TIME | test interval | No | If it is not a UI test project, you do not need it |\r\n| BUSINESS_BRANCH | Branch of the business repo | Yes | Quickly verify branch correctness and avoid unnecessary merging efforts |\r\n| PARALLEL_TEST | Whether to enable multithreading| No | Enable this, speed up the test, use cases have dependencies and use with caution |\r\n\r\n#### run with parameter\r\n![jenkins_run_entry.png](xiaoli-autotest-pytest/assets/jenkins_run_entry.png)\r\n![jenkins_run_config.png](xiaoli-autotest-pytest/assets/jenkins_run_config.png)\r\n\r\n#### view logs & reports\r\n![jenkins_run_logs.png](xiaoli-autotest-pytest/assets/jenkins_run_logs.png)\r\n![jenkins_report_entry.png](xiaoli-autotest-pytest/assets/jenkins_report_entry.png)\r\n![jenkins_allure_report.png](xiaoli-autotest-pytest/assets/jenkins_allure_report.png)\r\n\r\n## End\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Simple autotest framework, using python and pytest as the basis for data comparison, interface testing, UI testing and so on",
"version": "1.0.1",
"project_urls": {
"Homepage": "https://gitee.com/roger813/xiaoli-autotest-pytest.git"
},
"split_keywords": [
"example",
"project"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e82143733e8c4a41ce3d7dfaf4d351261056b2026bad2915e83b6e4e4f731cb2",
"md5": "35b8c4a64a60d6bde3f7ccd937e6763b",
"sha256": "189b31c96f559da5b2dac2513f0a0a92a50a8f41239874c9498fddac4ad86f3f"
},
"downloads": -1,
"filename": "xiaoli_autotest_pytest-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "35b8c4a64a60d6bde3f7ccd937e6763b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 4708,
"upload_time": "2025-01-01T06:47:29",
"upload_time_iso_8601": "2025-01-01T06:47:29.291588Z",
"url": "https://files.pythonhosted.org/packages/e8/21/43733e8c4a41ce3d7dfaf4d351261056b2026bad2915e83b6e4e4f731cb2/xiaoli_autotest_pytest-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "de031cb3ffb00721955a7db4f894965ba41c8d5a795ce35c9f0fad9a3cff5dc2",
"md5": "ef3b38f8fe3befb41756b1ef2260da88",
"sha256": "a547c365acda18a947e7300504ae64fed5ff6332a3395f6d925c706e20fa17a0"
},
"downloads": -1,
"filename": "xiaoli_autotest_pytest-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "ef3b38f8fe3befb41756b1ef2260da88",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5179,
"upload_time": "2025-01-01T06:47:33",
"upload_time_iso_8601": "2025-01-01T06:47:33.700168Z",
"url": "https://files.pythonhosted.org/packages/de/03/1cb3ffb00721955a7db4f894965ba41c8d5a795ce35c9f0fad9a3cff5dc2/xiaoli_autotest_pytest-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-01 06:47:33",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "xiaoli-autotest-pytest"
}