Skip to content

Commit

Permalink
Merge pull request #1484 from emanueldima/improve-tests
Browse files Browse the repository at this point in the history
Improve end to end tests
  • Loading branch information
emanueldima authored May 31, 2017
2 parents adc10c0 + 9916580 commit 03242eb
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 63 deletions.
3 changes: 3 additions & 0 deletions webui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"postinstall": "./copy_files.sh",
"test": "jest"
},
"jest": {
"modulePathIgnorePatterns": ["common.js"]
},
"devDependencies": {
"babel-core": "^6.2.1",
"babel-jest": "^20.0.0",
Expand Down
48 changes: 48 additions & 0 deletions webui/src/__tests__/common.js
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);
}
74 changes: 11 additions & 63 deletions webui/src/__tests__/homepage.js
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);
});
});

0 comments on commit 03242eb

Please sign in to comment.