Skip to content

[DEV] Smoke Test Automation #1225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 95 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
version: 2
version: 2.1
parameters:
run_basedeployment:
default: true
type: boolean
run_smoketesting:
default: false
type: boolean

defaults: &defaults
docker:
- image: circleci/python:2.7-stretch-browsers

test_defaults: &test_defaults
docker:
- image: docker:17.11.0-ce-git

install_dependency: &install_dependency
name: Installation of build and deployment dependencies.
command: |
sudo apt install jq
sudo pip install awscli --upgrade
sudo pip install docker-compose

install_test_dependency: &install_test_dependency
name: Installation of build and deployment dependencies.
command: |
apk update
apk add --no-cache bash openssl curl
apk upgrade
apk add --no-cache jq py-pip sudo
sudo pip install awscli --upgrade

install_deploysuite: &install_deploysuite
name: Installation of install_deploysuite.
command: |
git clone --branch v1.4 https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript
cp ./../buildscript/master_deploy.sh .
cp ./../buildscript/buildenv.sh .
cp ./../buildscript/awsconfiguration.sh .

restore_cache_settings_for_build: &restore_cache_settings_for_build
key: docker-node-modules-28-10-2020-{{ checksum "package-lock.json" }}

Expand All @@ -35,7 +59,7 @@ builddeploy_steps: &builddeploy_steps
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-${APPNAME}-buildvar
echo awsenvconf >.dockerignore
echo buildenvvar >>.dockerignore
- run:
- run:
name: "building image"
command: |
source buildenvvar
Expand All @@ -48,7 +72,35 @@ builddeploy_steps: &builddeploy_steps
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-${APPNAME}-deployvar
source buildenvvar
./master_deploy.sh -d ECS -e $DEPLOY_ENV -t latest -s ${LOGICAL_ENV}-global-appvar,${LOGICAL_ENV}-${APPNAME}-appvar -i ${APPNAME}
curl --request POST \
--url https://circleci.com/api/v2/project/github/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/pipeline \
--header "Circle-Token: ${CIRCLE_TOKEN}" \
--header 'content-type: application/json' \
--data '{"branch":"'"$CIRCLE_BRANCH"'","parameters":{"run_smoketesting":true, "run_basedeployment": false}}'

# Automated Smoke Testing
smoke_testing: &smoke_testing
# Initialization.
- checkout
- setup_remote_docker
- run: *install_test_dependency
- run: *install_deploysuite
# Restoration of node_modules from cache.
- restore_cache: *restore_cache_settings_for_build
- run:
name: "configuring environment"
command: |
./awsconfiguration.sh $DEPLOY_ENV
./buildenv.sh -e $DEPLOY_ENV -b ${LOGICAL_ENV}-${APPNAME}-buildvar
- run:
name: "Run automation"
no_output_timeout: 20m
command: |
source awsenvconf
source buildenvvar
./test-automation/smoketest.sh
- store_artifacts:
path: ./test-automation/test-results

jobs:
# Build & Deploy against development backend
Expand All @@ -59,34 +111,69 @@ jobs:
LOGICAL_ENV: "dev"
NODE_ENV: "development"
BABEL_ENV: "development"
APPNAME: "challenge-engine-ui"
APPNAME: "challenge-engine-ui"
steps: *builddeploy_steps

"build-prod":
<<: *defaults
environment:
DEPLOY_ENV: "PROD"
LOGICAL_ENV: "prod"
LOGICAL_ENV: "prod"
NODE_ENV: "production"
BABEL_ENV: "production"
APPNAME: "challenge-engine-ui"
APPNAME: "challenge-engine-ui"
steps: *builddeploy_steps

"smoke-testing-dev":
<<: *test_defaults
environment:
DEPLOY_ENV: "DEV"
LOGICAL_ENV: "dev"
APPNAME: "challenge-engine-ui"
steps: *smoke_testing

