devops:tests:protractor
This is an old revision of the document!
Table of Contents
Protractor
Is an end-to-end testing JavaScript solution.
- Executes the real application using selenium
- Run the tests against it
Protractor is nothing but a wrapper over the Selenium WebDriverJS Api that translates its succinct code and methods to WebDriver JS methods. That said, you can use WebDriverJS methods too inside your e2e script.
UI Tests
test_config.js
This is the configuration file used by protractor for managing any config parameter used globally within the web application.
require('dotenv').config();
let options = require("./lib/config");
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
exports.config = {
framework: 'jasmine',
seleniumAddress: options.seleniumAddress,
//specs is used for when calling protractor without passing suites to run
specs: ['spec/API_Widgets_tests.js',
'spec/Functional_tests.js',
'spec/API_CRUD_tests.js',
'spec/Negative_tests.js',
'spec/Filters_tests.js',
'spec/Negative_Filters_tests.js',
'spec/UI_tests_Main.js',
'spec/UI_tests.js',
'spec/UI_tests_files.js',
'spec/UI_tests_NavVis',
'spec/Auth_UI_tests.js'],
//'spec/UI_tests_NavVis.js'],
// //'spec/UI_tests_api_reference.js'],
//specs: ['spec/API_CRUD_tests.js'],
//Suites defined to run tests on Dev or Stage
suites: {
//dev: 'spec/*.js',
// dev: ['spec/Functional_tests.js',
// 'spec/Negative_tests.js',
// 'spec/Filters_tests.js',
// 'spec/Negative_Filters_tests.js',
// // 'spec/UI_tests.js',
// // 'spec/UI_tests_files.js',
// // 'spec/UI_tests_Main.js',
// // 'spec/UI_tests_template.js',
// 'spec/API_Widgets_tests.js',
// 'spec/API_CRUD_tests.js',
// 'spec/Auth_UI_tests.js'],
dev: ['spec/Auth_UI_tests.js'],
// stage: ['spec/API_CRUD_tests.js',
// 'spec/Negative_tests.js',
// 'spec/Filters_tests.js',
// 'spec/Negative_Filters_tests.js',
// 'spec/API_Widgets_tests.js',
// 'spec/UI_tests.js',
// 'spec/UI_tests_files.js',
// 'spec/API_CRUD_tests.js',
// 'spec/UI_tests_Main.js',
// 'spec/Auth_UI_tests.js']
stage: ['spec/Auth_UI_tests.js']
},
onPrepare: function () {
browser.driver.manage().window().maximize();
jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
savePath: './test/reports/',
screenshotsFolder: 'images',
takeScreenshots: true,
takeScreenshotsOnlyOnFailures: true,
fixedScreenshotName: true,
showPassed: false,
filePrefix: 'SeleniumReport'
// consolidate: false,
// consolidateAll: false
}));
var AllureReporter = require('./node_modules/jasmine-allure-reporter');
jasmine.getEnv().addReporter(new AllureReporter({
resultsDir: 'test/allure-results/'
}));
var jasmineReporters = require('./node_modules/jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'test/reports',
filePrefix: 'xmloutput'
})
)
},
ignoreUncaughtExceptions: true,
capabilities: {
browserName: 'chrome',
noGlobals: false,
binary: 'C:/Program Files/ChromePortable/App/Chrome-bin/chrome.exe',
//shardTestFiles: true,
//maxInstances:7,
chromeOptions: {
useAutomationExtension: false,
args: ["--headless",
"--disable-gpu",
"--disable-browser-side-navigation",
"--disable-infobars",
"--no-sandbox",
"--window-size=1200,900"]
// args: [ "--window-size=1400,900" ]
}
},
// capabilities: {
// browserName: 'firefox',
// 'moz:firefoxOptions': {
// args: ['--verbose'],
// binary: 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe'
// //Provide binary location to avoid potential binary not found errors
// //Need to start cmd via admin mode to avoid permission error
// }
// },
// capabilities: {
// browserName: 'chrome',
// noGlobals: false,
// //shardTestFiles: true,
// //maxInstances:7,
// chromeOptions: {
// useAutomationExtension: false,
// args: ["--headless",
// "--disable-gpu",
// "--disable-browser-side-navigation",
// "--disable-infobars",
// "--no-sandbox",
// "--window-size=1200,900"]
// // args: [ "--window-size=1400,900" ]
// }
// },
// TODO: Initial work proves multi browser testing works.
// multiCapabilities: [
// {'browserName': 'chrome',
// 'chromeOptions': {
// 'args': ['disable-infobars']
// }
// },
// {'browserName': 'firefox',
// 'moz:firefoxOptions': {
// 'args': ['--safe-mode']
// }
// }
// ],
// Options to be passed to Jasmine.
jasmineNodeOpts: {
defaultTimeoutInterval: 90000, //increased to 30 seconds
},
params: {
gWidgetID: 'empty',
gCampusID: 'empty'
}
}
package.json
NPM dependency configs.
{
"name": "ui",
"version": "1.0.0",
"description": "This is a reference implementation of the Selenium test using javascript.",
"main": "conf.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "0.19.0",
"dotenv": "8.1.0",
"jasmine-allure-reporter": "^0.2.3",
"protractor": "^5.4.4",
"protractor-jasmine2-html-reporter": "0.0.7",
"proxy-agent": "3.1.0",
"request": "2.88.0",
"request-promise": "^4.2.4"
},
"devDependencies": {
"jasmine-reporters": "^2.0.0"
}
}
</sxh >
====== Execution script ======
This script sets the environment variables, which then are passed into the
config files and then may be used in the tests.
<sxh bash>
if [ $# -eq 0 ]
then
echo "Please provide the environment: dev or stage"
exit 1
fi
#update IDs prior to processing Spec
if [ $1 == 'stage' ]
then
export FLOOR_SOURCE=2uPwyjC2z1Jx16EzvQ_xZO
export SPACE_NAME="1.001"
export SPACE_SOURCE=03fjvA5B1CWOG33uprLUQT
export SPACE_ISPARTOF=b5c703a7-627d-4562-ba2c-6399557c670d
export DEVICE_NAME="Sensor_block:T&LQ:1138260"
export DEVICE_SOURCE="3TYhTs\$S924vrYvWDC_1_z"
export DEVICE_TAG=air
export DEVICE_ISLOCATEDIN=233ffa56-c569-4ece-8781-23e021a8d990
export EQUIPMENT_NAME="Sensor_block:T&LQ:1138260"
export EQUIPMENT_SOURCE="3TYhTs\$S924vrYvWDC_1_z"
export EQUIPMENT_TAG=air
export EQUIPMENT_ISLOCATEDIN=233ffa56-c569-4ece-8781-23e021a8d990
export TEST_ID=7890
export FILE_ID=42be5ad2-fb95-4a3b-b4b9-c1a87699b711
elif [ $1 == 'dev' ]
then
export FLOOR_NAME=1OG
export SPACE_NAME="1.001"
export SPACE_SOURCE=03fjvA5B1CWOG33uprLUQT
export SPACE_ISPARTOF=6bfed7de-ccbc-4780-b834-5d8cbf73560f
export DEVICE_NAME="Sensor_block:T&LQ:1138260"
export DEVICE_SOURCE="3TYhTs\$S924vrYvWDC_1_z"
export DEVICE_TAG=air
export DEVICE_ISLOCATEDIN=37124033-c860-43d0-b468-92b58198fbcb
export EQUIPMENT_NAME="Sensor_block:T&LQ:1138260"
export EQUIPMENT_SOURCE="3TYhTs\$S924vrYvWDC_1_z"
export EQUIPMENT_TAG=air
export EQUIPMENT_ISLOCATEDIN=37124033-c860-43d0-b468-92b58198fbcb
export TEST_ID=1234
export FILE_ID=2f6a1ae7-6a88-41a8-b2ba-bbf6f06ccf63
fi
export TARGETAWSACCOUNT=$1
export TOKEN_ENDPOINT=https://myoauthserver.com/oauth/token
export TOKEN_AUDIENCE=https://api.myapplication.com/
export TOKEN_DEFAULT=$(node createToken.js clientDefault)
echo $TOKEN_DEFAULT
export TOKEN_ALICE=$(node createToken.js clientAlice)
echo $TOKEN_ALICE
export TOKEN_BOB=$(node createToken.js clientBob)
echo $TOKEN_BOB
export TOKEN_AUTH=$(node createTokenAuth.js)
echo $TOKEN_AUTH
echo $API_URL
export LOG_REQUESTS=true
protractor test_config.js --suite $TARGETAWSACCOUNT
##protractor test_config.js
Configs
To configure the protractor you will need the configs
config.js
The file where the environment variables are injected into the JS
require('dotenv').config();
module.exports = {
seleniumAddress: process.env.SELENIUM_ADDRESS,
issuer:{
endpoint: process.env.TOKEN_ENDPOINT,
audience: process.env.TOKEN_AUDIENCE,
audience_auth: process.env.AUDIENCE_AUTH
},
params: {
floorName: process.env.FLOOR_NAME,
spaceName: process.env.SPACE_NAME,
spaceSource: process.env.SPACE_SOURCE,
spaceIsPartOf: process.env.SPACE_ISPARTOF,
deviceName: process.env.DEVICE_NAME,
deviceSource: process.env.DEVICE_SOURCE,
deviceTag: process.env.DEVICE_TAG,
deviceIsLocatedIn: process.env.DEVICE_ISLOCATEDIN,
equipName: process.env.EQUIPMENT_NAME,
equipSource: process.env.EQUIPMENT_SOURCE,
equipTag: process.env.EQUIPMENT_TAG,
equipIsLocatedIn: process.env.EQUIPMENT_ISLOCATEDIN,
testID: process.env.TEST_ID,
fileID: process.env.FILE_ID
},
clientDefault: {
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET
},
clientAlice: {
clientId: process.env.ALICE_CLIENT_ID,
clientSecret: process.env.ALICE_CLIENT_SECRET
},
clientBob: {
clientId: process.env.BOB_CLIENT_ID,
clientSecret: process.env.BOB_CLIENT_SECRET
},
clientAuth: {
clientId: process.env.CLIENT_ID_AUTH,
clientSecret: process.env.CLIENT_SECRET_AUTH
},
token:{
default: process.env.TOKEN_DEFAULT,
alice: process.env.TOKEN_ALICE,
bob: process.env.TOKEN_BOB,
auth: process.env.TOKEN_AUTH
},
target:{
url: process.env.URL,
auth_url: process.env.API_AUTH_URL
}
}
test_config.js
require('dotenv').config();
let options = require("./lib/config");
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
exports.config = {
framework: 'jasmine',
seleniumAddress: options.seleniumAddress,
//specs is used for when calling protractor without passing suites to run
specs: ['spec/API_Widgets_tests.js',
'spec/Functional_tests.js',
'spec/API_CRUD_tests.js',
'spec/Negative_tests.js',
'spec/Filters_tests.js',
'spec/Negative_Filters_tests.js',
'spec/UI_tests_Main.js',
'spec/UI_tests.js',
'spec/UI_tests_files.js',
'spec/UI_tests_NavVis',
'spec/Auth_UI_tests.js'],
//Suites defined to run tests on Dev or Stage
suites: {
//dev: 'spec/*.js',
// dev: ['spec/Functional_tests.js',
// 'spec/Negative_tests.js',
// 'spec/Filters_tests.js',
// 'spec/Negative_Filters_tests.js',
// // 'spec/UI_tests.js',
// // 'spec/UI_tests_files.js',
// // 'spec/UI_tests_Main.js',
// // 'spec/UI_tests_template.js',
// 'spec/API_Widgets_tests.js',
// 'spec/API_CRUD_tests.js',
// 'spec/Auth_UI_tests.js'],
dev: ['spec/Auth_UI_tests.js'],
// stage: ['spec/API_CRUD_tests.js',
// 'spec/Negative_tests.js',
// 'spec/Filters_tests.js',
// 'spec/Negative_Filters_tests.js',
// 'spec/API_Widgets_tests.js',
// 'spec/UI_tests.js',
// 'spec/UI_tests_files.js',
// 'spec/API_CRUD_tests.js',
// 'spec/UI_tests_Main.js',
// 'spec/Auth_UI_tests.js']
stage: ['spec/Auth_UI_tests.js']
},
onPrepare: function () {
browser.driver.manage().window().maximize();
jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
savePath: './test/reports/',
screenshotsFolder: 'images',
takeScreenshots: true,
takeScreenshotsOnlyOnFailures: true,
fixedScreenshotName: true,
showPassed: false,
filePrefix: 'SeleniumReport'
// consolidate: false,
// consolidateAll: false
}));
var AllureReporter = require('./node_modules/jasmine-allure-reporter');
jasmine.getEnv().addReporter(new AllureReporter({
resultsDir: 'test/allure-results/'
}));
var jasmineReporters = require('./node_modules/jasmine-reporters');
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'test/reports',
filePrefix: 'xmloutput'
})
)
},
ignoreUncaughtExceptions: true,
capabilities: {
browserName: 'chrome',
noGlobals: false,
binary: 'C:/Program Files/ChromePortable/App/Chrome-bin/chrome.exe',
//shardTestFiles: true,
//maxInstances:7,
chromeOptions: {
useAutomationExtension: false,
args: ["--headless",
"--disable-gpu",
"--disable-browser-side-navigation",
"--disable-infobars",
"--no-sandbox",
"--window-size=1200,900"]
// args: [ "--window-size=1400,900" ]
}
},
// Options to be passed to Jasmine.
jasmineNodeOpts: {
defaultTimeoutInterval: 90000, //increased to 30 seconds
},
params: {
gWidgetID: 'empty',
gCampusID: 'empty'
}
}
Example test
devops/tests/protractor.1602152007.txt.gz · Last modified: (external edit)

