import { element, by, ElementFinder<% if (authenticationType === 'oauth2') { _%>, browser<%_ } %> } from 'protractor'; <%_ let elementGetter = `getText()`; if (enableTranslation) { elementGetter = `getAttribute('jhiTranslate')`; } _%> export class NavBarPage { entityMenu = element(by.id('entity-menu')); accountMenu = element(by.id('account-menu')); adminMenu: ElementFinder; signIn = element(by.id('login')); register = element(by.css('[routerLink="register"]')); signOut = element(by.id('logout')); passwordMenu = element(by.css('[routerLink="password"]')); settingsMenu = element(by.css('[routerLink="settings"]')); constructor(asAdmin?: Boolean) { if (asAdmin) { this.adminMenu = element(by.id('admin-menu')); } } async clickOnEntityMenu() { await this.entityMenu.click(); } async clickOnAccountMenu() { await this.accountMenu.click(); } async clickOnAdminMenu() { await this.adminMenu.click(); } async clickOnSignIn() { await this.signIn.click(); } async clickOnRegister() { await this.signIn.click(); } async clickOnSignOut() { await this.signOut.click(); } async clickOnPasswordMenu() { await this.passwordMenu.click(); } async clickOnSettingsMenu() { await this.settingsMenu.click(); } async clickOnEntity(entityName: string) { await element(by.css('[routerLink="' + entityName + '"]')).click(); } async clickOnAdmin(entityName: string) { await element(by.css('[routerLink="admin/' + entityName + '"]')).click(); } async getSignInPage() { await this.clickOnAccountMenu(); await this.clickOnSignIn(); return new SignInPage(); } <%_ if (authenticationType !== 'oauth2') { _%> async getPasswordPage() { await this.clickOnAccountMenu(); await this.clickOnPasswordMenu(); return new PasswordPage(); } async getSettingsPage() { await this.clickOnAccountMenu(); await this.clickOnSettingsMenu(); return new SettingsPage(); } <%_ } _%> async goToEntity(entityName: string) { await this.clickOnEntityMenu(); await this.clickOnEntity(entityName); } async goToSignInPage() { await this.clickOnAccountMenu(); await this.clickOnSignIn(); } async goToPasswordMenu() { await this.clickOnAccountMenu(); await this.clickOnPasswordMenu(); } async autoSignOut() { await this.clickOnAccountMenu(); await this.clickOnSignOut(); } } export class SignInPage { <%_ if (authenticationType !== 'oauth2') { _%> username = element(by.id('username')); password = element(by.id('password')); loginButton = element(by.css('button[type=submit]')); <%_ } else { _%> username = element(by.name('username')); password = element(by.name('password')); loginButton = element(by.css('input[type=submit]')); <%_ } _%> async setUserName(username) { await this.username.sendKeys(username); } async getUserName() { return this.username.getAttribute('value'); } async clearUserName() { await this.username.clear(); } async setPassword(password) { await this.password.sendKeys(password); } async getPassword() { return this.password.getAttribute('value'); } async clearPassword() { await this.password.clear(); } <%_ if (authenticationType !== 'oauth2') { _%> async autoSignInUsing(username: string, password: string) { await this.setUserName(username); await this.setPassword(password); await this.login(); } <%_ } else { _%> async loginWithOAuth(username: string, password: string) { // Entering non angular site, tell webdriver to switch to synchronous mode. browser.waitForAngularEnabled(false); if (await this.username.isPresent()) { await this.username.sendKeys(username); await this.password.sendKeys(password); await this.loginButton.click(); } else { browser.waitForAngularEnabled(true); } } <%_ } _%> async login() { await this.loginButton.click(); } } <%_ if (authenticationType !== 'oauth2') { _%> export class PasswordPage { currentPassword = element(by.id('currentPassword')); password = element(by.id('newPassword')); confirmPassword = element(by.id('confirmPassword')); saveButton = element(by.css('button[type=submit]')); title = element.all(by.css('h2')).first(); async setCurrentPassword(password) { await this.currentPassword.sendKeys(password); } async setPassword(password) { await this.password.sendKeys(password); } async getPassword() { return this.password.getAttribute('value'); } async clearPassword() { await this.password.clear(); } async setConfirmPassword(confirmPassword) { await this.confirmPassword.sendKeys(confirmPassword); } async getConfirmPassword() { return this.confirmPassword.getAttribute('value'); } async clearConfirmPassword() { await this.confirmPassword.clear(); } async getTitle() { return this.title.<%- elementGetter %>; } async save() { await this.saveButton.click(); } } export class SettingsPage { firstName = element(by.id('firstName')); lastName = element(by.id('lastName')); email = element(by.id('email')); saveButton = element(by.css('button[type=submit]')); title = element.all(by.css('h2')).first(); async setFirstName(firstName) { await this.firstName.sendKeys(firstName); } async getFirstName() { return this.firstName.getAttribute('value'); } async clearFirstName() { await this.firstName.clear(); } async setLastName(lastName) { await this.lastName.sendKeys(lastName); } async getLastName() { return this.lastName.getAttribute('value'); } async clearLastName() { await this.lastName.clear(); } async setEmail(email) { await this.email.sendKeys(email); } async getEmail() { return this.email.getAttribute('value'); } async clearEmail() { await this.email.clear(); } async getTitle() { return this.title.<%- elementGetter %>; } async save() { await this.saveButton.click(); } } <%_ } _%>