From 4c4b6d5ef50213c0bfa7719dd19685835dd40571 Mon Sep 17 00:00:00 2001 From: DStampede Date: Tue, 28 Jan 2020 16:20:28 +0800 Subject: [PATCH] taga pluto --- e2e/src/features/employee/employee.feature | 25 +++ e2e/src/features/security/security.feature | 8 + e2e/src/hooks/generic.hook.ts | 8 + e2e/src/po/dashboard.po.ts | 37 +++++ e2e/src/po/employee.po.ts | 19 +++ e2e/src/po/form.po.ts | 29 ++++ e2e/src/po/form2.po.ts | 38 +++++ e2e/src/po/message.po.ts | 9 ++ e2e/src/po/security.po.ts | 20 +++ .../step_definition/employee.definition.ts | 144 ++++++++++++++++++ .../step_definition/security.definition.ts | 18 +++ 11 files changed, 355 insertions(+) create mode 100644 e2e/src/features/employee/employee.feature create mode 100644 e2e/src/features/security/security.feature create mode 100644 e2e/src/hooks/generic.hook.ts create mode 100644 e2e/src/po/dashboard.po.ts create mode 100644 e2e/src/po/employee.po.ts create mode 100644 e2e/src/po/form.po.ts create mode 100644 e2e/src/po/form2.po.ts create mode 100644 e2e/src/po/message.po.ts create mode 100644 e2e/src/po/security.po.ts create mode 100644 e2e/src/step_definition/employee.definition.ts create mode 100644 e2e/src/step_definition/security.definition.ts diff --git a/e2e/src/features/employee/employee.feature b/e2e/src/features/employee/employee.feature new file mode 100644 index 0000000..7725c67 --- /dev/null +++ b/e2e/src/features/employee/employee.feature @@ -0,0 +1,25 @@ +Feature: Employee + As a user + I should be able to create, read, update, and delete an Employee record + + Scenario: Create an Employee record + Given I am on the dashboard page + When I create an employee record + Then I should see the success message "Success: Data has been added!" + And I should see the employee record in the list + + Scenario: Read an Employee record + Given I am on the actual dashboard page + When I Select an employee + Then I should Read the Employee Status + + Scenario: Delete an Employee record + Given I am on the Present dashboard page + When I delete the employee record + Then It should remove in the Table + + Scenario: Update an Employee record + Given I am on the Recent dashboard page + When I Click the Table on the employee record + Then It should be see the success msg + \ No newline at end of file diff --git a/e2e/src/features/security/security.feature b/e2e/src/features/security/security.feature new file mode 100644 index 0000000..bf1f7f2 --- /dev/null +++ b/e2e/src/features/security/security.feature @@ -0,0 +1,8 @@ +Feature: Security + As a User + I should be able to access the sytem with proper credentials + +Scenario: Login + Given I am on the Login Page + When I log in + Then I should be redirected to dashboard \ No newline at end of file diff --git a/e2e/src/hooks/generic.hook.ts b/e2e/src/hooks/generic.hook.ts new file mode 100644 index 0000000..75bd4b9 --- /dev/null +++ b/e2e/src/hooks/generic.hook.ts @@ -0,0 +1,8 @@ +import {Before, setDefaultTimeout} from 'cucumber'; +import { browser } from 'protractor'; + +Before((Scenario) => { + console.log('hook executed'); + browser.waitForAngularEnabled(false); + setDefaultTimeout (60 * 10000); +}); diff --git a/e2e/src/po/dashboard.po.ts b/e2e/src/po/dashboard.po.ts new file mode 100644 index 0000000..a95a77f --- /dev/null +++ b/e2e/src/po/dashboard.po.ts @@ -0,0 +1,37 @@ +import { element, by } from 'protractor'; +import { FormPage } from './form.po'; + +export class DashboardPage { + static get newEmployeeButton() { + return element(by.buttonText('New Employee')); + } + + static async createEmployee() { + await this.newEmployeeButton.click(); + await FormPage.fillForm(); + await FormPage.addButton.click(); + } + + static get table() { + return element(by.tagName('p-table')); + } + + static get tableRows() { + return this.table.all(by.tagName('tr')); + } + + static get tableNextPageButton() { + return element(by.css('span[class="ui-paginator-icon pi pi-caret-right"]')); + } + + static async checkTableRowForData(data: string) { + let foundData = null; + (await this.tableRows.getText() as any).forEach(trData => { + if (trData.includes('LinKin Park')) { + foundData = trData; + } + }); + + return foundData; + } +} diff --git a/e2e/src/po/employee.po.ts b/e2e/src/po/employee.po.ts new file mode 100644 index 0000000..f2340eb --- /dev/null +++ b/e2e/src/po/employee.po.ts @@ -0,0 +1,19 @@ +import { by, element, ElementFinder, } from 'protractor'; +import { DashboardPage } from './dashboard.po'; + +export class Employee { + + static get delbutton(): ElementFinder { + return element.all(by.buttonText('Delete')).first(); + } + + static get clkbutton(): ElementFinder { + return element (by.css('class["ui-selectable-row ng-star-inserted"]')); + } + static async del() { + await Employee.delbutton.click(); + } + static async clk() { + await Employee.clkbutton.click(); + } +} diff --git a/e2e/src/po/form.po.ts b/e2e/src/po/form.po.ts new file mode 100644 index 0000000..3b46850 --- /dev/null +++ b/e2e/src/po/form.po.ts @@ -0,0 +1,29 @@ +import { element, by, browser } from 'protractor'; + +export class FormPage { + static get form() { + return element(by.tagName('form')); + } + + static getFormControlElement(formControlName: string) { + return element(by.css(`[formcontrolname=${formControlName}]`)); + } + + static get addButton() { + return element(by.buttonText('Add')); + } + + static async fillForm() { + await this.getFormControlElement('firstName').sendKeys('LinKin'); + await this.getFormControlElement('lastName').sendKeys('Park'); + await this.getFormControlElement('country').sendKeys('Korea'); + await this.getFormControlElement('nationality').sendKeys('Kinorian'); + await this.getFormControlElement('company').sendKeys('Ching Ko'); + await this.getFormControlElement('designation').sendKeys('KPOPanget'); + await this.getFormControlElement('workExp').sendKeys('100 years'); + await this.getFormControlElement('dataSource').click(); + // may need to wait for list to load + await browser.sleep(1000); + await element.all(by.tagName('p-dropdownitem')).get(2).click(); + } +} diff --git a/e2e/src/po/form2.po.ts b/e2e/src/po/form2.po.ts new file mode 100644 index 0000000..3c2d00a --- /dev/null +++ b/e2e/src/po/form2.po.ts @@ -0,0 +1,38 @@ +import { element, by, browser } from 'protractor'; + +export class Form2Page { + static get form() { + return element(by.tagName('form')); + } + + static getFormControlElement(formControlName: string) { + return element(by.css(`[formcontrolname=${formControlName}]`)); + } + static get updateButton() { + return element(by.buttonText('Update')); + } + static get clearbutton() { + return element(by.buttonText('Clear')); + } + static async fillForm2() { + await this.getFormControlElement('firstName').clear(); + await this.getFormControlElement('firstName').sendKeys('Ma'); + await this.getFormControlElement('lastName').clear(); + await this.getFormControlElement('lastName').sendKeys('FangHee'); + await this.getFormControlElement('country').clear(); + await this.getFormControlElement('country').sendKeys('China'); + await this.getFormControlElement('nationality').clear(); + await this.getFormControlElement('nationality').sendKeys('Chinese'); + await this.getFormControlElement('company').clear(); + await this.getFormControlElement('company').sendKeys('Ching Chong'); + await this.getFormControlElement('designation').clear(); + await this.getFormControlElement('designation').sendKeys('Corona'); + await this.getFormControlElement('workExp').clear(); + await this.getFormControlElement('workExp').sendKeys('1000000 years'); + await this.getFormControlElement('dataSource').click(); + await browser.sleep(1000); + // may need to wait for list to load + await element.all(by.tagName('p-dropdownitem')).get(4).click(); + await browser.sleep(1000); + } +} diff --git a/e2e/src/po/message.po.ts b/e2e/src/po/message.po.ts new file mode 100644 index 0000000..b88f9ea --- /dev/null +++ b/e2e/src/po/message.po.ts @@ -0,0 +1,9 @@ +import { element, by } from 'protractor'; + +export class MessagePage { + static get successMessage() { + return element(by.id('success-message')); + } + + +} diff --git a/e2e/src/po/security.po.ts b/e2e/src/po/security.po.ts new file mode 100644 index 0000000..1601361 --- /dev/null +++ b/e2e/src/po/security.po.ts @@ -0,0 +1,20 @@ +import { ElementFinder, element, by, Button} from 'protractor'; + +export class SecurityPageObject { + static get usernamefield(): ElementFinder { + return element (by.id('username-field')); + } + + static get passwordfield(): ElementFinder { + return element (by.id('password-field')); + + } + static get loginbutton(): ElementFinder { + return element (by.css('button[label="Login"]')); + } + static async login() { + await SecurityPageObject.usernamefield.sendKeys('asd'); + await SecurityPageObject.passwordfield.sendKeys('asd'); + await SecurityPageObject.loginbutton.click(); + } +} diff --git a/e2e/src/step_definition/employee.definition.ts b/e2e/src/step_definition/employee.definition.ts new file mode 100644 index 0000000..8427011 --- /dev/null +++ b/e2e/src/step_definition/employee.definition.ts @@ -0,0 +1,144 @@ +import { Given, Then, When } from 'cucumber'; +import { browser, by, element } from 'protractor'; +import { DashboardPage } from '../po/dashboard.po'; +import { Employee } from '../po/employee.po'; +import { MessagePage } from '../po/message.po'; +import { Alert } from 'selenium-webdriver'; +import { Form2Page } from '../po/form2.po'; +import { FormPage } from '../po/form.po'; + +const chai = require('chai').use(require('chai-as-promised')); +const expect = chai.expect; +​ +///////////////////////////////// Create //////////////////////////////////////////////// + +// tslint:disable-next-line: only-arrow-functions +Given('I am on the dashboard page', async function() { + const currentUrl = await browser.getCurrentUrl(); + const dashboardUrl = 'http://localhost:4200/dashboard'; +​ + if (currentUrl !== dashboardUrl) { + await browser.get(dashboardUrl); + } +​ + const dashboardElement = element(by.tagName('app-dashboard')); + if (!(await dashboardElement.isPresent())) { + throw Error('The user is not on the dashboard page'); + } +}); +​ +// tslint:disable-next-line: only-arrow-functions +When('I create an employee record', async function() { + await DashboardPage.createEmployee(); + await browser.sleep(1000); +}); +​ +// tslint:disable-next-line: only-arrow-functions +Then('I should see the success message {string}', async function(expectedMessage: string) { + const messageObject = MessagePage.successMessage; + expect(true, 'The success message was not displayed').to.equal(await messageObject.isPresent()); + expect(await messageObject.getText(), 'The success message did not match the expected message').to.equal(expectedMessage); +}); +​ +// tslint:disable-next-line: only-arrow-functions +Then('I should see the employee record in the list', async function() { + let rowData; +​ + if (!(await DashboardPage.checkTableRowForData('LinKin'))) { + await DashboardPage.tableNextPageButton.click(); + await browser.sleep(1000); + } +​ + rowData = (await DashboardPage.checkTableRowForData('LinKin') as string); + rowData = (rowData.replace('Delete', ' ')).trim(); + expect('8 LinKin Park Korea Kinorian Ching Ko KPOPanget 100 years Monster Gulf').to.equal(rowData); + await browser.sleep(2000); + + await element(by.css('i[class="pi pi-times"]')).click(); +}); + +////////////////////////////////// Update //////////////////////////////////////////// + +// tslint:disable-next-line: only-arrow-functions +Given('I am on the Recent dashboard page', async function() { + const currentUrl = await browser.getCurrentUrl(); + const dashboardUrl = 'http://localhost:4200/dashboard'; +​ +}); + +// tslint:disable-next-line: only-arrow-functions +When('I Click the Table on the employee record', async function() { + element(by.css('td')).click(); + await browser.sleep(1000); + // await Form2Page.clearbutton.click(); + await browser.sleep(1000); + await Form2Page.fillForm2(); + await Form2Page.updateButton.click(); + await browser.sleep(1000); + await element(by.css('i[class="pi pi-times"]')).click(); + await browser.sleep(2000); +}); + +// tslint:disable-next-line: only-arrow-functions +Then('It should be see the success msg', async function() { + expect (await browser.getCurrentUrl()).to.equal('http://localhost:4200/dashboard'); + await browser.sleep(1000); + await element(by.linkText('Logout')).click(); + await browser.sleep(1000); +}); + +////////////////////////////////// Delete //////////////////////////////////////////// + +// tslint:disable-next-line: only-arrow-functions +Given('I am on the Present dashboard page', async function() { + const currentUrl = await browser.getCurrentUrl(); + const dashboardUrl = 'http://localhost:4200/dashboard'; + +}); + +// tslint:disable-next-line: only-arrow-functions +When('I delete the employee record', async function() { + let dataRow; +​ + if (!(await DashboardPage.checkTableRowForData('LinKin'))) { + await DashboardPage.tableNextPageButton.click(); + await browser.sleep(1000); + } +​ + dataRow = (await DashboardPage.checkTableRowForData('LinKin') as string); + dataRow = (dataRow.replace('Delete', '')).trim(); + expect('8 LinKin Park Korea Kinorian Ching Ko KPOPanget 100 years Monster Gulf').to.equal(dataRow); + await browser.sleep(1000); + await Employee.del(); + await browser.sleep(1000); + const ale: Alert = browser.switchTo().alert(); + ale.accept(); + await browser.sleep(1000); + +}); + +// tslint:disable-next-line: only-arrow-functions +Then('It should remove in the Table', async function() { +​ const currentUrl = await browser.getCurrentUrl(); + const dashboardUrl = 'http://localhost:4200/dashboard'; +}); + +////////////////////////////////// Read //////////////////////////////////////////// + +// tslint:disable-next-line: only-arrow-functions +Given('I am on the actual dashboard page', async function() { + const currentUrl = await browser.getCurrentUrl(); + const dashboardUrl = 'http://localhost:4200/dashboard'; +}); + +// tslint:disable-next-line: only-arrow-functions +When('I Select an employee', async function() { +}); + +// tslint:disable-next-line: only-arrow-functions +Then('I should Read the Employee Status', async function() { + const currentUrl = await browser.getCurrentUrl(); + const dashboardUrl = 'http://localhost:4200/dashboard'; + +}); + diff --git a/e2e/src/step_definition/security.definition.ts b/e2e/src/step_definition/security.definition.ts new file mode 100644 index 0000000..fa9c930 --- /dev/null +++ b/e2e/src/step_definition/security.definition.ts @@ -0,0 +1,18 @@ +import {Given, When, Then } from 'cucumber'; +import { browser, element, by } from 'protractor'; +import { SecurityPageObject } from '../po/security.po'; + +const chai = require('chai').use(require('chai-as-promised')); +const expect = chai.expect; + +Given('I am on the Login Page', async function() { + await browser.get('http://localhost:4200/login'); +}); +When('I log in', async function() { + await SecurityPageObject.login(); + await browser.sleep(1000); +}); +Then('I should be redirected to dashboard', async function() { + expect (await browser.getCurrentUrl()).to.equal('http://localhost:4200/dashboard'); + await browser.sleep(1000); +});