"smoke-testing-prod":
<<: *test_defaults
environment:
DEPLOY_ENV: "PROD"
LOGICAL_ENV: "prod"
APPNAME: "challenge-engine-ui"
steps: *smoke_testing

workflows:
version: 2
build:
when: << pipeline.parameters.run_basedeployment >>
jobs:
# Development builds are executed on "develop" branch only.
- "build-dev":
context : org-global
filters:
filters: &filters-dev
branches:
only: ['develop', 'feature/bug-bash-july']
only: ['develop', 'feature/bug-bash-july', 'feature/test-automation']

# Production builds are exectuted only on tagged commits to the
# master branch.
- "build-prod":
context : org-global
filters:
filters: &filters-prod
branches:
only: master

Smoke Testing:
when: << pipeline.parameters.run_smoketesting >>
jobs:
- Hold [Smoke-Testing]:
type: approval
- smoke-testing-dev:
context : org-global
requires:
- Hold [Smoke-Testing]
filters:
<<: *filters-dev
- smoke-testing-prod:
context : org-global
requires:
- Hold [Smoke-Testing]
filters:
<<: *filters-prod
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
node_modules
/.pnp
.pnp.js
.idea
Expand All @@ -27,3 +27,7 @@ yarn-error.log*
*.env

*.vscode

