Skip to content

Commit d541598

Browse files
author
JAMES FUQIAN
committed
add selenium tests.
1 parent acbbdf0 commit d541598

9 files changed

Lines changed: 10353 additions & 17 deletions

File tree

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ copy server/src/configs/sample.config.ts -> server/src/configs/config.ts
8686
yarn --cwd server install
8787
yarn --cwd server test
8888

89+
## Run selenium tests in docker
90+
91+
Configure the remote target BB2 instance where the tested app is registered (as described above "Running the Back-end & Front-end")
92+
93+
Go to local repo base directory, from there run:
94+
95+
docker-compose --profile tests up --abort-on-container-exit
96+
97+
Note: --abort-on-container-exit will abort client and server containers when selenium tests ends
98+
8999
## Error Responses and handling:
90100

91101
[See ErrorResponses.md](./ErrorResponses.md)

client/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:14.17.1
1+
FROM node:16.17.1
22

33
LABEL version="1.0"
44
LABEL description="Demo of a Medicare claims data sample app"

client/package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
"@types/react-dom": "^17.0.0",
1111
"axios": "^0.21.2",
1212
"http-proxy-middleware": "^1.3.1",
13-
"react": "^17.0.2",
14-
"react-dom": "^17.0.2",
15-
"react-router-dom": "^5.2.0",
16-
"react-scripts": "4.0.3",
17-
"sass": "^1.49.7",
18-
"typescript": "^4.1.2",
19-
"web-vitals": "^1.0.1"
13+
"react": "^18.2.0",
14+
"react-dom": "^18.2.0",
15+
"react-router-dom": "^6.4.2",
16+
"react-scripts": "5.0.1",
17+
"node-sass": "7.0.3",
18+
"typescript": "^4.8.4",
19+
"web-vitals": "^3.0.3"
2020
},
2121
"scripts": {
22-
"start": "REACT_APP_CTX=docker react-scripts start",
23-
"start-native": "REACT_APP_CTX=native react-scripts start",
22+
"start": "DANGEROUSLY_DISABLE_HOST_CHECK=true REACT_APP_CTX=docker react-scripts start",
23+
"start-native": "NODE_OPTIONS=--openssl-legacy-provider REACT_APP_CTX=native react-scripts start",
2424
"lint": "eslint --ext .ts --ext .js --ext .tsx .",
2525
"build": "react-scripts build",
2626
"test": "react-scripts test",
@@ -45,11 +45,11 @@
4545
]
4646
},
4747
"devDependencies": {
48-
"@testing-library/jest-dom": "^5.16.2",
49-
"@testing-library/react": "^12.1.3",
48+
"@testing-library/jest-dom": "^5.16.5",
49+
"@testing-library/react": "^13.4.0",
5050
"@testing-library/user-event": "^13.5.0",
51-
"@types/jest": "^27.4.0",
52-
"@types/react-router-dom": "^5.1.7",
51+
"@types/jest": "^29.1.2",
52+
"@types/react-router-dom": "^5.3.3",
5353
"@typescript-eslint/eslint-plugin": "^5.12.0",
5454
"@typescript-eslint/parser": "^5.12.0",
5555
"eslint-config-react-app": "^7.0.0",

client/src/components/patientData.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function PatientData() {
3434
<div>
3535
<h4>{ header }</h4>
3636
</div>
37-
<Button variation="primary" onClick={goAuthorize}>Authorize</Button>
37+
<Button id="auth_btn" variation="primary" onClick={goAuthorize}>Authorize</Button>
3838
</div>
3939
</div>
4040
);

client/yarn.lock

Lines changed: 10220 additions & 0 deletions
Large diffs are not rendered by default.

docker-compose.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,21 @@ services:
1313
context: ./client
1414
dockerfile: ./Dockerfile
1515
ports:
16-
- "3000:3000"
16+
- "3000:3000"
17+
selenium-tests:
18+
build:
19+
context: ./selenium_tests
20+
dockerfile: ./Dockerfile
21+
command: pytest ./src/test_node_sample.py
22+
depends_on:
23+
- chrome
24+
- server
25+
- client
26+
profiles:
27+
- tests
28+
chrome:
29+
image: selenium/standalone-chrome-debug
30+
hostname: chrome
31+
ports:
32+
- "4444:4444"
33+
- "5900:5900"

selenium_tests/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM selenium/standalone-chrome-debug
2+
3+
ENV PYTHONUNBUFFERED 1
4+
USER root
5+
RUN apt-get update && apt-get install -yq python3.8 python3-pip
6+
RUN mkdir /code
7+
ADD . /code/
8+
WORKDIR /code
9+
RUN ln -s /usr/bin/python3 /usr/local/bin/python
10+
RUN pip3 install --upgrade pip
11+
RUN pip3 install selenium pytest
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Generated by Selenium IDE
2+
import pytest
3+
import time
4+
import json
5+
from selenium import webdriver
6+
from selenium.webdriver.common.by import By
7+
from selenium.webdriver.support import expected_conditions as EC
8+
from selenium.webdriver.common.action_chains import ActionChains
9+
from selenium.webdriver.support import expected_conditions
10+
from selenium.webdriver.support.wait import WebDriverWait
11+
from selenium.webdriver.common.keys import Keys
12+
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
13+
14+
15+
class TestNodeSampleApp():
16+
def setup_method(self, method):
17+
print("Waiting 20 sec. ======================================>>>>>>>>>")
18+
time.sleep(20)
19+
print("Waited 20 sec. <<<<<<<<<<<<<<<================================")
20+
21+
opt = webdriver.ChromeOptions()
22+
opt.add_argument("--disable-dev-shm-usage")
23+
opt.add_argument("--disable-web-security")
24+
opt.add_argument("--allow-running-insecure-content")
25+
opt.add_argument("--no-sandbox")
26+
opt.add_argument("--disable-setuid-sandbox")
27+
opt.add_argument("--disable-webgl")
28+
opt.add_argument("--disable-popup-blocking")
29+
opt.add_argument("--enable-javascript")
30+
opt.add_argument('--allow-insecure-localhost')
31+
opt.add_argument('--window-size=1920,1080')
32+
opt.add_argument("--whitelisted-ips=''")
33+
34+
# opt.add_argument('--headless')
35+
# self.driver = webdriver.Chrome(options=opt)
36+
print("Register remote debug driver. ***************************")
37+
self.driver = webdriver.Remote(
38+
command_executor='http://chrome:4444/wd/hub', options=opt)
39+
40+
def teardown_method(self, method):
41+
self.driver.quit()
42+
43+
def _find_and_click(self, timeout_sec, by, by_expr, **kwargs):
44+
elem = WebDriverWait(self.driver, timeout_sec).until(EC.visibility_of_element_located((by, by_expr)))
45+
assert elem is not None
46+
elem.click()
47+
return elem
48+
49+
def _find_and_sendkey(self, timeout_sec, by, by_expr, txt, **kwargs):
50+
elem = WebDriverWait(self.driver, timeout_sec).until(EC.visibility_of_element_located((by, by_expr)))
51+
assert elem is not None
52+
elem.send_keys(txt)
53+
return elem
54+
55+
def test_node_sample_app(self):
56+
print("In test_node_sample_app(): about to connect to FE at http://client:3000 ...")
57+
self.driver.get("http://client:3000/")
58+
print("Connected !")
59+
print("Set window size to 1500 X 1800 ++++++++++++++")
60+
self.driver.set_window_size(1500, 1800)
61+
print("Locate button 'Authorize' and click ===================")
62+
# 3 | click | id=auth_btn |
63+
elem = self._find_and_click(30, By.ID, "auth_btn")
64+
# self._find_and_click(30, By.ID, "auth_btn")
65+
print("Wait 10 sec for the bene login page to show up ===================")
66+
time.sleep(10)
67+
print("Locate user name input and type user name ===================")
68+
self._find_and_sendkey(30, By.ID, "username-textbox", "BBUser10000")
69+
print("Locate password input and type password ===================")
70+
self._find_and_sendkey(30, By.ID, "password-textbox", "PW10000!")
71+
print("Locate login button and click ===================")
72+
self._find_and_click(30, By.ID, "login-button")
73+
print("Wait 10 sec for access grant page to show up ===================")
74+
time.sleep(10)
75+
print("Locate Approve button and click ===================")
76+
self._find_and_click(30, By.ID, "approve")
77+
print("Now should be able to see the Claims page ===================")
78+

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"build": "./node_modules/.bin/ts-node build.ts",
66
"lint": "eslint --fix --ext .ts --ext .tsx .",
77
"start": "node -r module-alias/register ./dist --env=production",
8-
"start:debug": "node --inspect=0.0.0.0:9229 ./node_modules/.bin/ts-node -r tsconfig-paths/register ./src",
8+
"start:debug": "DANGEROUSLY_DISABLE_HOST_CHECK=true node --inspect=0.0.0.0:9229 ./node_modules/.bin/ts-node -r tsconfig-paths/register ./src",
99
"start:dev": "nodemon",
1010
"test": "jest --coverage"
1111
},

0 commit comments

Comments
 (0)