Skip to content

Commit 76c6d99

Browse files
authored
Merge pull request #1225 from topcoder-platform/feature/test-automation
[DEV] Smoke Test Automation
2 parents 34a30b0 + 945245b commit 76c6d99

28 files changed

+3820
-9
lines changed

.circleci/config.yml

Lines changed: 95 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,44 @@
1-
version: 2
1+
version: 2.1
2+
parameters:
3+
run_basedeployment:
4+
default: true
5+
type: boolean
6+
run_smoketesting:
7+
default: false
8+
type: boolean
9+
210
defaults: &defaults
311
docker:
412
- image: circleci/python:2.7-stretch-browsers
13+
14+
test_defaults: &test_defaults
15+
docker:
16+
- image: docker:17.11.0-ce-git
17+
518
install_dependency: &install_dependency
619
name: Installation of build and deployment dependencies.
720
command: |
821
sudo apt install jq
922
sudo pip install awscli --upgrade
1023
sudo pip install docker-compose
24+
25+
install_test_dependency: &install_test_dependency
26+
name: Installation of build and deployment dependencies.
27+
command: |
28+
apk update
29+
apk add --no-cache bash openssl curl
30+
apk upgrade
31+
apk add --no-cache jq py-pip sudo
32+
sudo pip install awscli --upgrade
33+
1134
install_deploysuite: &install_deploysuite
1235
name: Installation of install_deploysuite.
1336
command: |
1437
git clone --branch v1.4 https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript
1538
cp ./../buildscript/master_deploy.sh .
1639
cp ./../buildscript/buildenv.sh .
1740
cp ./../buildscript/awsconfiguration.sh .
41+
1842
restore_cache_settings_for_build: &restore_cache_settings_for_build
1943
key: docker-node-modules-28-10-2020-{{ checksum "package-lock.json" }}
2044

@@ -35,7 +59,7 @@ builddeploy_steps: &builddeploy_steps
3559
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-${APPNAME}-buildvar
3660
echo awsenvconf >.dockerignore
3761
echo buildenvvar >>.dockerignore
38-
- run:
62+
- run:
3963
name: "building image"
4064
command: |
4165
source buildenvvar
@@ -48,7 +72,35 @@ builddeploy_steps: &builddeploy_steps
4872
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-${APPNAME}-deployvar
4973
source buildenvvar
5074
./master_deploy.sh -d ECS -e $DEPLOY_ENV -t latest -s ${LOGICAL_ENV}-global-appvar,${LOGICAL_ENV}-${APPNAME}-appvar -i ${APPNAME}
75+
curl --request POST \
76+
--url https://circleci.com/api/v2/project/github/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/pipeline \
77+
--header "Circle-Token: ${CIRCLE_TOKEN}" \
78+
--header 'content-type: application/json' \
79+
--data '{"branch":"'"$CIRCLE_BRANCH"'","parameters":{"run_smoketesting":true, "run_basedeployment": false}}'
5180
81+
# Automated Smoke Testing
82+
smoke_testing: &smoke_testing
83+
# Initialization.
84+
- checkout
85+
- setup_remote_docker
86+
- run: *install_test_dependency
87+
- run: *install_deploysuite
88+
# Restoration of node_modules from cache.
89+
- restore_cache: *restore_cache_settings_for_build
90+
- run:
91+
name: "configuring environment"
92+
command: |
93+
./awsconfiguration.sh $DEPLOY_ENV
94+
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-${APPNAME}-buildvar
95+
- run:
96+
name: "Run automation"
97+
no_output_timeout: 20m
98+
command: |
99+
source awsenvconf
100+
source buildenvvar
101+
./test-automation/smoketest.sh
102+
- store_artifacts:
103+
path: ./test-automation/test-results
52104

53105
jobs:
54106
# Build & Deploy against development backend
@@ -59,34 +111,69 @@ jobs:
59111
LOGICAL_ENV: "dev"
60112
NODE_ENV: "development"
61113
BABEL_ENV: "development"
62-
APPNAME: "challenge-engine-ui"
114+
APPNAME: "challenge-engine-ui"
63115
steps: *builddeploy_steps
64116

65117
"build-prod":
66118
<<: *defaults
67119
environment:
68120
DEPLOY_ENV: "PROD"
69-
LOGICAL_ENV: "prod"
121+
LOGICAL_ENV: "prod"
70122
NODE_ENV: "production"
71123
BABEL_ENV: "production"
72-
APPNAME: "challenge-engine-ui"
124+
APPNAME: "challenge-engine-ui"
73125
steps: *builddeploy_steps
74126

