Selenium Google login works locally but not in CircleCI

Viewed 201

I'd like to run an end-to-end test of logging into our website using Selenium. We use Auth0 and the only available login mechanism is through Google social login. I wrote a script using Python Selenium (version 3.141.0), pytest, and selenium/standalone-chrome:87.0 Docker image which works correctly on my local machine, Mac OS 10.15.4.

However, it gets stuck at some point when I try to run it on CircleCI.

I use ubuntu-1604:202007-01 image in CircleCI

How I set up remote driver (tried a lot of arguments/commands..):

@pytest.fixture(scope="function")
def browser(remote_webdriver_url):
    options = webdriver.ChromeOptions()
    options.add_argument('--disable-popup-blocking')
    options.add_argument('--disable-web-security')
    options.add_argument('--allow-running-insecure-content')
    options.add_argument('--start-maximized')
    options.add_argument('-incognito')
    options.add_experimental_option("useAutomationExtension", False)
    options.add_experimental_option("excludeSwitches", ["enable-automation"])

    browser = webdriver.Remote(
        command_executor=remote_webdriver_url,
        desired_capabilities=DesiredCapabilities.CHROME,
        options=options)
    return browser

My docker-compose.yml

version: '3.1'

services:
  selenium-chrome:
    image: selenium/standalone-chrome:87.0
    # added the envvar as I found something about this in Selenium forums, it has no effect.
    environment:
      DBUS_SESSION_BUS_ADDRESS: /dev/null
    shm_size: 2g
    restart: 'no'
    ports:
      - "4444:4444"

My test code:

import os

from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


def test_logging_in(browser: WebElement, url):
    auth0_title = "Sign In with Auth0"
    browser.get(url)
    assert browser.title == auth0_title

    # Log in
    auth_login_button_class_name = 'auth0-lock-social-button-text'
    _ = WebDriverWait(browser, 20).until(EC.presence_of_element_located((By.CLASS_NAME, auth_login_button_class_name)))
    sign_in_button = browser.find_element_by_class_name(auth_login_button_class_name)
    browser.implicitly_wait(5)
    #
    sign_in_button.click()

    # Wait until we're redirected to Google's login page
    _ = WebDriverWait(browser,20).until(EC.title_contains('Google'))

    # Type in the email address and go to the next page
    email_input = browser.find_element_by_tag_name('input')
    email_input.send_keys(os.environ.get('E2E_TEST_DEVELOPMENT_USER_EMAIL'))
    first_next_button = browser.find_element_by_id("identifierNext")
    first_next_button.click()

    # Wait until the password entry screen is loaded
    browser.get_screenshot_as_file('/tmp/scr.png')
    _ = WebDriverWait(browser, 20).until(EC.presence_of_element_located((By.ID, "forgotPassword"))) ##### THIS IS WHERE I GET THE TIMEOUT

    # Put the password in
    password_input = browser.find_element_by_xpath("//input[@name='password']")
    password_input.send_keys(os.environ.get('E2E_TEST_DEVELOPMENT_USER_PASSWORD'))
    second_next_button = browser.find_element_by_id("passwordNext")
    second_next_button.click()

    # Wait until the login is successful by observing the logout button
    logout_icon_class_name = "bp3-icon-log-out"
    _ = WebDriverWait(browser, 20).until(EC.presence_of_element_located((By.CLASS_NAME, logout_icon_class_name)))
    assert browser.title == 'My page title'
    sign_out_button = browser.find_element_by_class_name(logout_icon_class_name)
    sign_out_button.click()


def test_teardown(browser):
    browser.close()
    browser.quit()

The test times out after clicking on the first button after typing in the email. I got screenshots from the run in CI, and it does seem to be stuck loading (see the Google's progress bar at the top, and the fact that it's more white-ish color), see the screenshot: enter image description here

I also took a screenshot before clicking on the "Next" button, to show the contrast: enter image description here

After having spent a long time on this and trying many things, I'm about to give up. Any ideas why this works locally but not in CI environment?

0 Answers
Related