我对Gitlab Ci有意见。我对此完全不感兴趣。我在gitlab中放置了Ci之后,在本地运行了一个很好的测试。(Python3.8)--不幸的是,它已经不再那么丰富多彩了。我承认我对诸如Docker这样的话题一无所知。
这是我的..gitlab ci.yml:
stages:
- test
e2e:chrome:
services:
- selenium/standalone-chrome
before_script:
- python -V
- python3 -m pip install pytest
- python3 -m pip install selenium pytest
- python3 -m pip install webdriver_manager
- python3 -m pip install allure-pytest
script:
- python -m pytest Tvn24_Tests/Login_By_Facebook_Test.py我得到了错误:
ERROR at setup of Test_Log_in.test_Facebook_login_method_Passed ________
request = <SubRequest 'setup' for <Function test_Facebook_login_method_Passed>>
@pytest.fixture()
def setup(request):
options = Options()
options.page_load_strategy = 'normal'
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
Tvn24_Tests/conftest.py:13:
/usr/local/lib/python3.9/site-packages/webdriver_manager/chrome.py:25: in __init__
self.driver = ChromeDriver(name=name,
/usr/local/lib/python3.9/site-packages/webdriver_manager/driver.py:54: in __init__
self.browser_version = chrome_version(chrome_type)这是原稿:
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
import allure
@pytest.fixture()
def setup(request):
options = Options()
options.page_load_strategy = 'normal'
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
request.cls.driver = driver
driver.maximize_window()
yield
driver.quit()问题
是否有任何简单的指令在表单中创建这个yml文件:
中进行测试
发布于 2021-03-17 15:58:41
问题在于两件事:
选定的映像/服务没有安装configuration.,在linux计算机上运行的
请看下面我的conftest.py
我的conftest.py
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
import allure
@pytest.fixture()
def setup(request):
options = Options()
options.page_load_strategy = 'normal'
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument('--headless')
options.add_argument('--disable-gpu')
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
request.cls.driver = driver
driver.maximize_window()
yield
driver.quit()我的.gitlab-ci.yml (请考虑使用python3 -m pip install -r requirements.txt而不是单独的pip install):
stages:
- test
test:e2e:
stage: test
image: jaktestowac/python-chromedriver:3.6-xvfb
before_script:
- python3 -V
- python3 -m pip install pytest
- python3 -m pip install selenium pytest
- python3 -m pip install webdriver_manager
- python3 -m pip install allure-pytest
script:
- export PYTHONUNBUFFERED=1
- python3 -m pytest sample_tests.py我的sample_tests.py
import pytest
@pytest.mark.usefixtures("setup")
class SampleTestClass:
def test_google_title(self):
self.driver.get('https://google.com')
title = self.driver.title
print(f'Page title: {title}')
assert title == 'google'所有文件都在项目根目录中。
现在commit+push给您GitLab存储库并等待结果..。
这将给我们带来失败作为一个结果-不用担心!我们期待它,因为Google页面标题与预期不同(但现在我们确信测试确实有效):
_____________________ TestClassWithSetup.test_google_title _____________________
self = <sample_tests.TestClassWithSetup object at 0x7f33c9b053c8>
def test_google_title(self):
self.driver.get('https://google.com')
title = self.driver.title
print(f'Page title: {title}')
> assert title == 'google'
E AssertionError: assert 'Google' == 'google'
E - google
E ? ^
E + Google
E ? ^
sample_tests.py:9: AssertionError发布于 2021-09-24 02:08:30
当您在gitlab-ci中声明服务时,管道将提供一个辅助容器来帮助作业的主容器。
这个auxiliar容器位于同一个运行时内部网络中,您必须在主容器中调用它。
因此,您不需要担心安装webdriver或webdriver。
您必须使用远程use驱动程序将命令执行器指向selenium/独立服务。
示例使用selenium/独立-firefox作为服务:
..gitlab ci.yml
test selenium:
stage: test
services:
- selenium/standalone-firefox
image: python:3.9-slim
script:
- pip install selenium pytest
- pytest -v tests/test_selenium.py
artifacts:
when: always
paths:
- ./selenium.png测试/测试_selenium.py
from selenium.webdriver import Remote
def test_google():
driver = Remote(
command_executor='http://selenium__standalone-firefox:4444/wd/hub',
desired_capabilities={'browserName': 'firefox'}
)
driver.get('http://www.google.com')
driver.save_screenshot('selenium.png')
assert driver.title == 'Google'访问服务的方式有点奇怪(Selenium_Standalone Firefox),但是可以定义一个别名来更好地理解这些事情。所有这些的参考都在这里(https://docs.gitlab.com/ee/ci/services/#accessing-the-services)
发布于 2021-03-17 23:38:41
requirements.txt
pytest==6.2.2
selenium==3.141.0
webdriver_manager==3.3.0
allure-pytest==2.8.36gitlab-ci.yml
stages:
- build
- test
build:
stage: build
image: jaktestowac/python-chromedriver:3.6-xvfb
before_script:
- python3 -V
- pip install --upgrade pip
script:
- python3 -m pip install -r requirements.txt
test:e2e:
stage: test
script:
- python3 -m pytest Tvn24_Tests/Login_By_Facebook_Test.py --alluredir ./Report/Allure/Login_By_FB阶段错误:测试
$ python3 -m pytest Tvn24_Tests/Login_By_Facebook_Test.py
--alluredir ./Report/Allure/Login_By_FB
/usr/bin/python3: No module named pytesthttps://stackoverflow.com/questions/66671263
复制相似问题