small refactoring of login / logout

This commit is contained in:
Adina Parpalita
2017-11-10 15:39:15 +02:00
parent 382609df95
commit dab38d5a47
4 changed files with 19 additions and 9 deletions

View File

@@ -18,6 +18,7 @@
import { browser, ExpectedConditions as EC, promise } from 'protractor';
import { LoginComponent } from '../components/components';
import { Page } from './page';
import { Utils } from '../utilities/utils';
import {
ADMIN_USERNAME,
@@ -38,17 +39,17 @@ export class LoginPage extends Page {
load(): promise.Promise<any> {
return super.load().then(() => {
const { submitButton } = this.login;
const hasSumbitButton = EC.presenceOf(submitButton);
const hasSubmitButton = EC.presenceOf(submitButton);
return browser.wait(hasSumbitButton, BROWSER_WAIT_TIMEOUT)
.then(() => browser.executeScript('window.localStorage.clear();'))
.then(() => browser.executeScript('window.sessionStorage.clear();'))
.then(() => browser.driver.manage().deleteAllCookies());
return browser.wait(hasSubmitButton, BROWSER_WAIT_TIMEOUT)
.then(() => Utils.clearLocalStorage())
.then(() => browser.manage().deleteAllCookies());
});
}
loginWith(username: string, password: string): promise.Promise<void> {
return this.login.enterCredentials(username, password).submit();
loginWith(username: string, password?: string): promise.Promise<void> {
const pass = password || username;
return this.login.enterCredentials(username, pass).submit();
}
loginWithAdmin(): promise.Promise<any> {

View File

@@ -18,6 +18,7 @@
import { promise } from 'protractor';
import { Page } from './page';
import { APP_ROUTES } from '../configs';
import { Utils } from '../utilities/utils';
export class LogoutPage extends Page {
/** @override */
@@ -27,6 +28,8 @@ export class LogoutPage extends Page {
/** @override */
load(): promise.Promise<any> {
return super.load();
return super.load()
.then(() => Utils.clearLocalStorage())
.then(() => Utils.clearSessionStorage());
}
}

View File

@@ -35,7 +35,7 @@ export class PeopleApi extends RepoApi {
.catch(this.handleError);
}
createUser(username: string, password: string, details?: Person): Promise<any> {
createUser(username: string, password?: string, details?: Person): Promise<any> {
const person: Person = new Person(username, password, details);
const onSuccess = (response) => response;
const onError = (response) => {

View File

@@ -27,4 +27,10 @@ export class Utils {
static clearLocalStorage(): promise.Promise<any> {
return browser.executeScript('window.localStorage.clear();');
}
// session storage
static clearSessionStorage(): promise.Promise<any> {
return browser.executeScript('window.sessionStorage.clear();');
}
}