Skip to content

Commit cb4dba6

Browse files
committed
use selenium headless on CI
1 parent a4d25cf commit cb4dba6

File tree

5 files changed

+69
-32
lines changed

5 files changed

+69
-32
lines changed

Dockerfile.selenium

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,45 @@
11
FROM seleniarm/standalone-chromium
22

33
ENV PYTHONUNBUFFERED 1
4+
45
USER root
5-
RUN sudo apt-get update ; apt-get install -yq build-essential zlib1g-dev make libssl-dev
6-
RUN wget -O /Python-3.11.9.tgz https://www.python.org/ftp/python/3.11.9/Python-3.11.9.tgz
7-
WORKDIR /
8-
RUN tar -xvzf Python-3.11.9.tgz
9-
WORKDIR /Python-3.11.9
10-
RUN sudo ./configure && sudo make && sudo make altinstall
11-
RUN sudo rm /usr/bin/python3
12-
RUN sudo ln -s /usr/local/bin/python3.11 /usr/bin/python3
13-
RUN sudo ln -s /usr/local/bin/pip3.11 /usr/bin/pip3
14-
# RUN sudo -H pip3 install virtualenv
15-
# RUN useradd -m -s /bin/bash DEV
16-
# USER DEV
6+
7+
#
8+
# Uncomment below section to use custom install python3.11.9 (the same as currently provisioned on EC2)
9+
# Keep it here to trouble shoot CI docker (registered at AWS ECR) locally since trouble shooting on CI is
10+
# time consuming.
11+
#
12+
# ------- begin custom install python 3.11.9 ----------------------------------------------
13+
# RUN sudo apt-get update ; apt-get install -yq build-essential zlib1g-dev make libssl-dev
14+
# RUN wget -O /Python-3.11.9.tgz https://www.python.org/ftp/python/3.11.9/Python-3.11.9.tgz
15+
# WORKDIR /
16+
# RUN tar -xvzf Python-3.11.9.tgz
17+
# WORKDIR /Python-3.11.9
18+
# RUN sudo ./configure && sudo make && sudo make altinstall
19+
# RUN sudo rm /usr/bin/python3
20+
# RUN sudo ln -s /usr/local/bin/python3.11 /usr/bin/python3
21+
# RUN sudo ln -s /usr/local/bin/pip3.11 /usr/bin/pip3
22+
# ------- end section -------------------------------------
23+
24+
#
25+
# For local run, install from python3 python3-venv which is faster and the python version
26+
# is the current (e.g. for now it is 3.12.X - the lowest version still receiving bug fix),
27+
# since this container is for selenium tests not bb2 server,
28+
# so it is OK to be relaxed on python version, when doing local trouble shooting of remote
29+
# CI selenium tests, e.g. reproducing issues, comment out below section and uncomment above
30+
# python 3.11.9 custom install section.
31+
#
32+
# ------- begin quick python3 apt install -------------------------------------------------
33+
RUN apt-get update ; apt-get install -yq python3 python3-venv
34+
RUN ln -s /usr/bin/python3 /usr/local/bin/python
35+
RUN useradd -m -s /bin/bash DEV
36+
USER DEV
1737
ADD . /code
1838
WORKDIR /code
19-
# RUN python3 -m venv /tmp/venv
20-
# RUN . /tmp/venv/bin/activate
21-
# ENV PATH="/tmp/venv/bin:${PATH}"
39+
RUN python -m venv /tmp/venv
40+
RUN . /tmp/venv/bin/activate
41+
ENV PATH="/tmp/venv/bin:${PATH}"
42+
# ------- end section -------------------------------------
43+
2244
RUN pip3 install --upgrade pip
2345
RUN pip3 install selenium pytest debugpy jsonschema python-dateutil

Dockerfiles/Dockerfile.selenium-jenkins-python311-chromium

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ FROM --platform=linux/amd64 seleniarm/standalone-chromium
22

33
ENV PYTHONUNBUFFERED 1
44
USER root
5+
# custom install python3.11.9 takes time to run, but this is built once and pushed to ECR
6+
# and then used by consumer many times.
7+
# ------- begin custom install python 3.11.9 ----------------------------------------------
58
# on CI node, django db defaults to sqlite3
69
RUN sudo apt-get update ; apt-get install -yq git build-essential zlib1g-dev make libssl-dev libffi-dev libsqlite3-dev sqlite3
710
RUN wget -O /Python-3.11.9.tgz https://www.python.org/ftp/python/3.11.9/Python-3.11.9.tgz
@@ -13,3 +16,4 @@ RUN sudo rm /usr/bin/python3
1316
RUN sudo ln -s /usr/local/bin/python3.11 /usr/bin/python3
1417
RUN sudo ln -s /usr/local/bin/python3.11 /usr/bin/python
1518
RUN sudo ln -s /usr/local/bin/pip3.11 /usr/bin/pip3
19+
# ------- end section -------------------------------------

Jenkinsfiles/Jenkinsfile.cbc-run-multi-pr-checks-w-selenium-chromium

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pipeline {
101101
}
102102
steps{
103103
sh """
104-
USE_NEW_PERM_SCREEN=true pytest ./apps/integration_tests/logging_tests.py::TestLoggings::test_auth_fhir_flows_logging
104+
SELENIUM_HEADLESS=true USE_NEW_PERM_SCREEN=true pytest ./apps/integration_tests/logging_tests.py::TestLoggings::test_auth_fhir_flows_logging
105105
"""
106106
}
107107
}
@@ -113,7 +113,7 @@ pipeline {
113113
steps{
114114
sh 'echo "RUN selenium tests - user account and app management tests"'
115115
sh """
116-
pytest ./apps/integration_tests/selenium_accounts_tests.py::TestUserAndAppMgmt::testAccountAndAppMgmt
116+
SELENIUM_HEADLESS=true pytest ./apps/integration_tests/selenium_accounts_tests.py::TestUserAndAppMgmt::testAccountAndAppMgmt
117117
"""
118118
}
119119
}
@@ -133,7 +133,7 @@ pipeline {
133133
steps{
134134
sh 'echo "RUN selenium tests - testclient based authorization flow tests and data flow tests"'
135135
sh """
136-
USE_NEW_PERM_SCREEN=true pytest ./apps/integration_tests/selenium_tests.py
136+
SELENIUM_HEADLESS=true USE_NEW_PERM_SCREEN=true pytest ./apps/integration_tests/selenium_tests.py
137137
"""
138138
}
139139
}

