I need your help so much! I have autotests written using Selenium+python+pytest in Gitlab CI\CD. After updating Chrome and, accordingly, the Chrome driver to version 119, autotests began to produce errors like TimeoutException or NoSuchElementException for some elements. And some elements it find without any problems. But when I run these same tests locally on the computer, the webdriver finds all the elements. Maybe it's a matter of the options being passed to Chromedriver in conftest.py file for CI\CD. It's look like:
def driver() -> WebDriver:
print("\nStart browser for test..")
options=Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--disable-gpu')
options.add_argument('--disable-browser-side-navigation')
options.add_argument('--disable-infobars')
options.add_argument('--disable-extensions')
options.add_argument('--start-maximized')
options.add_argument('--disable-notifications')
options.add_argument('--disable-translate')
browser = webdriver.Remote(
command_executor='http://selenium__standalone-chrome:4444/wd/hub',
options=options)
yield browser
print("\nQuit browser")
browser.quit()
I don't have any options for local tests except "--icognito". My yml file to Gitlab looks like:
image: python:3.11.4
default:
tags:
- almalinux8
- common
- dev-runner05
- devops
- docker
stages:
- test_Datateh
Datateh test:
stage: test_Datateh
extends: .job_template
script:
- pytest -s -v --tb=native Autotests/Sales/test_Datatech.py
.job_template:
services:
- selenium/standalone-chrome
before_script:
- pip install --upgrade pip
- pip install -r requirements.txt
Using requirements:
pytest==7.4.3
selenium==4.15.0
urllib3==2.1.0
I tried:
- to change the CSS selectors,
- to remove the chrome driver options one by one,
- to increase the waiting time for the page to load. Nothing helped. Nothing should overlap elements on the page. The tests worked properly in version 118 of Chrome on Gitlab CI\CD. When I'm running tests by Chrome 119 locally on the computer, the tests work correctly. It might be worth extracting the page structure using a script
with open("page2.html", "wt", encoding="utf-8") as file:
file.write(driver.page_source)
into a file and looking at it. I try, but can’t write it in file on Gitlab. Why might Selenium not see some elements on the page?
The problem was that after updating Chrome, the pages began to be displayed in mobile device mode. You need to register the web driver option with the required resolution.