I'm running simple selenium test on GitLab CI (free tier).
Sometimes I get failing job because elements where not located (after taking screenshot it appears that page is displayed as white screen).
After running failed job couple of times it starts working. It is very hard to reproduce because it is quite rare.
How can I get more info what kind of issue it is? Some memory problems with runners or other?
Example selenium script:
import unittest
from selenium import webdriver
class SmokeTests(unittest.TestCase):
@classmethod
def setUpClass(self):
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
self.driver = webdriver.Chrome(options=chrome_options)
base_url = 'https://google.com'
self.driver.get(base_url)
@classmethod
def tearDownClass(self):
self.driver.quit()
def test_name(self):
expected_title = 'Google'
observed_title = self.driver.title
self.assertEqual(expected_title, observed_title)
EDIT
How it looks like when running job couple times
Logs contain standard info when title will be not found:
AssertionError: 'Google' != ''
- Google
+
----------------------------------------------------------------------
Ran 1 test in 1.193s
FAILED (failures=1)
tearDown
Cleaning up project directory and file based variables 00:01
ERROR: Job failed: exit code 1
I experienced this problem on different pages/servers/repositories. Possible issue is lack of memory on shared runners so maybe usage of below option can help:
options.add_argument('--disable-dev-shm-usage')
but is not possible to test it due to randomness of this fail.
CI script:
test staging ui:
image: jaktestowac/python-chromedriver:3.9-selenium
before_script:
- pip install -r tests/requirements.txt
script:
- python -m unittest tests/smoke_tests.py
Image used for testing: https://hub.docker.com/layers/jaktestowac/python-chromedriver/3.9-selenium/images/sha256-5feb585b9ebdac3f5191e7c24f29e8e78beb4f69c9bc734d7050157544f4653f?context=explore
EDIT2
Using wait is not a case here (tested for 20sec). With this random bug the Page is not loaded at all (title element is not available).
Currently I'm trying find some clues with logging :
d = DesiredCapabilities.CHROME
d['goog:loggingPrefs'] = { 'browser':'ALL' }
self.driver = webdriver.Chrome(desired_capabilities=d, options=self.chrome_options)