-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1484 from emanueldima/improve-tests
Improve end to end tests
- Loading branch information
Showing
3 changed files
with
62 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Nightmare from 'nightmare'; | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL=20*1000; | ||
|
||
export const nightmareConfig = { | ||
// show: true, | ||
switches: { | ||
'ignore-certificate-errors': true, | ||
}, | ||
}; | ||
|
||
export const B2ACCESS_AUTH_URL = "https://unity.eudat-aai.fz-juelich.de:8443/oauth2-as/oauth2-authz-web-entry"; | ||
|
||
export const B2SHARE_URL = process.env.B2SHARE_URL || process.env.B2SHARE_JSONSCHEMAS_HOST; | ||
export const USER_NAME = process.env.AUTOTEST_USER; | ||
export const USER_PASS = process.env.AUTOTEST_PASS; | ||
export const USER_EMAIL = process.env.AUTOTEST_EMAIL; | ||
|
||
if (!B2SHARE_URL) { | ||
console.log("B2SHARE_URL environment variables not defined!"); | ||
} | ||
|
||
if (!USER_NAME || !USER_PASS || !USER_EMAIL) { | ||
console.log("username or password or email environment variables not defined!"); | ||
} | ||
|
||
export function step(msg) { | ||
console.log(msg, "..."); | ||
} | ||
|
||
export function print_obj(o) { | ||
for (var p in o) { | ||
console.log(p); | ||
} | ||
} | ||
|
||
export async function assertPageContains(page, text) { | ||
let body = await page.evaluate(()=>document.body.textContent); | ||
await expect(body).toContain(text); | ||
} | ||
|
||
export async function assertElementText(page, selector, text) { | ||
const fn = (selector) => { | ||
document.querySelector(selector).innerText | ||
}; | ||
let elementText = await page.evaluate(fn, selector); | ||
return expect(elementText == text); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,40 @@ | ||
import Nightmare from 'nightmare' | ||
import Nightmare from 'nightmare'; | ||
import { B2ACCESS_AUTH_URL, B2SHARE_URL, USER_NAME, USER_PASS, USER_EMAIL, | ||
nightmareConfig, step, print_obj, assertPageContains, assertElementText } from './common'; | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL=20*1000; | ||
|
||
const B2SHARE_URL = "https://b2share.local/" | ||
const B2ACCESS_AUTH_URL = "https://unity.eudat-aai.fz-juelich.de:8443/oauth2-as/oauth2-authz-web-entry" | ||
|
||
const user = process.env.AUTOTEST_USER; | ||
const pass = process.env.AUTOTEST_PASS; | ||
const email = process.env.AUTOTEST_EMAIL; | ||
|
||
if (!user || !pass || !email) { | ||
console.log("user, pass and email environment variables not defined!"); | ||
console.log(user, pass, email); | ||
} | ||
|
||
var nightmare = Nightmare({ | ||
// show: true, | ||
switches: { | ||
'ignore-certificate-errors': true, | ||
}, | ||
}); | ||
|
||
function step(msg) { | ||
console.log(msg, "...") | ||
} | ||
function print_obj(o) { | ||
for (var p in o) { | ||
console.log(p) | ||
} | ||
} | ||
|
||
async function assertPageContains(page, text) { | ||
let body = await page.evaluate(()=>document.body.textContent); | ||
await expect(body).toContain(text); | ||
} | ||
|
||
async function assertElementText(page, selector, text) { | ||
const fn = (selector) => { | ||
document.querySelector(selector).innerText | ||
}; | ||
let elementText = await page.evaluate(fn, selector); | ||
return expect(elementText == text); | ||
} | ||
|
||
describe('Smoke test', function () { | ||
describe('Homepage', function () { | ||
test('well formed homepage', async function () { | ||
let page = nightmare.goto(B2SHARE_URL); | ||
|
||
step("test homepage title"); | ||
let page = Nightmare(nightmareConfig).goto(B2SHARE_URL); | ||
expect(await page.title() == 'B2SHARE'); | ||
|
||
step("wait for menu") | ||
await page.wait('#header-navbar-collapse a'); | ||
|
||
step("wait for records") | ||
await page.wait('#page .home-page .record a'); | ||
}); | ||
}); | ||
|
||
describe('Smoke test2', function () { | ||
describe('Login', function () { | ||
test('user can login', async function () { | ||
let page = nightmare.goto(B2SHARE_URL); | ||
let page = Nightmare(nightmareConfig).goto(B2SHARE_URL); | ||
|
||
step("click on Login"); | ||
await page.wait('#header-navbar-collapse > .user > li > a') | ||
.click('#header-navbar-collapse > .user > li > a'); | ||
|
||
step("check if redirected to B2ACCESS"); | ||
await expect(page.url() == B2ACCESS_AUTH_URL); | ||
|
||
step("check if we are on B2ACCESS unity auth page"); | ||
await page.wait('#AuthenticationUI\\.username'); | ||
await assertPageContains(page, "Login to UNITY OAuth2 Authorization Server"); | ||
|
||
step("authenticate with user1"); | ||
await page.type('#AuthenticationUI\\.username', user) | ||
.type('#WebPasswordRetrieval\\.password', pass) | ||
await page.type('#AuthenticationUI\\.username', USER_NAME) | ||
.type('#WebPasswordRetrieval\\.password', USER_PASS) | ||
.click('#AuthenticationUI\\.authnenticateButton') | ||
.wait('#IdpButtonsBar\\.confirmButton') | ||
.click('#IdpButtonsBar\\.confirmButton'); | ||
|
||
step("check if we are back to B2SHARE"); | ||
expect(page.title() == 'B2SHARE'); | ||
expect(await page.title() == 'B2SHARE'); | ||
|
||
step("wait for menu"); | ||
await page.wait('#header-navbar-collapse a'); | ||
|
||
step("check that the test user is logged in"); | ||
await assertElementText(page, '#header-navbar-collapse > .user > li > a', email); | ||
await assertElementText(page, '#header-navbar-collapse > .user > li > a', USER_EMAIL); | ||
}); | ||
}); |