Skip to content

Commit

Permalink
fix async tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emanueldima committed May 23, 2017
1 parent 67bfb1b commit 113bf35
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions webui/src/__tests__/homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Nightmare from 'nightmare'

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;
Expand All @@ -23,6 +24,11 @@ var nightmare = Nightmare({
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);
Expand All @@ -34,26 +40,31 @@ async function assertElementText(page, selector, text) {
document.querySelector(selector).innerText
};
let elementText = await page.evaluate(fn, selector);
await expect(elementText == text);
return expect(elementText == text);
}

describe('Smoke test', function () {
let page = nightmare.goto('https://b2share.local/');

test('well formed homepage', async function () {
step("test homepage title")
expect(page.title() == 'B2SHARE');
let page = nightmare.goto(B2SHARE_URL);

step("test homepage title");
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 () {
test('user can login', async function () {
let page = nightmare.goto(B2SHARE_URL);

step("click on Login");
await page.click('#header-navbar-collapse > .user > li > a');
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);
Expand All @@ -77,7 +88,5 @@ describe('Smoke test', function () {

step("check that the test user is logged in");
await assertElementText(page, '#header-navbar-collapse > .user > li > a', email);

await page.end();
});
})
});

0 comments on commit 113bf35

Please sign in to comment.