127+
"smoke-testing-dev":
128+
<<: *test_defaults
129+
environment:
130+
DEPLOY_ENV: "DEV"
131+
LOGICAL_ENV: "dev"
132+
APPNAME: "challenge-engine-ui"
133+
steps: *smoke_testing
134+
135+
"smoke-testing-prod":
136+
<<: *test_defaults
137+
environment:
138+
DEPLOY_ENV: "PROD"
139+
LOGICAL_ENV: "prod"
140+
APPNAME: "challenge-engine-ui"
141+
steps: *smoke_testing
142+
75143
workflows:
76144
version: 2
77145
build:
146+
when: << pipeline.parameters.run_basedeployment >>
78147
jobs:
79148
# Development builds are executed on "develop" branch only.
80149
- "build-dev":
81150
context : org-global
82-
filters:
151+
filters: &filters-dev
83152
branches:
84-
only: ['develop', 'feature/bug-bash-july']
153+
only: ['develop', 'feature/bug-bash-july', 'feature/test-automation']
85154

86155
# Production builds are exectuted only on tagged commits to the
87156
# master branch.
88157
- "build-prod":
89158
context : org-global
90-
filters:
159+
filters: &filters-prod
91160
branches:
92161
only: master
162+
163+
Smoke Testing:
164+
when: << pipeline.parameters.run_smoketesting >>
165+
jobs:
166+
- Hold [Smoke-Testing]:
167+
type: approval
168+
- smoke-testing-dev:
169+
context : org-global
170+
requires:
171+
- Hold [Smoke-Testing]
172+
filters:
173+
<<: *filters-dev
174+
- smoke-testing-prod:
175+
context : org-global
176+
requires:
177+
- Hold [Smoke-Testing]
178+
filters:
179+
<<: *filters-prod

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
33

44
# dependencies
5-
/node_modules
5+
node_modules
66
/.pnp
77
.pnp.js
88
.idea
@@ -27,3 +27,7 @@ yarn-error.log*
2727
*.env
2828

2929
*.vscode
30+
31+
# e2e test case
32+
test-automation/temp
33+
test-automation/test-results