apps/integration_tests/selenium_generic.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from selenium.webdriver.support import expected_conditions as EC
1010
from selenium.webdriver.support.wait import WebDriverWait
1111
from selenium.webdriver.common.keys import Keys
12-
# from selenium.webdriver.chrome.service import Service
12+
from selenium.webdriver.chrome.service import Service
1313
from .common_utils import extract_href_from_html, extract_last_part_of_url
1414

1515
from .selenium_cases import (
@@ -51,10 +51,11 @@ def setup_method(self, method):
5151
else:
5252
print("driver_ready={}".format(SeleniumGenericTests.driver_ready))
5353

54+
self.headless_mode = os.getenv('SELENIUM_HEADLESS', "False")
5455
self.hostname_url = os.environ['HOSTNAME_URL']
5556
self.use_mslsx = os.environ['USE_MSLSX']
5657
self.login_seq = SEQ_LOGIN_MSLSX if self.use_mslsx == 'true' else SEQ_LOGIN_SLSX
57-
print("use_mslsx={}, hostname_url={}".format(self.use_mslsx, self.hostname_url))
58+
print("use_mslsx={}, hostname_url={}, selenium_headless={}".format(self.use_mslsx, self.hostname_url, self.headless_mode))
5859

5960
opt = webdriver.ChromeOptions()
6061
opt.add_argument("--disable-dev-shm-usage")
@@ -69,15 +70,16 @@ def setup_method(self, method):
6970
opt.add_argument("--whitelisted-ips=''")
7071
# keep the headless setup here in case we need it on CI context
7172
# note: in headless mode we need to set window size
72-
# opt.add_argument("--window-size=1920,1080")
73-
# opt.add_argument("--headless")
74-
# driver init goes with headless
75-
# ser = Service('/usr/bin/chromedriver')
76-
# self.driver = webdriver.Chrome(service=ser, options=opt)
77-
78-
# selenium grid
79-
self.driver = webdriver.Remote(
80-
command_executor='http://chrome:4444/wd/hub', options=opt)
73+
if self.headless_mode.lower() == 'true':
74+
opt.add_argument("--window-size=1920,1080")
75+
opt.add_argument("--headless")
76+
ser = Service('/usr/bin/chromedriver')
77+
self.driver = webdriver.Chrome(service=ser, options=opt)
78+
else:
79+
# selenium hub
80+
# currently not working on CI context, so always use headless on CI
81+
self.driver = webdriver.Remote(
82+
command_executor='http://chrome:4444/wd/hub', options=opt)
8183

8284
self.actions = {
8385
Action.LOAD_PAGE: self._load_page,

docker-compose/run_selenium_tests_remote.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ display_usage() {
2626
echo
2727
echo "-h Print this Help."
2828
echo "-p Test for newer permissions screen. Defaults to older screen."
29+
echo "-l Selenium run in headless mode."
2930
echo
3031
echo "Examples:"
3132
echo
@@ -54,15 +55,22 @@ export SERVICE_NAME="selenium-tests-remote"
5455
export TESTS_LIST="./apps/integration_tests/selenium_tests.py ./apps/integration_tests/selenium_spanish_tests.py"
5556
# BB2 service end point default (SBX)
5657
export HOSTNAME_URL="https://sandbox.bluebutton.cms.gov/"
58+
# selenium headless
59+
export SELENIUM_HEADLESS=false
60+
# Show test actions on std out : pytest -s
61+
PYTEST_SHOW_TRACE_OPT=''
5762

58-
59-
while getopts "hp" option; do
63+
while getopts "hplt" option; do
6064
case $option in
6165
h)
6266
display_usage;
6367
exit;;
6468
p)
6569
export USE_NEW_PERM_SCREEN=true;;
70+
l)
71+
export SELENIUM_HEADLESS=true;;
72+
t)
73+
export PYTEST_SHOW_TRACE_OPT='-s';;
6674
\?)
6775
display_usage;
6876
exit;;
@@ -103,13 +111,14 @@ SYSTEM=$(uname -s)
103111

104112
echo "USE_NEW_PERM_SCREEN=" ${USE_NEW_PERM_SCREEN}
105113
echo "BB2 Server URL=" ${HOSTNAME_URL}
114+
echo "Selenium headless mode=" ${SELENIUM_HEADLESS}
106115

107116
export USE_NEW_PERM_SCREEN
108117
export USE_MSLSX=false
109118

110119
# stop all before run selenium remote tests
111120
docker-compose -f docker-compose.selenium.remote.yml down --remove-orphans
112-
docker-compose -f docker-compose.selenium.remote.yml run selenium-remote-tests bash -c "pytest ${TESTS_LIST}"
121+
docker-compose -f docker-compose.selenium.remote.yml run selenium-remote-tests bash -c "SELENIUM_HEADLESS=${SELENIUM_HEADLESS} pytest ${PYTEST_SHOW_TRACE_OPT} ${TESTS_LIST}"
113122

114123
# Stop containers after use
115124
echo_msg

0 commit comments

Comments
 (0)