Я запустил тест, который отлично работает локально на Python 3.12)
После фиксации Ci gitlab — к сожалению, не работает
Мой yaml:
Код: Выделить всё
image: python:3.11-alpine
stages:
- test
auto-test:
stage: test
services:
- selenium/standalone-chrome:latest
stage: test
before_script:
# Install necessary dependencies
- pip install webdriver-manager
- apk add --no-cache bash curl unzip chromium chromium-chromedriver
- pip install --upgrade pip
- pip install selenium pytest
- 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
# Verify installation
- chromium-browser --version
- chromedriver --version
# Set up virtual environment
- python -m venv venv
- . venv/bin/activate
script:
- echo "Running Test Script..."
- pytest login_test.py --maxfail=1 --disable-warnings -q --tb=short
variables:
# Set Chrome options for headless execution in CI
DISPLAY: ":99"
CHROME_BIN: "/usr/bin/chromium-browser"
CHROME_DRIVER: "/usr/bin/chromedriver"
Код: Выделить всё
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
import pytest
import time
# Setup Chrome options
@pytest.fixture(scope='function')
def driver():
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
yield driver
driver.quit()
def test_login(driver):
driver.get("https://websitexxx/login")
# Find the username and password fields and fill them in
email = driver.find_element(By.XPATH, "//input[contains(@id, 'login-email')]")
password = driver.find_element(By.XPATH, "//input[contains(@id, 'login-password')]")
email.send_keys("xxx") # Replace with the actual username
password.send_keys("xxx") # Replace with the actual password
# Find and click the login button
login_button = driver.find_element(By.XPATH, "//button[@id='submit-btn']")
login_button.click()
# Wait for the login process to complete
time.sleep(10)
# Check if login was successful by verifying the page title
assert "Dashboard" in driver.title, "Title did not contain 'Dashboard'"
Код: Выделить всё
==================================== ERRORS ====================================
_________________________ ERROR at setup of test_login _________________________
login_test.py:17: in driver
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
/usr/local/lib/python3.11/site-packages/selenium/webdriver/chrome/webdriver.py:45: in __init__
super().__init__(
/usr/local/lib/python3.11/site-packages/selenium/webdriver/chromium/webdriver.py:55: in __init__
self.service.start()
/usr/local/lib/python3.11/site-packages/selenium/webdriver/common/service.py:98: in start
self._start_process(self._path)
/usr/local/lib/python3.11/site-packages/selenium/webdriver/common/service.py:208: in _start_process
self.process = subprocess.Popen(
/usr/local/lib/python3.11/subprocess.py:1026: in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
/usr/local/lib/python3.11/subprocess.py:1955: in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
E FileNotFoundError: [Errno 2] No such file or directory: '/root/.wdm/drivers/chromedriver/linux64/114.0.5735.90/chromedriver'
=========================== short test summary info ============================
ERROR login_test.py::test_login - FileNotFoundError: [Errno 2] No such file or directory: '/root/.wdm/drivers/chromedriver/linux64/114.0.5735.90/chromedriver'
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
1 error in 0.80s
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1
Подробнее здесь: https://stackoverflow.com/questions/789 ... t-selenium