test-automation/Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM node:10.17.0-stretch
2+
RUN apt update
3+
RUN apt install sudo
4+
RUN sudo apt-get update; sudo apt-get install -y openjdk-8-jre openjdk-8-jre-headless openjdk-8-jdk openjdk-8-jdk-headless;
5+
RUN curl --silent --show-error --location --fail --retry 3 --output /tmp/google-chrome-stable_current_amd64.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
6+
&& (sudo dpkg -i /tmp/google-chrome-stable_current_amd64.deb || sudo apt-get -fy install) \
7+
&& rm -rf /tmp/google-chrome-stable_current_amd64.deb \
8+
&& sudo sed -i 's|HERE/chrome"|HERE/chrome" --disable-setuid-sandbox --no-sandbox|g' \
9+
"/opt/google/chrome/google-chrome" \
10+
&& google-chrome --version
11+
RUN export CHROMEDRIVER_RELEASE=$(curl --location --fail --retry 3 http://chromedriver.storage.googleapis.com/LATEST_RELEASE) \
12+
&& curl --silent --show-error --location --fail --retry 3 --output /tmp/chromedriver_linux64.zip "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_RELEASE/chromedriver_linux64.zip" \
13+
&& cd /tmp \
14+
&& unzip chromedriver_linux64.zip \
15+
&& rm -rf chromedriver_linux64.zip \
16+
&& sudo mv chromedriver /usr/local/bin/chromedriver \
17+
&& sudo chmod +x /usr/local/bin/chromedriver \
18+
&& chromedriver --version
19+
RUN sudo apt-get install -y libgconf-2-4
20+
RUN sudo apt-get install -y xvfb
21+
RUN sudo apt-get install -y jq
22+
ENV DISPLAY :99
23+
RUN printf '#!/bin/sh\nXvfb :99 -screen 0 1280x1024x24 &\nexec "$@"\n' > /tmp/entrypoint \
24+
&& chmod +x /tmp/entrypoint \
25+
&& sudo mv /tmp/entrypoint /docker-entrypoint.sh
26+
27+
COPY . /test-automation
28+
WORKDIR /test-automation
29+
RUN npm install
30+
RUN ./node_modules/.bin/webdriver-manager update --versions.chrome=="$(google-chrome -version)"
31+
ENTRYPOINT ["/docker-entrypoint.sh"]
32+
CMD ["/bin/sh"]

test-automation/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Work Manager App - E2E Tests
2+
3+
#### Software Required
4+
5+
* Nodejs v15.4.0
6+
* Chrome Browser
7+
8+
#### Installation
9+
10+
- Install Dependencies using command
11+
`npm install`
12+
13+
- To run tests
14+
15+
`cd test-automation`
16+
17+
`npm run test`
18+
19+
- Test results are generated in `test-results/` folder
20+
21+
```
22+
HTML report - TestResult.html
23+
Junit report - junitresults-WorkManagerCreateChallengeTests.xml and junitresults-WorkMangerDashboardPageTests.xml
24+
```
25+
26+
- To view junit reports into html, install xunit-viewer
27+
`npm i -g xunit-viewer`
28+
29+
- HTML report from Junit reports can be generated using this command
30+
`xunit-viewer --results=test-results/ --output=./result.html`
31+
32+
As of now, the tests are running in headless mode. To view the actual chrome browser running the tests, you can remove `--headless` option from `chromeOptions.args` in `config.ts`
33+
34+
#### Test Data:
35+
36+
- Test data are located in `/test-data/test-data.json` file.
37+
38+
#### Configuration details:
39+
40+
- `config.json` holds the data level configuration, like user credentials etc
41+
- `conf.ts` holds the application configuration, like jasmine reporters to be configured, specs to be run etc.

test-automation/conf.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import reporters = require('jasmine-reporters');
2+
import HtmlReporter = require('protractor-beautiful-reporter');
3+
import { BrowserHelper } from 'topcoder-testing-lib';
4+
5+
declare global {
6+
namespace NodeJS {
7+
interface IGlobal {
8+
document: Document;
9+
window: Window;
10+
navigator: Navigator;
11+
forgotPasswordMailListener: any;
12+
registrationMailListener: any;
13+
}
14+
}
15+
}
16+
17+
exports.config = {
18+
setupFilesAfterEnv: ['./jest.setup.js'],
19+
20+
// Capabilities to be passed to the webdriver instance.
21+
capabilities: {
22+
browserName: 'chrome',
23+
chromeOptions: {
24+
args: [
25+
'--headless',
26+
'--disable-gpu',
27+
'--no-sandbox',
28+
'--window-size=1325x744',
29+
'disable-infobars'
30+
],
31+
'excludeSwitches': ['enable-automation'],
32+
prefs: {
33+
'credentials_enable_service': false,
34+
'profile': {
35+
'password_manager_enabled': false
36+
}
37+
}
38+
},
39+
},
40+
41+
directConnect: true,
42+
43+
// Framework to use. Jasmine is recommended.
44+
framework: 'jasmine2',
45+
46+
specs: [
47+
'../temp/test-suites/dashboard-flow/dashboard.spec.js',
48+
'../temp/test-suites/create-challenge-flow/create-challenge.spec.js',
49+
],
50+
51+
// Options to be passed to Jasmine.
52+
jasmineNodeOpts: {
53+
defaultTimeoutInterval: 1200000, // 20 minutes
54+
isVerbose: true,
55+
showColors: true,
56+
},
57+
58+
onPrepare: () => {
59+
BrowserHelper.maximize();
60+
const junitReporter = new reporters.JUnitXmlReporter({
61+
consolidateAll: false,
62+
savePath: 'test-results',
63+
});
64+
jasmine.getEnv().addReporter(junitReporter);
65+
jasmine.getEnv().addReporter(
66+
new HtmlReporter({
67+
baseDirectory: 'test-results',
68+
docName: 'TestResult.html', // Change html report file name
69+
docTitle: 'Test Automation Execution Report', // Add title for the html report
70+
gatherBrowserLogs: true, // Store Browser logs
71+
jsonsSubfolder: 'jsons', // JSONs Subfolder
72+
preserveDirectory: false, // Preserve base directory
73+
screenshotsSubfolder: 'screenshots',
74+
takeScreenShotsForSkippedSpecs: true, // Screenshots for skipped test cases
75+
takeScreenShotsOnlyForFailedSpecs: true, // Screenshots only for failed test cases
76+
}).getJasmine2Reporter()
77+
);
78+
},
79+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"Timeout": {
3+
"FieldVisibility": 15000,
4+
"ElementVisibility": 15000,
5+
"ElementInvisibility": 15000,
6+
"ElementPresence": 15000,
7+
"ElementClickable": 15000,
8+
"PageLoad": 300000,
9+
"ActiveChallengeTimeout": 300000
10+
},
11+
12+
"LoggerErrors": {
13+
"ElementVisibility": "Element did not display within timeout",
14+
"ElementInvisibility": "Element did not become invisible within timeout",
15+
"ElementPresence": "Element was not present within timeout",
16+
"ElementClickable": "Element was not clickable within timeout",
17+
"PageLoad": "Page did not load within timeout"
18+
}
19+
}

test-automation/config/config.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"copilotRole": {
3+
"email": "[email protected]",
4+
"password": "appirio123",
5+
"handle": "TCConnCopilot"
6+
},
7+
"copilotManagerRole": {
8+
"email": "[email protected]",
9+
"password": "appirio123",
10+
"handle": "TCConCopilotMgr"
11+
},
12+
"givenUrl": "https://challenges.topcoder-dev.com/",
13+
"challengeUrl": "https://challenges.topcoder-dev.com/projects/16573/challenges",
14+
"logoutUrl": "https://accounts-auth0.topcoder-dev.com/?logout=true&retUrl=https://connect.topcoder-dev.com",
15+
}

test-automation/logger/logger.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { createLogger, transports } from "winston";
2+
export const logger = createLogger({
3+
transports: [new transports.Console()]
4+
});

0 commit comments

Comments
 (0)