# e2e test case
test-automation/temp
test-automation/test-results
32 changes: 32 additions & 0 deletions test-automation/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM node:10.17.0-stretch
RUN apt update
RUN apt install sudo
RUN sudo apt-get update; sudo apt-get install -y openjdk-8-jre openjdk-8-jre-headless openjdk-8-jdk openjdk-8-jdk-headless;
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 \
&& (sudo dpkg -i /tmp/google-chrome-stable_current_amd64.deb || sudo apt-get -fy install) \
&& rm -rf /tmp/google-chrome-stable_current_amd64.deb \
&& sudo sed -i 's|HERE/chrome"|HERE/chrome" --disable-setuid-sandbox --no-sandbox|g' \
"/opt/google/chrome/google-chrome" \
&& google-chrome --version
RUN export CHROMEDRIVER_RELEASE=$(curl --location --fail --retry 3 http://chromedriver.storage.googleapis.com/LATEST_RELEASE) \
&& curl --silent --show-error --location --fail --retry 3 --output /tmp/chromedriver_linux64.zip "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_RELEASE/chromedriver_linux64.zip" \
&& cd /tmp \
&& unzip chromedriver_linux64.zip \
&& rm -rf chromedriver_linux64.zip \
&& sudo mv chromedriver /usr/local/bin/chromedriver \
&& sudo chmod +x /usr/local/bin/chromedriver \
&& chromedriver --version
RUN sudo apt-get install -y libgconf-2-4
RUN sudo apt-get install -y xvfb
RUN sudo apt-get install -y jq
ENV DISPLAY :99
RUN printf '#!/bin/sh\nXvfb :99 -screen 0 1280x1024x24 &\nexec "$@"\n' > /tmp/entrypoint \
&& chmod +x /tmp/entrypoint \
&& sudo mv /tmp/entrypoint /docker-entrypoint.sh

COPY . /test-automation
WORKDIR /test-automation
RUN npm install
RUN ./node_modules/.bin/webdriver-manager update --versions.chrome=="$(google-chrome -version)"
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["/bin/sh"]
41 changes: 41 additions & 0 deletions test-automation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Work Manager App - E2E Tests

#### Software Required

* Nodejs v15.4.0
* Chrome Browser

#### Installation

- Install Dependencies using command
`npm install`

- To run tests

`cd test-automation`

`npm run test`

- Test results are generated in `test-results/` folder

```
HTML report - TestResult.html
Junit report - junitresults-WorkManagerCreateChallengeTests.xml and junitresults-WorkMangerDashboardPageTests.xml
```

- To view junit reports into html, install xunit-viewer
`npm i -g xunit-viewer`

- HTML report from Junit reports can be generated using this command
`xunit-viewer --results=test-results/ --output=./result.html`

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`

#### Test Data:

- Test data are located in `/test-data/test-data.json` file.

#### Configuration details:

- `config.json` holds the data level configuration, like user credentials etc
- `conf.ts` holds the application configuration, like jasmine reporters to be configured, specs to be run etc.
79 changes: 79 additions & 0 deletions test-automation/conf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import reporters = require('jasmine-reporters');
import HtmlReporter = require('protractor-beautiful-reporter');
import { BrowserHelper } from 'topcoder-testing-lib';

declare global {
namespace NodeJS {
interface IGlobal {
document: Document;
window: Window;
navigator: Navigator;
forgotPasswordMailListener: any;
registrationMailListener: any;
}
}
}

exports.config = {
setupFilesAfterEnv: ['./jest.setup.js'],

// Capabilities to be passed to the webdriver instance.
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: [
'--headless',
'--disable-gpu',
'--no-sandbox',
'--window-size=1325x744',
'disable-infobars'
],
'excludeSwitches': ['enable-automation'],
prefs: {
'credentials_enable_service': false,
'profile': {
'password_manager_enabled': false
}
}
},
},

directConnect: true,

// Framework to use. Jasmine is recommended.
framework: 'jasmine2',

specs: [
'../temp/test-suites/dashboard-flow/dashboard.spec.js',
'../temp/test-suites/create-challenge-flow/create-challenge.spec.js',
],

// Options to be passed to Jasmine.
jasmineNodeOpts: {
defaultTimeoutInterval: 1200000, // 20 minutes
isVerbose: true,
showColors: true,
},

onPrepare: () => {
BrowserHelper.maximize();
const junitReporter = new reporters.JUnitXmlReporter({
consolidateAll: false,
savePath: 'test-results',
});
jasmine.getEnv().addReporter(junitReporter);
jasmine.getEnv().addReporter(
new HtmlReporter({
baseDirectory: 'test-results',
docName: 'TestResult.html', // Change html report file name
docTitle: 'Test Automation Execution Report', // Add title for the html report
gatherBrowserLogs: true, // Store Browser logs
jsonsSubfolder: 'jsons', // JSONs Subfolder
preserveDirectory: false, // Preserve base directory
screenshotsSubfolder: 'screenshots',
takeScreenShotsForSkippedSpecs: true, // Screenshots for skipped test cases
takeScreenShotsOnlyForFailedSpecs: true, // Screenshots only for failed test cases
}).getJasmine2Reporter()
);
},
};
19 changes: 19 additions & 0 deletions test-automation/config/app-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"Timeout": {
"FieldVisibility": 15000,
"ElementVisibility": 15000,
"ElementInvisibility": 15000,
"ElementPresence": 15000,
"ElementClickable": 15000,
"PageLoad": 300000,
"ActiveChallengeTimeout": 300000
},

"LoggerErrors": {
"ElementVisibility": "Element did not display within timeout",
"ElementInvisibility": "Element did not become invisible within timeout",
"ElementPresence": "Element was not present within timeout",
"ElementClickable": "Element was not clickable within timeout",
"PageLoad": "Page did not load within timeout"
}
}
15 changes: 15 additions & 0 deletions test-automation/config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"copilotRole": {
"email": "[email protected]",
"password": "appirio123",
"handle": "TCConnCopilot"
},
"copilotManagerRole": {
"email": "[email protected]",
"password": "appirio123",
"handle": "TCConCopilotMgr"
},
"givenUrl": "https://challenges.topcoder-dev.com/",
"challengeUrl": "https://challenges.topcoder-dev.com/projects/16573/challenges",
"logoutUrl": "https://accounts-auth0.topcoder-dev.com/?logout=true&retUrl=https://connect.topcoder-dev.com",
}
4 changes: 4 additions & 0 deletions test-automation/logger/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createLogger, transports } from "winston";
export const logger = createLogger({
transports: [new transports.Console()]
});
Loading