Skip to content
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

SIDM-2686 - Cross browser tests #333

Merged
merged 4 commits into from
Mar 12, 2020
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
21 changes: 14 additions & 7 deletions Jenkinsfile_nightly
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ properties([
])
])

@Library("Infrastructure")
@Library("Infrastructure") _

def type = "java"

Expand All @@ -36,18 +36,25 @@ static LinkedHashMap<String, Object> secret(String secretName, String envVar) {
}

withNightlyPipeline(type, product, component) {

env.TEST_URL = params.URL_TO_TEST

env.IDAMAPI = params.API_URL_TO_TEST

loadVaultSecrets(secrets)

enableSecurityScan()

enableMutationTest()

enableFullFunctionalTest(200)
enableCrossBrowserTest()

after('crossBrowserTest') {
try {
withSauceConnect("reform_tunnel") {
sh "./gradlew functionalSauce"
steps.archiveArtifacts allowEmptyArchive: true, artifacts: 'functional-output/**/*'
}
}
finally {
steps.saucePublisher()
}
}

after('fullFunctionalTest') {

Expand Down
21 changes: 20 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,26 @@ allprojects {
commandLine 'node_modules/codeceptjs/bin/codecept.js', 'run', '--grep', '@functional', '--verbose', '--reporter', 'mocha-multi'
}

task smokeSauce(dependsOn: ':codeceptSmokeSauce') {
group = 'Delivery pipeline'
description = 'Executes non-destructive smoke tests against a running instance'
}

task codeceptSmokeSauce(type: Exec, dependsOn: ':yarnInstall') {
workingDir '.'
commandLine 'node_modules/codeceptjs/bin/codecept.js', 'run', '--config', 'saucelabs.conf.js','--steps', '--grep', '@smoke', '--verbose', '--debug', '--reporter', 'mochawesome'
}

task functionalSauce(dependsOn: ':codeceptFunctionalSauce') {
group = 'Delivery pipeline'
description = 'Executes non-destructive smoke tests against a running instance'
}

task codeceptFunctionalSauce(type: Exec, dependsOn: [':yarnInstall', ':notifyClientInstall']) {
workingDir '.'
commandLine 'node_modules/codeceptjs/bin/codecept.js', 'run-multiple', '--all', '--config', 'saucelabs.conf.js', '--grep', '@crossbrowser', '--verbose', '--debug', '--reporter', 'mochawesome'
}

task pa11y(type: Exec, dependsOn: 'pa11yInstall') {
workingDir '.'
commandLine './node_modules/.bin/pa11y', '--config', 'pa11y.conf.js', System.getenv('TEST_URL')
Expand Down Expand Up @@ -215,4 +235,3 @@ test.finalizedBy jacocoTestReport
bootRun {
systemProperties = System.properties
}

2 changes: 0 additions & 2 deletions functional-output/zapreports

This file was deleted.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"codeceptjs": "^1.2.0",
"codeceptjs-resemblehelper": "^1.9.0",
"deep-equal-in-any-order": "^1.0.13",
"electron": "^2.0.8",
"mocha-junit-reporter": "^1.17.0",
"mocha-multi": "^1.0.1",
"mochawesome": "^3.0.2",
Expand All @@ -20,6 +19,12 @@
"pa11y": "^4.13.2",
"proxy-agent": "^3.0.1",
"puppeteer": "^2.0.0",
"node-fetch": "^2.6.0"
"node-fetch": "^2.6.0",
"wdio-sauce-service": "^0.4.4",
"webdriverio": "^4.14.2"
},
"scripts": {
"test-crossbrowser-e2e": "NODE_PATH=. codeceptjs run-multiple --all -c saucelabs.conf.js --steps --grep '@crossbrowser' --reporter mochawesome",
"test:crossbrowser": "runSauceLabsTests.sh"
}
}
63 changes: 63 additions & 0 deletions saucelabs.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const supportedBrowsers = require('./src/test/js/config/supportedBrowsers.js');
const browser = process.env.SAUCE_BROWSER || 'chrome';
const tunnelName = process.env.TUNNEL_IDENTIFIER || 'reformtunnel';

const waitForTimeout = 60000;
const smartWait = 5000;

const getBrowserConfig = browserGroup => {
const browserConfig = [];
for (const candidateBrowser in supportedBrowsers[browserGroup]) {
if (candidateBrowser) {
const desiredCapability = supportedBrowsers[browserGroup][candidateBrowser];
desiredCapability.acceptSslCerts = true;
desiredCapability.tunnelIdentifier = tunnelName;
desiredCapability.tags = ['idam-web-public'];
browserConfig.push({
browser: desiredCapability.browserName,
desiredCapabilities: desiredCapability
});
} else {
console.error('ERROR: supportedBrowsers.js is empty or incorrectly defined');
}
}
return browserConfig;
};

const setupConfig = {
tests: './src/test/js/cross_browser_test.js',
output: `${process.cwd()}/functional-output`,
helpers: {
WebDriverIO: {
url: process.env.TEST_URL,
browser : 'chrome',
waitForTimeout,
smartWait,
cssSelectorsEnabled: 'true',
host: 'ondemand.eu-central-1.saucelabs.com',
port: 80,
region: 'eu',
sauceConnect: true,
services: ['sauce'],
acceptSslCerts : true,
user: process.env.SAUCE_USERNAME,
key: process.env.SAUCE_ACCESS_KEY,
desiredCapabilities: { }
},
SauceLabsReportingHelper: { require: './src/test/js/shared/sauceLabsReportingHelper.js' },
idam_helper: { require: './src/test/js/shared/idam_helper.js' }
},
include: { I: './src/test/js/shared/custom_steps.js' },

multiple: {
chrome: {
browsers: getBrowserConfig('chrome')
},
firefox: {
browsers: getBrowserConfig('firefox')
}
},
name: 'Idam web public'
};

exports.config = setupConfig;
30 changes: 30 additions & 0 deletions src/test/js/config/runUITestsSauceLabs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
supportedBrowsers=`sed '/\/\//d' ./supportedBrowsers.js | sed '/\/\//d' | sed "s/[\'\:\{ ]//g"`
browsersArray=(${supportedBrowsers//$'\n'/ })

outputDirectory="${E2E_CROSSBROWSER_OUTPUT_DIR:-functional-output/crossbrowser/reports}"

echo
echo "*****************************************"
echo "* The following browsers will be tested *"
echo "*****************************************"
echo "$supportedBrowsers"
echo "****************************************"
echo
echo

for i in "${browsersArray[@]}"
do
echo "*** Testing $i ***"

FOLDERNAME="$i-$(date +%s)"

mkdir ../../../../output/$FOLDERNAME

SAUCELABS_BROWSER=$i TUNNEL_IDENTIFIER=reformtunnel npm run test-crossbrowser-e2e

for f in ../../../../output/*.*; do
echo $f
mv $f ../../../../output/$FOLDERNAME
done
done
32 changes: 32 additions & 0 deletions src/test/js/config/supportedBrowsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const supportedBrowsers = {
chrome: {
chrome_win_latest: {
browserName: 'chrome',
name: 'DIV_WIN_CHROME_LATEST',
platform: 'Windows 10',
version: 'latest'
},
chrome_mac_latest: {
browserName: 'chrome',
name: 'MAC_CHROME_LATEST',
platform: 'macOS 10.13',
version: 'latest'
}
},
firefox: {
firefox_win_latest: {
browserName: 'firefox',
name: 'WIN_FIREFOX_LATEST',
platform: 'Windows 10',
version: 'latest'
},
firefox_mac_latest: {
browserName: 'firefox',
name: 'MAC_FIREFOX_LATEST',
platform: 'macOS 10.13',
version: 'latest'
}
}
};

module.exports = supportedBrowsers;
2 changes: 1 addition & 1 deletion src/test/js/config/test_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ module.exports = {
NOTIFY_API_KEY: process.env.NOTIFY_API_KEY,
SCENARIO_RETRY_LIMIT: 3,
PASSWORD: "Passw0rdIDAM",
SERVICE_REDIRECT_URI: 'https://idam.testservice.gov.uk',
SERVICE_REDIRECT_URI: 'http://idam.testservice.gov.uk',
SERVICE_CLIENT_SECRET: 'autotestingservice',
};
119 changes: 119 additions & 0 deletions src/test/js/cross_browser_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
const chai = require('chai');
const {expect} = chai;
const TestData = require('./config/test_data');
const randomData = require('./shared/random_data');

Feature('Users can sign in');

let randomUserFirstName;
let citizenEmail;
let userFirstNames = [];
let roleNames = [];
let serviceNames = [];
let randomUserLastName;
let existingCitizenEmail;
let pinUserFirstName;
let pinUserLastName;
let pinaccessToken;

const serviceName = randomData.getRandomServiceName();

const selfRegUrl = `${TestData.WEB_PUBLIC_URL}/users/selfRegister?redirect_uri=${TestData.SERVICE_REDIRECT_URI}&client_id=${serviceName}`;

BeforeSuite(async (I) => {
randomUserFirstName = randomData.getRandomUserName();
const adminEmail = 'admin.' + randomData.getRandomEmailAddress();
citizenEmail = 'citizen.' + randomData.getRandomEmailAddress();
existingCitizenEmail = 'existingcitizen.' + randomData.getRandomEmailAddress();
pinUserLastName = randomData.getRandomUserName() + 'pinępinç';
pinUserFirstName = randomData.getRandomUserName() + 'ępinçłpin';

let token = await I.getAuthToken();
let response;
response = await I.createRole(randomData.getRandomRoleName() + "_beta", 'beta description', '', token);
const serviceBetaRole = response.name;
response = await I.createRole(randomData.getRandomRoleName() + "_admin", 'admin description', serviceBetaRole, token);
const serviceAdminRole = response.name;
response = await I.createRole(randomData.getRandomRoleName() + "_super", 'super description', serviceAdminRole, token);
const serviceSuperRole = response.name;
const serviceRoles = [serviceBetaRole, serviceAdminRole, serviceSuperRole];
roleNames.push(serviceRoles);
await I.createServiceWithRoles(serviceName, serviceRoles, serviceBetaRole, token);
serviceNames.push(serviceName);
await I.createUserWithRoles(adminEmail, randomUserFirstName + 'Admin', [serviceAdminRole, "IDAM_ADMIN_USER"]);
userFirstNames.push(randomUserFirstName + 'Admin');
await I.createUserWithRoles(citizenEmail, randomUserFirstName + 'Citizen', ["citizen"]);
userFirstNames.push(randomUserFirstName + 'Citizen');
randomUserLastName = randomData.getRandomUserName();
await I.createUserWithRoles(citizenEmail, randomUserFirstName, ["citizen"]);
userFirstNames.push(randomUserFirstName);
await I.createUserWithRoles(existingCitizenEmail, randomUserFirstName + 'Citizen', ["citizen"]);
userFirstNames.push(randomUserFirstName + 'Citizen');

const pinUser = await I.getPinUser(pinUserFirstName, pinUserLastName);
const code = await I.loginAsPin(pinUser.pin, serviceName, TestData.SERVICE_REDIRECT_URI);
pinaccessToken = await I.getAccessToken(code, serviceName, TestData.SERVICE_REDIRECT_URI, TestData.SERVICE_CLIENT_SECRET);
});

AfterSuite(async (I) => {
return I.deleteAllTestData(randomData.TEST_BASE_PREFIX)
});

Scenario('@functional @crossbrowser Idam Web public cross browser tests', async (I) => {

const email = 'test_citizen.' + randomData.getRandomEmailAddress();
citizenEmail = 'citizen.' + randomData.getRandomEmailAddress();

const loginPage = `${TestData.WEB_PUBLIC_URL}/login?redirect_uri=${TestData.SERVICE_REDIRECT_URI}&client_id=${serviceName}&state=selfreg`;
I.amOnPage(selfRegUrl);
I.waitInUrl('users/selfRegister', 180);
I.waitForText('Create an account or sign in', 20, 'h1');
I.see('Create an account');
I.fillField('firstName', randomUserFirstName);
I.fillField('lastName', randomUserLastName);
I.fillField('email', citizenEmail);
I.click("Continue");
I.waitForText('Check your email', 20, 'h1');
I.wait(5);
const userActivationUrl = await I.extractUrl(citizenEmail);
I.amOnPage(userActivationUrl);
I.waitForText('Create a password', 20, 'h1');
I.seeTitleEquals('User Activation - HMCTS Access');
I.fillField('#password1', TestData.PASSWORD);
I.fillField('#password2', TestData.PASSWORD);
I.click('Continue');
I.waitForText('Account created', 20, 'h1');
I.see('You can now sign in to your account.');
I.wait(5);
I.lockAccount(citizenEmail, serviceName);
I.click('reset your password');
I.waitForText('Reset your password', 20, 'h1');
I.fillField('#email', citizenEmail);
I.click('Submit');
I.waitForText('Check your email', 20, 'h1');
I.wait(5);
const resetPasswordUrl = await I.extractUrl(citizenEmail);
I.amOnPage(resetPasswordUrl);
I.waitForText('Create a new password', 20, 'h1');
I.seeTitleEquals('Reset Password - HMCTS Access');
I.fillField('#password1', 'Passw0rd1234');
I.fillField('#password2', 'Passw0rd1234');
I.click('Continue');
I.waitForText('Your password has been changed', 20, 'h1');
I.see('You can now sign in with your new password.');

const userInfo = await I.retry({retries: 3, minTimeout: 10000}).getUserByEmail(citizenEmail);
expect(userInfo.active).to.equal(true);
expect(userInfo.email).to.equal(citizenEmail);
expect(userInfo.forename).to.equal(randomUserFirstName);
expect(userInfo.id).to.not.equal(null);
expect(userInfo.roles).to.eql(['citizen']);

I.amOnPage(`${TestData.WEB_PUBLIC_URL}/login/uplift?client_id=${serviceName}&redirect_uri=${TestData.SERVICE_REDIRECT_URI}&jwt=${pinaccessToken}`);
I.waitForText('Sign in to your account.', 30);
I.click('Sign in to your account.');
I.fillField('#username', existingCitizenEmail);
I.wait(2)
I.fillField('#password', TestData.PASSWORD);
I.click('Sign in');
});
2 changes: 0 additions & 2 deletions src/test/js/policy_check_functional_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ BeforeSuite(async (I) => {
roleNames.push(serviceRoles);
await I.createServiceWithRoles(serviceName, serviceRoles, serviceBetaRole, token);
serviceNames.push(serviceName);
await I.createUserWithRoles(adminEmail, randomUserFirstName + 'Admin', [serviceAdminRole, "IDAM_ADMIN_USER"]);
userFirstNames.push(randomUserFirstName + 'Admin');
await I.createUserWithRoles(citizenEmail, randomUserFirstName + 'Citizen', ["citizen"]);
userFirstNames.push(randomUserFirstName + 'Citizen');

Expand Down
2 changes: 1 addition & 1 deletion src/test/js/shared/random_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function randomAlphabeticString(length = 10) {
return randomString
}

const testBasePrefix = "SIDMTESTWP" + randomAlphabeticString();
const testBasePrefix = "SIDMTESTWP_" + randomAlphabeticString();
const testUserPrefix = testBasePrefix + "USER";
const testRolePrefix = testBasePrefix + "ROLE_";
const testServicePrefix = testBasePrefix + "SERVICE_";
Expand Down
Loading