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

View File

@@ -18,6 +18,7 @@
import { promise } from 'protractor'; import { promise } from 'protractor';
import { Page } from './page'; import { Page } from './page';
import { APP_ROUTES } from '../configs'; import { APP_ROUTES } from '../configs';
import { Utils } from '../utilities/utils';
export class LogoutPage extends Page { export class LogoutPage extends Page {
/** @override */ /** @override */
@@ -27,6 +28,8 @@ export class LogoutPage extends Page {
/** @override */ /** @override */
load(): promise.Promise<any> { 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); .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 person: Person = new Person(username, password, details);
const onSuccess = (response) => response; const onSuccess = (response) => response;
const onError = (response) => { const onError = (response) => {

View File

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