Please help why I’m getting this error and what is the solution .
I’m not sure it is becasue my yaml or my test script itself.
Am i missing anything here or it’s wrong approach?
My script:
import pytest
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
import time
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-dev-shm-usage')
d = webdriver.Chrome('/home/<user>/chromedriver',chrome_options=chrome_options)
d.get('https://www.google.nl/')
service = Service("/usr/bin/chromedriver")
driver = webdriver.Chrome(service=service, options=chrome_options)
yield driver
self.driver = webdriver.Remote('http://selenium_standalone-chrome:4444/wd/hub', options=webdriver.ChromeOptions())
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("xxxx") # Replace with the actual username
password.send_keys("xxxx") # Replace with the actual password
# Find and click the login button
login_button = driver.find_element(By.XPATH, "//button[@id='submit-btn']") # Adjust the XPath for the actual button
login_button.click()
# Wait for a while to let the login process complete
time.sleep(10)
# Check if login was successful by verifying the presence of an element that appears after login
assert driver.find_element(By.XPATH, 'title').text == 'Dashboard'
and my yaml:
image: python:3.11-alpine
stages:
- test
auto-test:
stage: test
services:
- selenium/standalone-chrome
stage: test
before_script:
# Install necessary dependencies
- apk add --no-cache bash curl unzip chromium chromium-chromedriver
- pip install --upgrade pip
- pip install selenium 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 LogTest.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"
I have tried few solutions but still not working. Please help. Thankyou.
1