Skip to content

Commit 0f13799

Browse files
committed
make CI selenium tests testing again.
1 parent b19596a commit 0f13799

File tree

5 files changed

+184
-9
lines changed

5 files changed

+184
-9
lines changed

Dockerfile.selenium

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ FROM seleniarm/standalone-chromium
22

33
ENV PYTHONUNBUFFERED 1
44
USER root
5-
#RUN apt-get update ; apt-get install -yq git curl libpq-dev libffi-dev
65
RUN apt-get update ; apt-get install -yq python3 python3-venv
76
RUN ln -s /usr/bin/python3 /usr/local/bin/python
87
RUN ln -s /usr/bin/chromedriver /usr/local/bin/chromedriver
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM seleniarm/standalone-chromium
2+
3+
ENV PYTHONUNBUFFERED 1
4+
USER root
5+
6+
RUN apt-get update ; apt-get install -yq python3 python3-venv
7+
RUN ln -s /usr/bin/python3 /usr/local/bin/python
8+
RUN ln -s /usr/bin/chromedriver /usr/local/bin/chromedriver
9+
RUN useradd -m -s /bin/bash DEV
10+
11+
USER DEV
12+
13+
ADD . /code
14+
WORKDIR /code
15+
RUN python -m venv /tmp/venv
16+
RUN . /tmp/venv/bin/activate
17+
ENV PATH="/tmp/venv/bin:${PATH}"
18+
RUN pip3 install --upgrade pip
19+
RUN pip3 install selenium pytest debugpy jsonschema python-dateutil
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
pipeline {
2+
agent {
3+
kubernetes {
4+
defaultContainer "bb2-cbc-build-selenium-python311-chronium"
5+
yamlFile "Jenkinsfiles/cbc-pod-deployment-config-w-selenium-p311-chronium.yaml"
6+
}
7+
}
8+
9+
environment {
10+
USE_MSLSX = true
11+
DJANGO_LOG_JSON_FORMAT_PRETTY = true
12+
DJANGO_SETTINGS_MODULE = "hhs_oauth_server.settings.logging_it"
13+
OAUTHLIB_INSECURE_TRANSPORT = true
14+
DJANGO_SECURE_SESSION = false
15+
DJANGO_FHIR_CERTSTORE = "./certstore"
16+
DJANGO_MEDICARE_SLSX_REDIRECT_URI="http://localhost:8000/mymedicare/sls-callback"
17+
DJANGO_MEDICARE_SLSX_LOGIN_URI="https://test.medicare.gov/sso/authorize?client_id=bb2api"
18+
DJANGO_SLSX_HEALTH_CHECK_ENDPOINT="https://test.accounts.cms.gov/health"
19+
DJANGO_SLSX_TOKEN_ENDPOINT="https://test.medicare.gov/sso/session"
20+
DJANGO_SLSX_SIGNOUT_ENDPOINT="https://test.medicare.gov/sso/signout"
21+
DJANGO_SLSX_USERINFO_ENDPOINT="https://test.accounts.cms.gov/v1/users"
22+
DJANGO_SLSX_CLIENT_ID = credentials("bb2-selenium-tests-slsx-client-id")
23+
DJANGO_SLSX_CLIENT_SECRET = credentials("bb2-selenium-tests-slsx-client-secret")
24+
DJANGO_USER_ID_ITERATIONS = credentials("bb2-integration-tests-bfd-iterations")
25+
DJANGO_USER_ID_SALT = credentials("bb2-integration-tests-bfd-salt")
26+
FHIR_CERT = credentials("bb2-integration-tests-bfd-cert")
27+
FHIR_KEY = credentials("bb2-integration-tests-bfd-key")
28+
FHIR_URL = "${params.FHIR_URL}"
29+
HOSTNAME_URL = "http://localhost:8000"
30+
}
31+
32+
parameters {
33+
string(
34+
name: 'FHIR_URL',
35+
defaultValue: "https://prod-sbx.bfd.cms.gov",
36+
description: 'The default FHIR URL for the back end BFD service.'
37+
)
38+
booleanParam(
39+
name: 'RUN_SELENIUM_TESTS',
40+
defaultValue: false,
41+
description: 'Set to true, selenium tests will be run as part of integration tests'
42+
)
43+
}
44+
45+
stages {
46+
stage("SETUP FHIR cert and key") {
47+
steps {
48+
writeFile(file: "${env.DJANGO_FHIR_CERTSTORE}/certstore/ca.cert.pem", text: readFile(env.FHIR_CERT))
49+
writeFile(file: "${env.DJANGO_FHIR_CERTSTORE}/certstore/ca.key.nocrypt.pem", text: readFile(env.FHIR_KEY))
50+
}
51+
}
52+
53+
stage("INSTALL Python Packages") {
54+
steps {
55+
sh """
56+
python -m venv venv
57+
. venv/bin/activate
58+
python -m pip install --upgrade pip setuptools wheel cryptography
59+
make reqs-install-dev
60+
"""
61+
}
62+
}
63+
64+
stage("CHECK Flake8 Python Lint/Style") {
65+
steps{
66+
sh """
67+
. venv/bin/activate
68+
flake8
69+
"""
70+
}
71+
}
72+
73+
stage("RUN Django Unit Tests") {
74+
steps{
75+
sh """
76+
. venv/bin/activate
77+
python runtests.py
78+
"""
79+
}
80+
}
81+
82+
stage("START BB2 server in background") {
83+
when {
84+
expression { params.RUN_SELENIUM_TESTS == true }
85+
}
86+
steps{
87+
sh """
88+
. venv/bin/activate
89+
mkdir ./docker-compose/tmp/
90+
python manage.py migrate && python manage.py create_admin_groups && python manage.py loaddata scopes.json && python manage.py create_blue_button_scopes && python manage.py create_test_user_and_application && python manage.py create_user_identification_label_selection && python manage.py create_test_feature_switches && (if [ ! -d 'bluebutton-css' ] ; then git clone https://github.com/CMSgov/bluebutton-css.git ; else echo 'CSS already installed.' ; fi) && echo 'starting bb2...' && (export DJANGO_SETTINGS_MODULE=hhs_oauth_server.settings.logging_it && python manage.py runserver 0.0.0.0:8000 > ./docker-compose/tmp/bb2_email_to_stdout.log 2>&1 &)
91+
"""
92+
}
93+
}
94+
95+
stage("RUN logging integration tests") {
96+
when {
97+
expression { params.RUN_SELENIUM_TESTS == true }
98+
}
99+
steps{
100+
sh """
101+
. venv/bin/activate
102+
USE_NEW_PERM_SCREEN=true pytest ./apps/integration_tests/logging_tests.py::TestLoggings::test_auth_fhir_flows_logging
103+
"""
104+
}
105+
}
106+
107+
stage("RUN selenium user and apps management tests") {
108+
when {
109+
expression { params.RUN_SELENIUM_TESTS == true }
110+
}
111+
steps{
112+
sh 'echo "RUN selenium tests - user account and app management tests"'
113+
sh """
114+
. venv/bin/activate
115+
pytest ./apps/integration_tests/selenium_accounts_tests.py::TestUserAndAppMgmt::testAccountAndAppMgmt
116+
"""
117+
}
118+
}
119+
120+
stage("RUN integration tests") {
121+
steps{
122+
sh """
123+
. venv/bin/activate
124+
python runtests.py --integration apps.integration_tests.integration_test_fhir_resources.IntegrationTestFhirApiResources
125+
"""
126+
}
127+
}
128+
129+
stage("RUN selenium tests") {
130+
when {
131+
expression { params.RUN_SELENIUM_TESTS == true }
132+
}
133+
steps{
134+
sh 'echo "RUN selenium tests - testclient based authorization flow tests and data flow tests"'
135+
sh """
136+
. venv/bin/activate
137+
USE_NEW_PERM_SCREEN=true pytest ./apps/integration_tests/selenium_tests.py
138+
"""
139+
}
140+
}
141+
142+
}
143+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: Pod
3+
spec:
4+
containers:
5+
- name: bb2-cbc-build-selenium-python311-chronium
6+
image: "public.ecr.aws/f5g8o1y9/bb2-cbc-build-selenium-python311-chronium:latest"
7+
tty: true
8+
command: ["tail", "-f"]
9+
imagePullPolicy: Always
10+
nodeSelector:
11+
Agents: true

apps/integration_tests/selenium_generic.py

Lines changed: 11 additions & 8 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 (
@@ -67,14 +67,17 @@ def setup_method(self, method):
6767
opt.add_argument("--enable-javascript")
6868
opt.add_argument('--allow-insecure-localhost')
6969
opt.add_argument("--whitelisted-ips=''")
70-
opt.add_argument("--window-size=1920,1080")
71-
opt.add_argument("--headless")
70+
# keep the headless setup here in case we need it on CI context
71+
# 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)
7277

73-
ser = Service('/usr/local/bin/chromedriver')
74-
self.driver = webdriver.Chrome(service=ser, options=opt)
75-
76-
# self.driver = webdriver.Remote(
77-
# command_executor='http://chrome:4444/wd/hub', options=opt)
78+
# selenium grid
79+
self.driver = webdriver.Remote(
80+
command_executor='http://chrome:4444/wd/hub', options=opt)
7881

7982
self.actions = {
8083
Action.LOAD_PAGE: self._load_page,

0 commit comments

Comments
 (0)