diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..05191e2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,170 @@ +### Example user template template +### Example user template + +# IntelliJ project files +.idea +*.iml +out +gen +### Python template +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + diff --git a/README.md b/README.md index 20f0091..abc61ba 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![fork](https://gitee.com/by_cwc/basic-auto-test/badge/fork.svg?theme=dark)](https://gitee.com/by_cwc/basic-auto-test) # 自动化测试框架 -- 使用技术:Python+Selenium3+Requests+Allure2+Pytest+Jenkins+Pymysql+openpyxl。 +- 使用技术:Python+Selenium4+Requests+Allure2+Pytest+Jenkins+Pymysql+openpyxl。 - 我们已经成功地在公司中落地了通用型框架!如果这个项目对你有帮助或启发,请多多点赞! - 在 conftest.py 中,我们封装了公共的 driver 对象,实现了调用 driver 对象时自动识别本地 Chrome 版本并自动下载相应的 driver,从而免除了手动下载匹配的麻烦。此外,我们还对代码进行了适配,使其可以自动识别是否是 Linux 平台,从而使用无头浏览器和 Selenium Grid,为我们的测试工作提供了便利。 - [![XRdTFH.jpg](https://s1.ax1x.com/2022/06/13/XRdTFH.jpg)](https://imgtu.com/i/XRdTFH) @@ -39,5 +39,7 @@ - 20220907 1. 新增ui自动化demo 2. 新增元素染色功能[![vHJmjS.jpg](https://s1.ax1x.com/2022/09/07/vHJmjS.jpg)](https://imgse.com/i/vHJmjS) +- 20240124 + 1. 依赖升级到 selenium4 diff --git a/TestCase/conftest.py b/TestCase/conftest.py index 480bb66..7a4bf19 100644 --- a/TestCase/conftest.py +++ b/TestCase/conftest.py @@ -6,8 +6,6 @@ import platform import pytest from selenium import webdriver -from selenium.webdriver.common.desired_capabilities import DesiredCapabilities -from webdriver_manager.chrome import ChromeDriverManager from Commons.operation_file.operation_ymal import ReadYaml @@ -27,30 +25,33 @@ def pytest_collection_modifyitems(items): # 代码提取 def get_drvier(model=None): - # def get_drvier(model="debug"): global driver # 判断系统是否是linux如果是就返回true ishandless = True if platform.system() == 'Linux' else False # 服务器使用或者远程调试 if model == "debug" or ishandless: option = webdriver.ChromeOptions() - option.add_argument('--headless') - option.add_argument('--no-sandbox') - option.add_argument('--disable-gpu') + # option.add_argument('--headless') + # option.add_argument('--no-sandbox') + # option.add_argument('--disable-gpu') option.add_argument('--disable-dev-shm-usage') option.add_argument('--hide-scrollbars') option.add_argument('--window-size=1920,1080') + option.add_argument('--disable-blink-features=AutomationControlled') option.add_experimental_option('useAutomationExtension', False) option.add_experimental_option('excludeSwitches', ['enable-automation']) - # command_executor 填写自己的grid地址 - driver = webdriver.Remote(command_executor='', - desired_capabilities=DesiredCapabilities.CHROME, options=option) + # command_executor 自己的 webdriver 地址 + driver = webdriver.Remote(command_executor='http://192.168.1.227:5444/wd/hub', options=option) driver.implicitly_wait(conf.get("ALL_TIMEOUT")) # 本地调试使用 else: - path = ChromeDriverManager(cache_valid_range=7).install() - driver = webdriver.Chrome(executable_path=path) + options = webdriver.ChromeOptions() + service = webdriver.ChromeService() + driver = webdriver.Chrome(service=service, options=options) driver.maximize_window() + # path = ChromeDriverManager().install() + # driver = webdriver.Chrome(executable_path=path) + # driver.maximize_window() return driver diff --git a/requeirments.txt b/requeirments.txt new file mode 100644 index 0000000..d5d655f --- /dev/null +++ b/requeirments.txt @@ -0,0 +1,53 @@ +allure-pytest==2.13.2 +allure-python-commons==2.13.2 +apipkg==3.0.2 +attrs==23.2.0 +certifi==2023.11.17 +chardet==5.2.0 +charset-normalizer==3.3.2 +colorama==0.4.6 +configparser==6.0.0 +crayons==0.4.0 +et-xmlfile==1.1.0 +exceptiongroup==1.2.0 +execnet==1.9.0 +h11==0.14.0 +idna==3.2 +iniconfig==1.1.1 +jenkins==1.0.2 +jmespath==1.0.1 +jsonpath==0.82 +jsonschema==4.4.0 +multi-key-dict==2.0.3 +openpyxl==3.0.7 +outcome==1.3.0.post0 +packaging==21.3 +pbr==5.8.1 +pluggy==1.4.0 +py==1.10.0 +PyMySQL==1.1.0 +pyparsing==2.4.7 +pyrsistent==0.18.1 +PySocks==1.7.1 +pytest==8.0.0rc2 +pytest-assume==2.4.3 +pytest-forked==1.3.0 +pytest-ordering==0.6 +pytest-repeat==0.9.3 +pytest-rerunfailures==13.0 +pytest-xdist==3.5.0 +python-jenkins==1.8.2 +PyYAML==6.0.1 +requests==2.31.0 +selenium==4.17.2 +six==1.16.0 +sniffio==1.3.0 +sortedcontainers==2.4.0 +toml==0.10.2 +tomli==2.0.1 +trio==0.24.0 +trio-websocket==0.11.1 +typing_extensions==4.9.0 +urllib3==1.26.6 +webdriver-manager==3.2.2 +wsproto==1.2.0 diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index ad55a03..0000000 --- a/requirements.txt +++ /dev/null @@ -1,42 +0,0 @@ -allure-pytest==2.8.29 -allure-python-commons==2.8.29 -apipkg==1.5 -attrs==21.2.0 -certifi==2021.5.30 -chardet==4.0.0 -charset-normalizer==2.0.4 -colorama==0.4.4 -configparser==5.0.2 -crayons==0.4.0 -et-xmlfile==1.1.0 -execnet==1.9.0 -idna==3.2 -iniconfig==1.1.1 -jenkins==1.0.2 -jmespath==0.10.0 -jsonpath==0.82 -jsonschema==4.4.0 -multi-key-dict==2.0.3 -openpyxl==3.0.7 -packaging==21.3 -pbr==5.8.1 -pluggy==0.13.1 -py==1.10.0 -PyMySQL==0.9.3 -pyparsing==2.4.7 -pyrsistent==0.18.1 -pytest==6.2.4 -pytest-assume==2.4.3 -pytest-forked==1.3.0 -pytest-ordering==0.6 -pytest-repeat==0.9.1 -pytest-rerunfailures==10.1 -pytest-xdist==2.3.0 -python-jenkins==1.7.0 -PyYAML==5.3.1 -requests==2.26.0 -selenium==3.141.0 -six==1.16.0 -toml==0.10.2 -urllib3==1.26.6 -webdriver-manager==3.2.2