Commit ce6f0ed4 authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg

Major update test set

parent 933c066b
const moment = require('moment');
var ts = moment().format('YYYY-MM-DD HH:mm')
exports.config = {
user: process.env.BROWSERSTACK_USERNAME || 'BROWSERSTACK_USERNAME',
key: process.env.BROWSERSTACK_ACCESS_KEY || 'BROWSERSTACK_ACCESS_KEY',
updateJob: false,
specs: [
'./tests/specs/dataporten-test.js'
],
exclude: [],
commonCapabilities: {
build: 'Development play.oauth.no Dataporten UI Test',
"browserstack.debug": true,
name: 'Dataporten UI Test',
},
capabilities: [
{
os: "WINDOWS", os_version: "10",
browser: "chrome",
browser_version: "62"
},
// {
// os: "WINDOWS", os_version: "10",
// browser: "firefox",
// browser_version: "57"
// },
// {
// os: "WINDOWS", os_version: "10",
// browser: "chrome",
// browser_version: "14"
// },
// {
// os: "WINDOWS", os_version: "7",
// browser: "IE",
// browser_version: "8"
// },
// {
// os: "WINDOWS", os_version: "7",
// browser: "firefox",
// browser_version: "3.6"
// },
// {
// os: "OS X", os_version: "Sierra",
// browser: "safari",
// browser_version: "10"
// },
// {
// os: "OS X", os_version: "Snow Leopard",
// browser: "safari",
// browser_version: "5.1"
// },
],
logLevel: 'silent', // verbose
coloredLogs: true,
screenshotPath: './errorShots/',
baseUrl: '',
waitforTimeout: 5000,
connectionRetryTimeout: 90000,
connectionRetryCount: 3,
framework: 'mocha',
mochaOpts: {
ui: 'bdd',
timeout: 25000
}
}
// Code to support common capabilities
exports.config.capabilities.forEach(function(caps){
for(var i in exports.config.commonCapabilities) caps[i] = caps[i] || exports.config.commonCapabilities[i];
caps.name = exports.config.commonCapabilities.name + ' ' + ts
});
......@@ -47,9 +47,9 @@ exports.config = {
// browser_version: "3.6"
// },
{
os: "OS X", os_version: "High Sierra",
os: "OS X", os_version: "Sierra",
browser: "safari",
browser_version: "11"
browser_version: "10"
},
// {
// os: "OS X", os_version: "Snow Leopard",
......
const uuidv4 = require('uuid/v4')
var assert = require('assert');
class Page {
constructor(session) {
this.session = session
this.browser = session.browser
}
debug() {
this.browser.screenshot()
console.log(" ")
console.log(" ====== Page " + this.browser.getUrl())
console.log(" Type : " + this.constructor.name)
console.log(" Title : " + this.browser.getTitle())
console.log(" ")
}
}
class LoginPage extends Page {
login(u, p) {
if (!this.browser.isExisting('[id=username]')) {
console.log("Cannot find username, making screenshot")
this.browser.screenshot()
}
this.browser
.setValue('[id=username]', u)
.setValue('[id=password]', p)
.click('input.submit')
this.session.waitForURL('/simplesaml/module.php/feide', false)
return this.session.detectPage()
}
}
class PreProdWarningPage extends Page {
skip() {
assert(this.browser.isExisting('#yesbutton'), 'Expecting a YES button on the preprodwarning page')
this.browser.click('#yesbutton')
console.log("About to waitforurl", this.browser.getUrl() )
this.session.waitForURL('/simplesaml/module.php/preprodwarning/showwarning.php', false)
// this.session.detectPage()
this.session.waitForURL('/simplesaml/saml2/idp/SSOService.php', false)
return this.session.detectPage()
}
}
class AuthorizationPage extends Page {
acceptTermsOfUse() {
assert(browser.getTitle() === 'Authorization Required', "Title should be Authorization Required")
this.browser
.click('a=Dataportens personvernerklæring')
this.browser
.waitForVisible('button=Lukk')
this.browser
.screenshot()
.click('button=Lukk')
this.browser
.waitForVisible('#bruksvilkar')
this.browser
.click('#bruksvilkar')
this.browser
.waitForVisible('#submit')
this.browser
.screenshot()
this.browser
.click('#submit')
return this.session.detectPage()
}
}
class CompletedPage extends Page {
}
class DiscoveryPage extends Page {
search(term) {
this.browser.setValue('[id=usersearch]', 'UNIN')
return this
}
setLang() {
this.browser.click('a=Bokmål')
this.browser.waitForText('p=Feide testbrukere', 3000);
return this
}
selectOther() {
assert(this.browser.isExisting('h3=Velg hvilken brukerkonto du vil logge inn med'),
"Page should have the header for the account chooser")
this.browser.click('[id=altlogin]')
this.browser.waitForText('h1=Velg hvordan du vil logge inn')
return this
}
select(term) {
// browser.click('p=Feide testbrukere')
assert(this.browser.isExisting('p=' + term), "Can find term " + term + " on discovery page")
console.log(" EXISTS " + (this.browser.isExisting('p=' + term) ? 'YES ' : 'NO'))
console.log("About to click on " + term + " on url " + browser.getUrl())
this.browser.click('p=' + term)
this.session.waitForURL('://authengine.paas2.uninett.no/', false)
return this.session.detectPage()
}
selectOtherTestuser() {
let term = 'Feide testbrukere'
assert(this.browser.isExisting('p=' + term), "Can find term " + term + " on discovery page")
this.browser.click('p=' + term)
this.browser.waitForVisible('p=Logg ut for å logge inn igjen med en annen brukerkonto ved Feide testbruker')
this.browser.click('p=Logg ut for å logge inn igjen med en annen brukerkonto ved Feide testbruker')
this.session.waitForURL('://authengine.paas2.uninett.no/', false)
return this.session.detectPage()
}
}
class Session {
constructor(browser) {
this.browser = browser
this.state = uuidv4()
}
end() {
this.browser.end()
}
urlMatch(term) {
// console.log("URL MATCH look for [" + term + "] in " + this.browser.getUrl())
// if (this.browser.getUrl().indexOf(term) > -1) {
// console.log("MATCH ON " + term + " " + this.browser.getUrl())
// }
return (this.browser.getUrl().indexOf(term) > -1)
}
detectPage() {
console.log("")
console.log(" Detecting " + this.browser.getUrl())
console.log("")
if (this.urlMatch('/simplesaml/module.php/feide')) {
return new LoginPage(this)
}
if (this.urlMatch('/simplesaml/module.php/preprodwarning/showwarning.php')) {
return new PreProdWarningPage(this)
}
if (this.urlMatch('/accountchooser')) {
return new DiscoveryPage(this)
}
if (this.urlMatch('play.oauth.no/callback#access_token=')) {
return new CompletedPage(this)
}
if (this.urlMatch('/oauth/authorization')) {
return new AuthorizationPage(this)
}
throw new Error("Cannot detect which kind of Page we landed on: " + this.browser.getUrl())
}
waitForURL(term, hit) {
console.log(" -- wait for [" + term + "] in " + (hit ? 'NORMAL' : 'INVERSE'))
return this.browser.waitUntil(() => {
const match = this.urlMatch(term)
if (hit && match) console.log("MATCH ON " + term + " " + this.browser.getUrl())
if (!hit && !match) console.log("MATCH ON INVERSE " + term + " " + this.browser.getUrl())
if (hit && match) return true;
if (!hit && !match) return true;
return false;
}, 5000);
}
auth() {
var url = 'https://authengine.paas2.uninett.no/oauth/authorization?response_type=token&state=' +
this.state +
'&redirect_uri=https%3A%2F%2Fplay.oauth.no%2Fcallback&client_id=fbc138bb-432d-4c0c-b4b2-ef10aaa02db2'
this.browser.url(url);
this.waitForURL('oauth/authorization', false)
return this.detectPage()
// this.browser.pause(2000)
// this.browser.screenshot()
// this.browser.end()
}
}
exports.Session = Session
exports.LoginPage = LoginPage
exports.PreProdWarningPage = PreProdWarningPage
exports.DiscoveryPage = DiscoveryPage
exports.CompletedPage = CompletedPage
exports.AuthorizationPage = AuthorizationPage
......@@ -5,6 +5,7 @@
"description": "Selenium examples for WebdriverIO and BrowserStack Automate",
"scripts": {
"test": "npm run single && npm run local && npm run parallel",
"dev": "./node_modules/.bin/wdio conf/dataporten-test.conf.js",
"start": "./node_modules/.bin/wdio conf/dataporten.conf.js"
},
"repository": {
......@@ -24,6 +25,7 @@
"dependencies": {
"browserstack-local": "^1.0.0",
"moment": "^2.19.2",
"uuid": "^3.1.0",
"webdriverio": "^4.0.5"
},
"devDependencies": {
......
var assert = require('assert');
var Dataporten = require('../../lib/Dataporten')
var settings = {
oauthserver: {
inputAuthorization: "https://authengine.paas2.uninett.no/oauth/authorization",
inputToken: "https://authengine.paas2.uninett.no/oauth/token",
inputUserinfo: "https://authengine.paas2.uninett.no/openid/userinfo",
inputClientid: "fbc138bb-432d-4c0c-b4b2-ef10aaa02db2"
},
users: {
"test": {
"username": "asbjorn_elevg",
"password": "1qaz"
},
"test2": {
"username": "bjorg_laererg",
"password": "2wsx"
}
}
}
var dp = new Dataporten.Session(browser)
let page
describe('Login for the first time', function() {
it('initiate authentication', function () {
page = dp.auth()
assert(page instanceof Dataporten.DiscoveryPage, 'Expected the discovery page first time when authenticating')
});
it('set language', function () {
page = page.setLang()
});
it('incremental search UNINETT', function () {
page = page.search('UNIN')
});
it('Select testusers on the discovery page', function () {
page = page.select('Feide testbrukere')
assert(page instanceof Dataporten.LoginPage, 'Expected Feide login page after discovery')
});
it('Authenticate with a test user on the login page', function () {
page = page.login(settings.users.test.username, settings.users.test.password)
console.log(" ==============> Step 6 After authentication")
page.debug()
if (page instanceof Dataporten.PreProdWarningPage) {
page = page.skip()
console.log(" ==============> Step 7 PreProdWarningPage")
page.debug()
}
if (page instanceof Dataporten.AuthorizationPage) {
page = page.acceptTermsOfUse()
console.log(" ==============> Step 8 AuthorizationPage")
page.debug()
}
assert(page instanceof Dataporten.CompletedPage, 'Expected returned after successfull authz')
page = dp.auth()
assert(page instanceof Dataporten.DiscoveryPage, 'Expected the discovery page second time when authenticating')
console.log(" ==============> Step 8 Authenticateion second time")
page.debug()
page = page.selectOther()
page = page.selectOtherTestuser()
console.log(" ==============> Step 9 Selecting other")
page.debug()
assert(page instanceof Dataporten.LoginPage, 'Expected Feide login page after discovery')
page = page.login(settings.users.test2.username, settings.users.test2.password)
if (page instanceof Dataporten.PreProdWarningPage) {
page = page.skip()
console.log(" ==============> Step 7 PreProdWarningPage")
page.debug()
}
if (page instanceof Dataporten.AuthorizationPage) {
page = page.acceptTermsOfUse()
console.log(" ==============> Step 8 AuthorizationPage")
page.debug()
}
page = dp.auth()
assert(page instanceof Dataporten.DiscoveryPage, 'Expected the discovery page third time when authenticating')
page.debug()
});
});
var assert = require('assert');
var Dataporten = require('../../../lib/Dataporten')
var settings = {
oauthserver: {
......@@ -15,7 +16,6 @@ var settings = {
}
}
describe('Prepare play.oauth.no', function() {
it('can find search results', function () {
browser
......@@ -24,6 +24,7 @@ describe('Prepare play.oauth.no', function() {
browser
.click('a=OAuth Server Configuration')
browser.waitForVisible('#inputUserinfo')
for (var key in settings.oauthserver) {
browser.setValue('[id=' + key + ']', settings.oauthserver[key])
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment