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

CIV-15585 Adding cross browser tests #4890

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions Jenkinsfile_nightly
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,18 @@ withNightlyPipeline(type, product, component) {
])
loadVaultSecrets(secrets)

afterAlways('build') {
yarnBuilder.yarn('install-dependencies')
}

enableCrossBrowserTest()

enableFullFunctionalTest(200)

afterAlways('crossBrowserTest') {
steps.archiveArtifacts allowEmptyArchive: true, artifacts: 'functional-output/**/*'
}

afterAlways('fullFunctionalTest') {
archiveArtifacts allowEmptyArchive: true, artifacts: 'test-results/functional/**/*'
steps.archiveArtifacts allowEmptyArchive: true, artifacts: 'src/test/functionalTests/test-results/functional/**/*'
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
"test:cui-regression": "MOCHAWESOME_REPORTFILENAME=cui yarn test:functional:codeceptjs run-workers --suites 13 --grep @regression --reporter mocha-multi --verbose",
"test:carm": "MOCHAWESOME_REPORTFILENAME=carm yarn test:functional:codeceptjs run-workers --suites 2 --grep @regression-carm --reporter mocha-multi --verbose",
"test:functional": "src/test/functionalTests/run-functional-tests.sh",
"test:crossbrowser": "src/test/crossbrowser/run-crossbrowser-tests.sh",
"test:fullfunctional": "MOCHAWESOME_REPORTFILENAME=functionalTests yarn test:functional:codeceptjs run-workers --suites 4 --grep @nightly --reporter mocha-multi --verbose",
"test:crossbrowser": "SAUCE='true' yarn test:crossbrowser:codeceptjs run",
"test-crossbrowser-fullfunctional": "MOCHAWESOME_REPORTFILENAME=crossBrowserTests yarn codeceptjs run-workers 1 --grep @smoketest ${BROWSER_GROUP:-'--all'} -c src/test/crossbrowser/saucelabs.conf.js",
"test:crossbrowser:playwright": "yarn test:crossbrowser:codeceptjs run-multiple crossBrowser",
"test:crossbrowser:codeceptjs": "codeceptjs --config ./src/test/cross-browser/codecept.conf.js",
"test:functional:codeceptjs": "codeceptjs --config src/test/functionalTests/codecept.conf.js",
Expand Down
5 changes: 5 additions & 0 deletions src/test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ module.exports = {
roleCategory: 'JUDICIAL',
regionId: '1',
},
legalAdvisor: {
password: defaultPassword,
email: 'tribunal_legal_caseworker_reg2@justice.gov.uk',
type: 'legal operations',
},
judgeUserWithRegionId2: {
password: judgeDefaultPassword,
email: 'DJ.Angel.Morgan@ejudiciary.net',
Expand Down
26 changes: 26 additions & 0 deletions src/test/crossbrowser/helpers/SauceLabsReportingHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

const event = require('codeceptjs').event;
const container = require('codeceptjs').container;
const exec = require('child_process').exec;

const sauceUsername = process.env.SAUCE_USERNAME;
const sauceKey = process.env.SAUCE_ACCESS_KEY;

function updateSauceLabsResult(result, sessionId) {
console.log('SauceOnDemandSessionID=' + sessionId + ' job-name=citizen-ui');
return 'curl -X PUT -s -d \'{"passed": ' + result + '}\' -u ' + sauceUsername + ':' + sauceKey + ' https://eu-central-1.saucelabs.com/rest/v1/' + sauceUsername + '/jobs/' + sessionId;
}

module.exports = function() {
// Setting test success on SauceLabs
event.dispatcher.on(event.test.passed, () => {
const sessionId = container.helpers('WebDriver').browser.sessionId;
exec(updateSauceLabsResult('true', sessionId));
});

// Setting test failure on SauceLabs
event.dispatcher.on(event.test.failed, () => {
const sessionId = container.helpers('WebDriver').browser.sessionId;
exec(updateSauceLabsResult('false', sessionId));
});
};
15 changes: 15 additions & 0 deletions src/test/crossbrowser/run-crossbrowser-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -ex

# Setup required for Saucelabs environment variables. TEST_URL should be set by CNP
export E2E_FRONTEND_URL=${TEST_URL}
export IGNORE_SESSION_VALIDATION=true

EXIT_STATUS=0
BROWSER_GROUP=microsoftIE11 yarn test-crossbrowser-fullfunctional || EXIT_STATUS=$?
BROWSER_GROUP=microsoftEdge yarn test-crossbrowser-fullfunctional || EXIT_STATUS=$?
BROWSER_GROUP=chrome yarn test-crossbrowser-fullfunctional || EXIT_STATUS=$?
BROWSER_GROUP=firefox yarn test-crossbrowser-fullfunctional || EXIT_STATUS=$?
BROWSER_GROUP=safari yarn test-crossbrowser-fullfunctional || EXIT_STATUS=$?
echo EXIT_STATUS: $EXIT_STATUS
exit $EXIT_STATUS
150 changes: 150 additions & 0 deletions src/test/crossbrowser/saucelabs.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
const supportedBrowsers = require('../crossbrowser/supportedBrowsers.js');
const {unAssignAllUsers} = require('../functionalTests/specClaimHelpers/api/caseRoleAssignmentHelper');
const {deleteAllIdamTestUsers} = require('../functionalTests/specClaimHelpers/api/idamHelper');
const testConfig = require('../config');

const browser = process.env.SAUCELABS_BROWSER || 'chromium';

const defaultSauceOptions = {
username: process.env.SAUCE_USERNAME,
accessKey: process.env.SAUCE_ACCESS_KEY,
tunnelIdentifier: process.env.TUNNEL_IDENTIFIER || 'reformtunnel',
acceptSslCerts: true,
pageLoadStrategy: 'normal',
idleTimeout: 700,
tags: ['Citizen UI'],
};

function merge(intoObject, fromObject) {
return Object.assign({}, intoObject, fromObject);
}

function getBrowserConfig(browserGroup) {
const browserConfig = [];
for (const candidateBrowser in supportedBrowsers[browserGroup]) {
if (candidateBrowser) {
const candidateCapabilities = supportedBrowsers[browserGroup][candidateBrowser];
candidateCapabilities['sauce:options'] = merge(
defaultSauceOptions, candidateCapabilities['sauce:options'],
);
browserConfig.push({
browser: candidateCapabilities.browserName,
capabilities: candidateCapabilities,
});
} else {
console.error('ERROR: supportedBrowsers.js is empty or incorrectly defined');
}
}
return browserConfig;
}

let startTime;
const setupConfig = {
bootstrapAll: async () => {
startTime = new Date();
console.log(`Starting the tests at ${startTime}`);
},
teardownAll: async () => {
const endTime = new Date();
const executionTime = (endTime - startTime) / 1000; // in seconds
console.log(`Finished the tests at ${endTime}`);
console.log(`Total execution time: ${executionTime} seconds`);
},
async teardown() {
console.log('Current worker has finished running tests so we should clean up the user roles');
await unAssignAllUsers();
await deleteAllIdamTestUsers();
},
tests: process.env.ENVIRONMENT == 'aat' ?
[ '../functionalTests/tests/prod/**/*.js',
'../functionalTests/tests/common/**/*.js',
'../e2eTests/tests/**/*.js'] :
[ '../functionalTests/tests/nonprod/**/*.js',
'../functionalTests/tests/common/**/*.js',
'../e2eTests/tests/**/*.js'],
output: `${process.cwd()}/functional-output`,
helpers: {
WebDriver: {
url: testConfig.TestUrl,
browser,
keepCookies: true,
waitForTimeout: 90000,
smartWait: 90000,
cssSelectorsEnabled: 'true',
chromeOptions: {
args: [
'start-maximized',
'--disable-dev-shm-usage',
'--disable-gpu',
'--no-sandbox',
'disable-infobars',
'ignore-gpu-blacklist',
],
},
acceptInsecureCerts: true,
sauceSeleniumAddress: 'ondemand.eu-central-1.saucelabs.com:443/wd/hub',
host: 'ondemand.eu-central-1.saucelabs.com',
port: 80,
region: 'eu',
sauceConnect: true,
supportedBrowsers,
capabilities: {},
},
SauceLabsReportingHelper: {
require: './helpers/SauceLabsReportingHelper.js',
},
},
plugins: {
autoDelay: {
enabled: true,
methods: [
'click',
'fillField',
'checkOption',
'selectOption',
'attachFile',
'see',
'seeInCurrentUrl',
],
},
retryFailedStep: {
enabled: true,
},
screenshotOnFail: {
enabled: true,
fullPageScreenshots: true,
},
},
include: {
api: '../functionalTests/specClaimHelpers/api/steps.js',
wa: '../functionalTests/specClaimHelpers/api/stepsWA.js',
noc: '../functionalTests/specClaimHelpers/api/steps_noc.js',
},
mocha: {
reporter: 'mochawesome',
reporterOptions: {
reportDir: process.env.CROSSBROWSER_OUTPUT_DIR || './functional-output',
reportTitle: 'Crossbrowser results',
inline: true,
},
},
multiple: {
microsoftIE11: {
browsers: getBrowserConfig('microsoftIE11'),
},
microsoftEdge: {
browsers: getBrowserConfig('microsoftEdge'),
},
chrome: {
browsers: getBrowserConfig('chrome'),
},
firefox: {
browsers: getBrowserConfig('firefox'),
},
safari: {
browsers: getBrowserConfig('safari'),
},
},
};

exports.config = setupConfig;
74 changes: 74 additions & 0 deletions src/test/crossbrowser/supportedBrowsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const supportedBrowsers = {
microsoftIE11: {
ie11: {
browserName: 'internet explorer',
platformName: 'Windows 10',
browserVersion: '11.285',
'sauce:options': {
name: 'CUI_WIN10_IE11_11',
},
},
},
microsoftEdge: {
edge: {
browserName: 'MicrosoftEdge',
platformName: 'Windows 10',
browserVersion: '18.17763',
'sauce:options': {
name: 'CUI_WIN10_EDGE_18',
},
},
},
chrome: {
chrome_win_latest: {
browserName: 'chrome',
browserVersion: 'latest',
platformName: 'Windows 10',
'sauce:options': {
name: 'CUI_WIN10_CHROME_LATEST',
extendedDebugging: true,
},
},
chrome_mac_latest: {
browserName: 'chrome',
browserVersion: 'latest',
platformName: 'macOS 10.13',
'sauce:options': {
name: 'CUI_MAC_CHROME_LATEST',
extendedDebugging: true,
},
},
},
firefox: {
firefox_win_latest: {
browserName: 'firefox',
platformName: 'Windows 10',
browserVersion: 'latest',
'sauce:options': {
name: 'CUI_WIN10_FIREFOX_LATEST',
extendedDebugging: true,
},
},
firefox_mac_latest: {
browserName: 'firefox',
platformName: 'macOS 10.13',
browserVersion: 'latest',
'sauce:options': {
name: 'CUI_MAC_FIREFOX_LATEST',
extendedDebugging: true,
},
},
},
safari: {
safari11: {
browserName: 'safari',
browserVersion: '11.1',
platformName: 'macOS 10.13',
'sauce:options': {
name: 'CUI_MAC_SAFARI_11',
},
},
},
};

module.exports = supportedBrowsers;
Loading