From e9f964450a2397885dd158328463bd602c69fb6b Mon Sep 17 00:00:00 2001 From: ardengatz Date: Tue, 28 Jan 2020 13:44:17 +0800 Subject: [PATCH 1/4] Full CRUD --- e2e/src/feature/Read/read.feature | 11 ++ e2e/src/feature/creation/creation.feature | 10 ++ e2e/src/feature/delete/delete.feature | 9 ++ e2e/src/feature/security/security.feature | 10 ++ e2e/src/feature/update/update.feature | 10 ++ e2e/src/hooks/generic.hooks.ts | 8 ++ e2e/src/po/creation.po.ts | 57 ++++++++++ e2e/src/po/dashboard.po.ts | 80 ++++++++++++++ e2e/src/po/message.po.ts | 11 ++ e2e/src/po/security.po.ts | 23 ++++ .../steps_definition/creation_definitions.ts | 58 ++++++++++ e2e/src/steps_definition/delete_definition.ts | 47 ++++++++ e2e/src/steps_definition/read_definition.ts | 103 ++++++++++++++++++ .../steps_definition/security_definitions.ts | 21 ++++ e2e/src/steps_definition/update_definition.ts | 63 +++++++++++ 15 files changed, 521 insertions(+) create mode 100644 e2e/src/feature/Read/read.feature create mode 100644 e2e/src/feature/creation/creation.feature create mode 100644 e2e/src/feature/delete/delete.feature create mode 100644 e2e/src/feature/security/security.feature create mode 100644 e2e/src/feature/update/update.feature create mode 100644 e2e/src/hooks/generic.hooks.ts create mode 100644 e2e/src/po/creation.po.ts create mode 100644 e2e/src/po/dashboard.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/steps_definition/creation_definitions.ts create mode 100644 e2e/src/steps_definition/delete_definition.ts create mode 100644 e2e/src/steps_definition/read_definition.ts create mode 100644 e2e/src/steps_definition/security_definitions.ts create mode 100644 e2e/src/steps_definition/update_definition.ts diff --git a/e2e/src/feature/Read/read.feature b/e2e/src/feature/Read/read.feature new file mode 100644 index 0000000..f0b16ed --- /dev/null +++ b/e2e/src/feature/Read/read.feature @@ -0,0 +1,11 @@ +@Read + Feature: Read + As a User + I should be able to see the employee table + + Scenario: Read + + Given I redirected on the dashboard + When I browse the table + Then I should see the details of different employees + \ No newline at end of file diff --git a/e2e/src/feature/creation/creation.feature b/e2e/src/feature/creation/creation.feature new file mode 100644 index 0000000..e750215 --- /dev/null +++ b/e2e/src/feature/creation/creation.feature @@ -0,0 +1,10 @@ +@Creation + Feature: Creation + As a User + I should be able to create a new Employee + + Scenario: Create + Given I am on the dashboard + When I create an Employee + Then I should see the success message "Success: Data has been added!" + And I should see an employee should be added on the list diff --git a/e2e/src/feature/delete/delete.feature b/e2e/src/feature/delete/delete.feature new file mode 100644 index 0000000..0e223eb --- /dev/null +++ b/e2e/src/feature/delete/delete.feature @@ -0,0 +1,9 @@ +@Delete + Feature: Delete + As a User + I should be able to delete an employee detail + + Scenario: Delete + Given I am still on the dashboard + When I deleted an Employee + Then The deleted data will not be shown in the table diff --git a/e2e/src/feature/security/security.feature b/e2e/src/feature/security/security.feature new file mode 100644 index 0000000..365fa54 --- /dev/null +++ b/e2e/src/feature/security/security.feature @@ -0,0 +1,10 @@ +@Security + Feature: Security + As a User + I should be able to access the system with proper credentials + + Scenario: Login + Given I am on the login page + When I log in + Then I should be redirected to the dashboard + diff --git a/e2e/src/feature/update/update.feature b/e2e/src/feature/update/update.feature new file mode 100644 index 0000000..544faaf --- /dev/null +++ b/e2e/src/feature/update/update.feature @@ -0,0 +1,10 @@ +@Update + Feature: Update + As a User + I should be able to edit employee details + + Scenario: Update + Given I am on the dashboard2 + When I updated an Employee + Then I should see the updated success message "Data has been updated!" + And I should see the updated data on the table diff --git a/e2e/src/hooks/generic.hooks.ts b/e2e/src/hooks/generic.hooks.ts new file mode 100644 index 0000000..8de434e --- /dev/null +++ b/e2e/src/hooks/generic.hooks.ts @@ -0,0 +1,8 @@ +import {BeforeAll, setDefaultTimeout } from 'cucumber'; +import { browser } from 'protractor'; + +BeforeAll(async() => { + console.log('hook executed'); + browser.waitForAngularEnabled(false); + setDefaultTimeout(60 *10000); +}); \ No newline at end of file diff --git a/e2e/src/po/creation.po.ts b/e2e/src/po/creation.po.ts new file mode 100644 index 0000000..e531277 --- /dev/null +++ b/e2e/src/po/creation.po.ts @@ -0,0 +1,57 @@ +import { element, by, ElementFinder, logging, browser } from 'protractor'; + + + +export class FormPage { + + // static get form() { + // return element(by.tagName('form')); + // } + + static get updateButton() { + return element(by.buttonText('Update')); + } + + static get newEmployeeButton(): ElementFinder{ + return element(by.id('new-employee')); + } + + static getFormControlElement(formControlName: string) { + return element(by.css(`[formcontrolname=${formControlName}]`)); + } + + static get addbuttonEmployee(): ElementFinder{ + return element(by.css('[ng-reflect-label="Add"]')); + } + + static async fillForm(){ + // await this.newEmployeeButton.click(); + + await this.getFormControlElement('firstName').sendKeys('Arden'); + await this.getFormControlElement('lastName').sendKeys('Gatdula'); + await this.getFormControlElement('country').sendKeys('Japan'); + await this.getFormControlElement('nationality').sendKeys('Nihonjin'); + await this.getFormControlElement('company').sendKeys('TitusUniversal'); + await this.getFormControlElement('designation').sendKeys('CEO'); + await this.getFormControlElement('workExp').sendKeys('69years'); + await this.getFormControlElement('dataSource').click(); + // browser.executeScript('window.scrollTo(0,document.body.scrollHeight)'); + // await browser.executeScript("arguments[0].scrollIntoView()", this.addbuttonEmployee ); + await element.all(by.tagName('p-dropdownitem')).get(1).click(); + } + + // static async updateForm(){ + // await this.getFormControlElement('firstName').sendKeys('Brenden'); + // await this.getFormControlElement('lastName').sendKeys('Wagner'); + // await this.getFormControlElement('country').sendKeys('Japan'); + // await this.getFormControlElement('nationality').sendKeys('Nihonjin'); + // await this.getFormControlElement('company').sendKeys('TitusUniversal'); + // await this.getFormControlElement('designation').sendKeys('CEO'); + // await this.getFormControlElement('workExp').sendKeys('69years'); + // await this.getFormControlElement('dataSource').click(); + // // browser.executeScript('window.scrollTo(0,document.body.scrollHeight)'); + // // await browser.executeScript("arguments[0].scrollIntoView()", this.addbuttonEmployee ); + // await element.all(by.tagName('p-dropdownitem')).get(1).click(); + // await this.updateButton.click(); + // } +} diff --git a/e2e/src/po/dashboard.po.ts b/e2e/src/po/dashboard.po.ts new file mode 100644 index 0000000..58aa1af --- /dev/null +++ b/e2e/src/po/dashboard.po.ts @@ -0,0 +1,80 @@ +import { element, by, browser } from 'protractor'; +import { FormPage } from './creation.po'; +​import { Alert } from 'selenium-webdriver'; + +export class DashboardPage { + + // static get tableFiles(){ + // return expect(element(by.tagName('table'))); + // } + + static get newEmployeeButton() { + return element(by.buttonText('New Employee')); + } +​ + static get deleteEmployeeButton(){ + return element(by.buttonText('Delete')); + } + + static get alertButtonOk(){ + let ale:Alert = browser.switchTo().alert(); + return ale; + } + + // static get clickTable(){ + // return this.table.all(by.tagName('tr')); + // } + + + static async createEmployee() { + await this.newEmployeeButton.click(); + await FormPage.fillForm(); + await FormPage.addbuttonEmployee.click(); + + } + + static async deleteEmployee(){ + await this.deleteEmployeeButton.click(); + await this.alertButtonOk.accept(); + } + + static async updateEmployee(){ + // await this.clickTable.click(); + await this.table.click(); + await element(by.css('input[formcontrolname="nationality"]')).clear(); + await element(by.css('input[formcontrolname="nationality"]')).sendKeys("Japanese"); + await element(by.css('input[formcontrolname="company"]')).clear(); + await element(by.css('input[formcontrolname="company"]')).sendKeys("Titus"); + await element(by.css('input[formcontrolname="country"]')).clear(); + await element(by.css('input[formcontrolname="country"]')).sendKeys("Japan"); + // await FormPage.updateForm(); + await FormPage.updateButton.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 get tableBackPageButton() { + return element(by.css('span[class="ui-paginator-icon pi pi-caret-left"]')); + } +​ + static async checkTableRowForData(data: string) { + let foundData = null; + (await this.tableRows.getText() as any).forEach(trData => { + if (trData.includes(data)) { + foundData = trData; + } + }); +​ + return foundData; + } +} \ No newline at end of file diff --git a/e2e/src/po/message.po.ts b/e2e/src/po/message.po.ts new file mode 100644 index 0000000..655fcb0 --- /dev/null +++ b/e2e/src/po/message.po.ts @@ -0,0 +1,11 @@ +import { element, by } from 'protractor'; +​ +export class MessagePage { + static get successMessage() { + return element(by.id('success-message')); + } +​ +​ static get updatedMessage() { + return element(by.css('span[class="ui-messages-detail ng-tns-c3-2 ng-star-inserted"]')); + } +} \ No newline at end of file diff --git a/e2e/src/po/security.po.ts b/e2e/src/po/security.po.ts new file mode 100644 index 0000000..822eae2 --- /dev/null +++ b/e2e/src/po/security.po.ts @@ -0,0 +1,23 @@ +import { element, by, ElementFinder, logging, browser } from 'protractor'; + +export class SecurityPage { + + 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 this.usernameField.sendKeys('asd'); + await this.passwordField.sendKeys('asd'); + await this.loginButton.click(); + } +} diff --git a/e2e/src/steps_definition/creation_definitions.ts b/e2e/src/steps_definition/creation_definitions.ts new file mode 100644 index 0000000..2b63c94 --- /dev/null +++ b/e2e/src/steps_definition/creation_definitions.ts @@ -0,0 +1,58 @@ +import {Given, When, Then} from 'cucumber'; +import { SecurityPage } from '../po/security.po'; +import { browser, element, by, ElementFinder} from 'protractor'; +import { FormPage } from '../po/creation.po'; +import { DashboardPage } from '../po/dashboard.po'; +import { MessagePage } from '../po/message.po'; + +const chai = require('chai').use(require('chai-as-promised')); +const expect = chai.expect; + +Given('I am on the dashboard', async function () { + console.log('1st hurdle'); + + if(await browser.getCurrentUrl()==="http://localhost:4200/dashboard"){ + return true; + } + else{ + throw Error('The user is not on the dashboard page'); + + } + + }); + +When('I create an Employee', async function () { + + console.log('2nd hurdle'); + // SecurityPage.login(); + + await DashboardPage.createEmployee(); + + console.log('Success Creation'); + + }); + +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); + console.log('1st then working(success)') + }); + +Then('I should see an employee should be added on the list', async function () { + +let rowData; +​ + if (!(await DashboardPage.checkTableRowForData('Arden Gatdula'))) { + await DashboardPage.tableNextPageButton.click(); + + } +​ + rowData = (await DashboardPage.checkTableRowForData('Arden Gatdula') as string); + rowData = (rowData.replace('Delete', '')).trim(); + expect('8 Arden Gatdula Japan Nihonjin TitusUniversal CEO 69years Google').to.equal(rowData); + + console.log('final checking success'); +}); + + diff --git a/e2e/src/steps_definition/delete_definition.ts b/e2e/src/steps_definition/delete_definition.ts new file mode 100644 index 0000000..6abfa12 --- /dev/null +++ b/e2e/src/steps_definition/delete_definition.ts @@ -0,0 +1,47 @@ +import {Given, When, Then} from 'cucumber'; +import { Alert } from 'selenium-webdriver'; +import { browser } from 'protractor'; +import { DashboardPage } from '../po/dashboard.po'; + +const chai = require('chai').use(require('chai-as-promised')); +const expect = chai.expect; + +Given('I am still on the dashboard', async function () { + if(await browser.getCurrentUrl()==="http://localhost:4200/dashboard"){ + + console.log('deletePage entered') + + return true; + } + else{ + throw Error('The user is not on the dashboard page'); + + } + + }); + + +When('I deleted an Employee', async function () { + console.log('entered when command'); + + + await DashboardPage.deleteEmployee(); + + console.log('after delete click'); + + }); + +Then('The deleted data will not be shown in the table', async function () { + + let rowData; +​ + rowData = (await DashboardPage.checkTableRowForData('Brenden Wagner') as string); + + expect(rowData).to.equal(null); + + // rowData = (rowData.replace('Delete', '')).trim(); + // expect('1 Brenden Wagner United States of America, California American Facebook Software Engineer 8 Facebook').to.equal(rowData); + + console.log('final checking success'); + + }); diff --git a/e2e/src/steps_definition/read_definition.ts b/e2e/src/steps_definition/read_definition.ts new file mode 100644 index 0000000..9cf33de --- /dev/null +++ b/e2e/src/steps_definition/read_definition.ts @@ -0,0 +1,103 @@ +import { Given, When, Then } from 'cucumber'; +import { browser, element, by } from 'protractor'; +import { DashboardPage } from '../po/dashboard.po'; +import { MessagePage } from '../po/message.po'; + + +const chai = require('chai').use(require('chai-as-promised')); +const expect = chai.expect; + +Given('I redirected on the dashboard', 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'); + } + }); + +When('I browse the table', async function () { + const tableObject = element(by.tagName('table')); + if(await tableObject.isPresent()){ + console.log('success table view') + return true; + } + else + { + throw Error('error'); + } + + + + }); + +Then('I should see the details of different employees', async function () { + + let rowData; + let rowData2; + let rowData3; + let rowData4; + let counter: number = 0; + + + console.log(await DashboardPage.tableRows.getText()); + rowData = (await DashboardPage.checkTableRowForData('1 Cara Steves United States of America, New York American Walmart Sales Assistant 5 Google') as string); + rowData = (rowData.replace('Delete', '')).trim(); + + rowData2 = (await DashboardPage.checkTableRowForData('4 Jenny Chang Singapore, Singapore Chinese Singapore Airlines Regional Director 15 Twitter') as string); + rowData2= (rowData2.replace('Delete', '')).trim(); + + rowData4 = (await DashboardPage.checkTableRowForData('0 Brenden Wagner United States of America, California American Facebook Software Engineer 8 Facebook') as string); + rowData4= (rowData4.replace('Delete', '')).trim(); + await DashboardPage.tableNextPageButton.click(); + + + rowData3 = (await DashboardPage.checkTableRowForData('Jireh Kael') as string); + rowData3 = (rowData3.replace('Delete', '')).trim(); + + + + + if('1 Cara Steves United States of America, New York American Walmart Sales Assistant 5 Google'=== rowData){ + await counter++; + await console.log('pumasok!!'+ counter); + } + else{ + console.log('error!!'); + } + + if('4 Jenny Chang Singapore, Singapore Chinese Singapore Airlines Regional Director 15 Twitter'===rowData2){ + await counter++; + await console.log('pumasok2!!'+ counter); + } + else{ + await console.log('error2!!'); + } + + if('0 Brenden Wagner United States of America, California American Facebook Software Engineer 8 Facebook'===rowData4){ + await counter++; + await console.log('pumasok2!!'+ counter); + } + else{ + await console.log('error4!!'); + } + + if('6 Jireh Kael Kenya, Nairobi Kenyan Titus Global Tech-Inc Quality Assurance Engineer 1 TikTok' === rowData3){ + await counter++; + await console.log('pumasok3!!'+ counter); + } + else{ + await console.log('error3!!'); + } + + + await DashboardPage.tableBackPageButton.click(); + + + expect(counter).to.equal(3); + }); \ No newline at end of file diff --git a/e2e/src/steps_definition/security_definitions.ts b/e2e/src/steps_definition/security_definitions.ts new file mode 100644 index 0000000..7067620 --- /dev/null +++ b/e2e/src/steps_definition/security_definitions.ts @@ -0,0 +1,21 @@ +import {Given, When, Then} from 'cucumber'; +import { SecurityPage } from '../po/security.po'; +import { browser } from 'protractor'; + +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 SecurityPage.login(); + }); + +Then('I should be redirected to the dashboard', async function () { + + + expect (await browser.getCurrentUrl(), `the current url is `).to.equal("http://localhost:4200/dashboard"); + + }); \ No newline at end of file diff --git a/e2e/src/steps_definition/update_definition.ts b/e2e/src/steps_definition/update_definition.ts new file mode 100644 index 0000000..18ef993 --- /dev/null +++ b/e2e/src/steps_definition/update_definition.ts @@ -0,0 +1,63 @@ +import {Given, When, Then} from 'cucumber'; +import { SecurityPage } from '../po/security.po'; +import { browser, element, by, ElementFinder} from 'protractor'; +import { FormPage } from '../po/creation.po'; +import { DashboardPage } from '../po/dashboard.po'; +import { MessagePage } from '../po/message.po'; + +const chai = require('chai').use(require('chai-as-promised')); +const expect = chai.expect; + +Given('I am on the dashboard2', async function () { + console.log('1st hurdle'); + + if(await browser.getCurrentUrl()==="http://localhost:4200/dashboard"){ + return true; + } + else{ + throw Error('The user is not on the dashboard page'); + + } + + }); + +When('I updated an Employee', async function () { + await DashboardPage.updateEmployee(); + + + }); + +Then('I should see the updated success message {string}', async function(expectedMessage: string) { + const messageObject = MessagePage.updatedMessage; + 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); + console.log('1st then working(success)') + }); + +Then('I should see the updated data on the table', async function () { + let rowData; + // ​console.log(await DashboardPage.tableRows.getText()) + if (!(await DashboardPage.checkTableRowForData('Japan Japanese Titus'))) { + await DashboardPage.tableNextPageButton.click(); + + + } + ​ + rowData = (await DashboardPage.checkTableRowForData('Japan Japanese Titus') as string); + rowData = (rowData.replace('Delete', '')).trim(); + expect('1 Cara Steves Japan Japanese Titus Sales Assistant 5 Google').to.equal(rowData); + + console.log('final checking success'); + }); + // let rowData; + // ​ + // rowData = (await DashboardPage.checkTableRowForData('Japan Nihonjin Titus') as string); + // rowData = (rowData.replace('Delete', '')).trim(); + // expect('1 Cara Steves Japan Nihonjin Titus Sales Assistant 5 Google').to.equal(rowData); + + // console.log('final checking success'); + // }); + + + + From b1ff56ed380850e2fc967a3710da5fed03c35f2e Mon Sep 17 00:00:00 2001 From: ardengatz Date: Tue, 28 Jan 2020 14:06:11 +0800 Subject: [PATCH 2/4] working full CRUD --- e2e/src/po/creation.po.ts | 23 +-------- e2e/src/po/security.po.ts | 1 + .../steps_definition/creation_definitions.ts | 1 - e2e/src/steps_definition/delete_definition.ts | 3 -- e2e/src/steps_definition/read_definition.ts | 47 ++++++------------- .../steps_definition/security_definitions.ts | 1 - e2e/src/steps_definition/update_definition.ts | 15 ++---- 7 files changed, 20 insertions(+), 71 deletions(-) diff --git a/e2e/src/po/creation.po.ts b/e2e/src/po/creation.po.ts index e531277..5202237 100644 --- a/e2e/src/po/creation.po.ts +++ b/e2e/src/po/creation.po.ts @@ -4,10 +4,6 @@ import { element, by, ElementFinder, logging, browser } from 'protractor'; export class FormPage { - // static get form() { - // return element(by.tagName('form')); - // } - static get updateButton() { return element(by.buttonText('Update')); } @@ -25,7 +21,6 @@ export class FormPage { } static async fillForm(){ - // await this.newEmployeeButton.click(); await this.getFormControlElement('firstName').sendKeys('Arden'); await this.getFormControlElement('lastName').sendKeys('Gatdula'); @@ -34,24 +29,8 @@ export class FormPage { await this.getFormControlElement('company').sendKeys('TitusUniversal'); await this.getFormControlElement('designation').sendKeys('CEO'); await this.getFormControlElement('workExp').sendKeys('69years'); - await this.getFormControlElement('dataSource').click(); + await this.getFormControlElement('dataSource').click(); // browser.executeScript('window.scrollTo(0,document.body.scrollHeight)'); - // await browser.executeScript("arguments[0].scrollIntoView()", this.addbuttonEmployee ); await element.all(by.tagName('p-dropdownitem')).get(1).click(); } - - // static async updateForm(){ - // await this.getFormControlElement('firstName').sendKeys('Brenden'); - // await this.getFormControlElement('lastName').sendKeys('Wagner'); - // await this.getFormControlElement('country').sendKeys('Japan'); - // await this.getFormControlElement('nationality').sendKeys('Nihonjin'); - // await this.getFormControlElement('company').sendKeys('TitusUniversal'); - // await this.getFormControlElement('designation').sendKeys('CEO'); - // await this.getFormControlElement('workExp').sendKeys('69years'); - // await this.getFormControlElement('dataSource').click(); - // // browser.executeScript('window.scrollTo(0,document.body.scrollHeight)'); - // // await browser.executeScript("arguments[0].scrollIntoView()", this.addbuttonEmployee ); - // await element.all(by.tagName('p-dropdownitem')).get(1).click(); - // await this.updateButton.click(); - // } } diff --git a/e2e/src/po/security.po.ts b/e2e/src/po/security.po.ts index 822eae2..aa9b18b 100644 --- a/e2e/src/po/security.po.ts +++ b/e2e/src/po/security.po.ts @@ -21,3 +21,4 @@ export class SecurityPage { await this.loginButton.click(); } } + diff --git a/e2e/src/steps_definition/creation_definitions.ts b/e2e/src/steps_definition/creation_definitions.ts index 2b63c94..ac93e0e 100644 --- a/e2e/src/steps_definition/creation_definitions.ts +++ b/e2e/src/steps_definition/creation_definitions.ts @@ -16,7 +16,6 @@ Given('I am on the dashboard', async function () { } else{ throw Error('The user is not on the dashboard page'); - } }); diff --git a/e2e/src/steps_definition/delete_definition.ts b/e2e/src/steps_definition/delete_definition.ts index 6abfa12..fb457ef 100644 --- a/e2e/src/steps_definition/delete_definition.ts +++ b/e2e/src/steps_definition/delete_definition.ts @@ -39,9 +39,6 @@ Then('The deleted data will not be shown in the table', async function () { expect(rowData).to.equal(null); - // rowData = (rowData.replace('Delete', '')).trim(); - // expect('1 Brenden Wagner United States of America, California American Facebook Software Engineer 8 Facebook').to.equal(rowData); - console.log('final checking success'); }); diff --git a/e2e/src/steps_definition/read_definition.ts b/e2e/src/steps_definition/read_definition.ts index 9cf33de..bc728a5 100644 --- a/e2e/src/steps_definition/read_definition.ts +++ b/e2e/src/steps_definition/read_definition.ts @@ -27,12 +27,9 @@ When('I browse the table', async function () { console.log('success table view') return true; } - else - { + else{ throw Error('error'); } - - }); @@ -41,31 +38,25 @@ Then('I should see the details of different employees', async function () { let rowData; let rowData2; let rowData3; - let rowData4; + let counter: number = 0; + // console.log(await DashboardPage.tableRows.getText()); - - console.log(await DashboardPage.tableRows.getText()); rowData = (await DashboardPage.checkTableRowForData('1 Cara Steves United States of America, New York American Walmart Sales Assistant 5 Google') as string); rowData = (rowData.replace('Delete', '')).trim(); rowData2 = (await DashboardPage.checkTableRowForData('4 Jenny Chang Singapore, Singapore Chinese Singapore Airlines Regional Director 15 Twitter') as string); rowData2= (rowData2.replace('Delete', '')).trim(); - rowData4 = (await DashboardPage.checkTableRowForData('0 Brenden Wagner United States of America, California American Facebook Software Engineer 8 Facebook') as string); - rowData4= (rowData4.replace('Delete', '')).trim(); - await DashboardPage.tableNextPageButton.click(); - - - rowData3 = (await DashboardPage.checkTableRowForData('Jireh Kael') as string); - rowData3 = (rowData3.replace('Delete', '')).trim(); - - + rowData3 = (await DashboardPage.checkTableRowForData('0 Brenden Wagner United States of America, California American Facebook Software Engineer 8 Facebook') as string); + rowData3= (rowData3.replace('Delete', '')).trim(); - + // await DashboardPage.tableNextPageButton.click(); + // check to 2nd page + if('1 Cara Steves United States of America, New York American Walmart Sales Assistant 5 Google'=== rowData){ - await counter++; - await console.log('pumasok!!'+ counter); + await counter++; + await console.log('Success 1st row check!!'+ counter); } else{ console.log('error!!'); @@ -73,30 +64,22 @@ Then('I should see the details of different employees', async function () { if('4 Jenny Chang Singapore, Singapore Chinese Singapore Airlines Regional Director 15 Twitter'===rowData2){ await counter++; - await console.log('pumasok2!!'+ counter); + await console.log('Success 2nd row check!!'+ counter); } else{ await console.log('error2!!'); } - if('0 Brenden Wagner United States of America, California American Facebook Software Engineer 8 Facebook'===rowData4){ - await counter++; - await console.log('pumasok2!!'+ counter); - } - else{ - await console.log('error4!!'); - } - - if('6 Jireh Kael Kenya, Nairobi Kenyan Titus Global Tech-Inc Quality Assurance Engineer 1 TikTok' === rowData3){ + if('0 Brenden Wagner United States of America, California American Facebook Software Engineer 8 Facebook'===rowData3){ await counter++; - await console.log('pumasok3!!'+ counter); + await console.log('Success 3rd row check!!'+ counter); } else{ await console.log('error3!!'); } - - await DashboardPage.tableBackPageButton.click(); + // await DashboardPage.tableBackPageButton.click(); + // go back to first page expect(counter).to.equal(3); diff --git a/e2e/src/steps_definition/security_definitions.ts b/e2e/src/steps_definition/security_definitions.ts index 7067620..d16036f 100644 --- a/e2e/src/steps_definition/security_definitions.ts +++ b/e2e/src/steps_definition/security_definitions.ts @@ -15,7 +15,6 @@ When('I log in', async function () { Then('I should be redirected to the dashboard', async function () { - expect (await browser.getCurrentUrl(), `the current url is `).to.equal("http://localhost:4200/dashboard"); }); \ No newline at end of file diff --git a/e2e/src/steps_definition/update_definition.ts b/e2e/src/steps_definition/update_definition.ts index 18ef993..c270827 100644 --- a/e2e/src/steps_definition/update_definition.ts +++ b/e2e/src/steps_definition/update_definition.ts @@ -16,15 +16,14 @@ Given('I am on the dashboard2', async function () { } else{ throw Error('The user is not on the dashboard page'); - } }); When('I updated an Employee', async function () { - await DashboardPage.updateEmployee(); - + await DashboardPage.updateEmployee(); + }); Then('I should see the updated success message {string}', async function(expectedMessage: string) { @@ -49,15 +48,7 @@ Then('I should see the updated data on the table', async function () { console.log('final checking success'); }); - // let rowData; - // ​ - // rowData = (await DashboardPage.checkTableRowForData('Japan Nihonjin Titus') as string); - // rowData = (rowData.replace('Delete', '')).trim(); - // expect('1 Cara Steves Japan Nihonjin Titus Sales Assistant 5 Google').to.equal(rowData); - - // console.log('final checking success'); - // }); - + From 9e8cd2f0051d71926b63ae0be5f7a996042ae02e Mon Sep 17 00:00:00 2001 From: ardengatz Date: Tue, 28 Jan 2020 14:47:20 +0800 Subject: [PATCH 3/4] organized page objects --- e2e/src/po/creation.po.ts | 10 ++++++++++ e2e/src/po/dashboard.po.ts | 9 +-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/e2e/src/po/creation.po.ts b/e2e/src/po/creation.po.ts index 5202237..3f4f88b 100644 --- a/e2e/src/po/creation.po.ts +++ b/e2e/src/po/creation.po.ts @@ -33,4 +33,14 @@ export class FormPage { // browser.executeScript('window.scrollTo(0,document.body.scrollHeight)'); await element.all(by.tagName('p-dropdownitem')).get(1).click(); } + + static async updateFill(){ + await this.getFormControlElement('nationality').clear(); + await this.getFormControlElement('nationality').sendKeys('Japanese'); + await this.getFormControlElement('company').clear(); + await this.getFormControlElement('company').sendKeys('Titus'); + await this.getFormControlElement('country').clear(); + await this.getFormControlElement('country').sendKeys('Japan'); + browser.sleep(2000); + } } diff --git a/e2e/src/po/dashboard.po.ts b/e2e/src/po/dashboard.po.ts index 58aa1af..87c0e93 100644 --- a/e2e/src/po/dashboard.po.ts +++ b/e2e/src/po/dashboard.po.ts @@ -39,15 +39,8 @@ export class DashboardPage { } static async updateEmployee(){ - // await this.clickTable.click(); await this.table.click(); - await element(by.css('input[formcontrolname="nationality"]')).clear(); - await element(by.css('input[formcontrolname="nationality"]')).sendKeys("Japanese"); - await element(by.css('input[formcontrolname="company"]')).clear(); - await element(by.css('input[formcontrolname="company"]')).sendKeys("Titus"); - await element(by.css('input[formcontrolname="country"]')).clear(); - await element(by.css('input[formcontrolname="country"]')).sendKeys("Japan"); - // await FormPage.updateForm(); + await FormPage.updateFill(); await FormPage.updateButton.click(); } ​ From 2138ca44c1f9330efcc0a90515acbbcebbf6841c Mon Sep 17 00:00:00 2001 From: ardengatz Date: Wed, 29 Jan 2020 11:11:48 +0800 Subject: [PATCH 4/4] proper indentation and removal of console.logs --- e2e/src/po/creation.po.ts | 75 ++++++++--------- e2e/src/po/dashboard.po.ts | 3 +- e2e/src/po/message.po.ts | 16 ++-- e2e/src/po/security.po.ts | 35 ++++---- .../steps_definition/creation_definitions.ts | 43 +++------- e2e/src/steps_definition/delete_definition.ts | 42 +++------- e2e/src/steps_definition/read_definition.ts | 82 +++++++------------ .../steps_definition/security_definitions.ts | 14 ++-- e2e/src/steps_definition/update_definition.ts | 52 +++++------- 9 files changed, 137 insertions(+), 225 deletions(-) diff --git a/e2e/src/po/creation.po.ts b/e2e/src/po/creation.po.ts index 3f4f88b..584c1f5 100644 --- a/e2e/src/po/creation.po.ts +++ b/e2e/src/po/creation.po.ts @@ -1,46 +1,39 @@ import { element, by, ElementFinder, logging, browser } from 'protractor'; - - - export class FormPage { - static get updateButton() { - return element(by.buttonText('Update')); - } - - static get newEmployeeButton(): ElementFinder{ - return element(by.id('new-employee')); - } - - static getFormControlElement(formControlName: string) { - return element(by.css(`[formcontrolname=${formControlName}]`)); - } - - static get addbuttonEmployee(): ElementFinder{ - return element(by.css('[ng-reflect-label="Add"]')); - } - - static async fillForm(){ - - await this.getFormControlElement('firstName').sendKeys('Arden'); - await this.getFormControlElement('lastName').sendKeys('Gatdula'); - await this.getFormControlElement('country').sendKeys('Japan'); - await this.getFormControlElement('nationality').sendKeys('Nihonjin'); - await this.getFormControlElement('company').sendKeys('TitusUniversal'); - await this.getFormControlElement('designation').sendKeys('CEO'); - await this.getFormControlElement('workExp').sendKeys('69years'); - await this.getFormControlElement('dataSource').click(); + static get updateButton() { + return element(by.buttonText('Update')); + } + static get newEmployeeButton(): ElementFinder{ + return element(by.id('new-employee')); + } + static getFormControlElement(formControlName: string) { + return element(by.css(`[formcontrolname=${formControlName}]`)); + } + static get addbuttonEmployee(): ElementFinder{ + return element(by.css('[ng-reflect-label="Add"]')); + } + + static async fillForm(){ + await this.getFormControlElement('firstName').sendKeys('Arden'); + await this.getFormControlElement('lastName').sendKeys('Gatdula'); + await this.getFormControlElement('country').sendKeys('Japan'); + await this.getFormControlElement('nationality').sendKeys('Nihonjin'); + await this.getFormControlElement('company').sendKeys('TitusUniversal'); + await this.getFormControlElement('designation').sendKeys('CEO'); + await this.getFormControlElement('workExp').sendKeys('69years'); + await this.getFormControlElement('dataSource').click(); // browser.executeScript('window.scrollTo(0,document.body.scrollHeight)'); - await element.all(by.tagName('p-dropdownitem')).get(1).click(); - } - - static async updateFill(){ - await this.getFormControlElement('nationality').clear(); - await this.getFormControlElement('nationality').sendKeys('Japanese'); - await this.getFormControlElement('company').clear(); - await this.getFormControlElement('company').sendKeys('Titus'); - await this.getFormControlElement('country').clear(); - await this.getFormControlElement('country').sendKeys('Japan'); - browser.sleep(2000); - } + await element.all(by.tagName('p-dropdownitem')).get(1).click(); + } + + static async updateFill(){ + await this.getFormControlElement('nationality').clear(); + await this.getFormControlElement('nationality').sendKeys('Japanese'); + await this.getFormControlElement('company').clear(); + await this.getFormControlElement('company').sendKeys('Titus'); + await this.getFormControlElement('country').clear(); + await this.getFormControlElement('country').sendKeys('Japan'); + browser.sleep(2000); + } } diff --git a/e2e/src/po/dashboard.po.ts b/e2e/src/po/dashboard.po.ts index 87c0e93..734820c 100644 --- a/e2e/src/po/dashboard.po.ts +++ b/e2e/src/po/dashboard.po.ts @@ -1,7 +1,6 @@ import { element, by, browser } from 'protractor'; import { FormPage } from './creation.po'; ​import { Alert } from 'selenium-webdriver'; - export class DashboardPage { // static get tableFiles(){ @@ -70,4 +69,4 @@ export class DashboardPage { ​ return foundData; } -} \ No newline at end of file +} diff --git a/e2e/src/po/message.po.ts b/e2e/src/po/message.po.ts index 655fcb0..1c136f4 100644 --- a/e2e/src/po/message.po.ts +++ b/e2e/src/po/message.po.ts @@ -1,11 +1,9 @@ import { element, by } from 'protractor'; -​ export class MessagePage { - static get successMessage() { - return element(by.id('success-message')); - } -​ -​ static get updatedMessage() { - return element(by.css('span[class="ui-messages-detail ng-tns-c3-2 ng-star-inserted"]')); - } -} \ No newline at end of file +static get successMessage() { + return element(by.id('success-message')); +} +static get updatedMessage() { + return element(by.css('span[class="ui-messages-detail ng-tns-c3-2 ng-star-inserted"]')); +} +} diff --git a/e2e/src/po/security.po.ts b/e2e/src/po/security.po.ts index aa9b18b..24a9dd3 100644 --- a/e2e/src/po/security.po.ts +++ b/e2e/src/po/security.po.ts @@ -1,24 +1,17 @@ import { element, by, ElementFinder, logging, browser } from 'protractor'; - export class SecurityPage { - - 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 this.usernameField.sendKeys('asd'); - await this.passwordField.sendKeys('asd'); - await this.loginButton.click(); - } +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 this.usernameField.sendKeys('asd'); + await this.passwordField.sendKeys('asd'); + await this.loginButton.click(); +} } - diff --git a/e2e/src/steps_definition/creation_definitions.ts b/e2e/src/steps_definition/creation_definitions.ts index ac93e0e..9d991ac 100644 --- a/e2e/src/steps_definition/creation_definitions.ts +++ b/e2e/src/steps_definition/creation_definitions.ts @@ -9,49 +9,32 @@ const chai = require('chai').use(require('chai-as-promised')); const expect = chai.expect; Given('I am on the dashboard', async function () { - console.log('1st hurdle'); - - if(await browser.getCurrentUrl()==="http://localhost:4200/dashboard"){ - return true; - } - else{ - throw Error('The user is not on the dashboard page'); - } - - }); + if (await browser.getCurrentUrl() === "http://localhost:4200/dashboard"){ + return true; + } + else{ + throw Error('The user is not on the dashboard page'); + } +}); -When('I create an Employee', async function () { - - console.log('2nd hurdle'); - // SecurityPage.login(); - +When('I create an Employee', async function(){ await DashboardPage.createEmployee(); - - console.log('Success Creation'); - }); 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); - console.log('1st then working(success)') - }); + 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); +}); Then('I should see an employee should be added on the list', async function () { - -let rowData; + let rowData; ​ if (!(await DashboardPage.checkTableRowForData('Arden Gatdula'))) { await DashboardPage.tableNextPageButton.click(); - } -​ rowData = (await DashboardPage.checkTableRowForData('Arden Gatdula') as string); rowData = (rowData.replace('Delete', '')).trim(); expect('8 Arden Gatdula Japan Nihonjin TitusUniversal CEO 69years Google').to.equal(rowData); - - console.log('final checking success'); }); - diff --git a/e2e/src/steps_definition/delete_definition.ts b/e2e/src/steps_definition/delete_definition.ts index fb457ef..85d53bb 100644 --- a/e2e/src/steps_definition/delete_definition.ts +++ b/e2e/src/steps_definition/delete_definition.ts @@ -7,38 +7,20 @@ const chai = require('chai').use(require('chai-as-promised')); const expect = chai.expect; Given('I am still on the dashboard', async function () { - if(await browser.getCurrentUrl()==="http://localhost:4200/dashboard"){ - - console.log('deletePage entered') - - return true; - } - else{ - throw Error('The user is not on the dashboard page'); - - } - - }); - - -When('I deleted an Employee', async function () { - console.log('entered when command'); - - + if(await browser.getCurrentUrl()==="http://localhost:4200/dashboard"){ + return true; + } + else{ + throw Error('The user is not on the dashboard page'); + } +}); + +When('I deleted an Employee', async function() { await DashboardPage.deleteEmployee(); - - console.log('after delete click'); - - }); - -Then('The deleted data will not be shown in the table', async function () { +}); +Then('The deleted data will not be shown in the table', async function(){ let rowData; -​ rowData = (await DashboardPage.checkTableRowForData('Brenden Wagner') as string); - expect(rowData).to.equal(null); - - console.log('final checking success'); - - }); +}); diff --git a/e2e/src/steps_definition/read_definition.ts b/e2e/src/steps_definition/read_definition.ts index bc728a5..c31dd55 100644 --- a/e2e/src/steps_definition/read_definition.ts +++ b/e2e/src/steps_definition/read_definition.ts @@ -19,68 +19,44 @@ Given('I redirected on the dashboard', async function () { if (!(await dashboardElement.isPresent())) { throw Error('The user is not on the dashboard page'); } - }); +}); When('I browse the table', async function () { - const tableObject = element(by.tagName('table')); - if(await tableObject.isPresent()){ - console.log('success table view') - return true; - } - else{ - throw Error('error'); - } - - }); + const tableObject = element(by.tagName('table')); + if(await tableObject.isPresent()){ + return true; + } + else{ + throw Error('error'); + } +}); Then('I should see the details of different employees', async function () { - - let rowData; - let rowData2; - let rowData3; - - let counter: number = 0; - // console.log(await DashboardPage.tableRows.getText()); - - rowData = (await DashboardPage.checkTableRowForData('1 Cara Steves United States of America, New York American Walmart Sales Assistant 5 Google') as string); - rowData = (rowData.replace('Delete', '')).trim(); + let rowData; + let rowData2; + let rowData3; + let counter: number = 0; - rowData2 = (await DashboardPage.checkTableRowForData('4 Jenny Chang Singapore, Singapore Chinese Singapore Airlines Regional Director 15 Twitter') as string); - rowData2= (rowData2.replace('Delete', '')).trim(); + rowData = (await DashboardPage.checkTableRowForData('1 Cara Steves United States of America, New York American Walmart Sales Assistant 5 Google') as string); + rowData = (rowData.replace('Delete', '')).trim(); - rowData3 = (await DashboardPage.checkTableRowForData('0 Brenden Wagner United States of America, California American Facebook Software Engineer 8 Facebook') as string); - rowData3= (rowData3.replace('Delete', '')).trim(); + rowData2 = (await DashboardPage.checkTableRowForData('4 Jenny Chang Singapore, Singapore Chinese Singapore Airlines Regional Director 15 Twitter') as string); + rowData2= (rowData2.replace('Delete', '')).trim(); + rowData3 = (await DashboardPage.checkTableRowForData('0 Brenden Wagner United States of America, California American Facebook Software Engineer 8 Facebook') as string); + rowData3= (rowData3.replace('Delete', '')).trim(); // await DashboardPage.tableNextPageButton.click(); // check to 2nd page - - if('1 Cara Steves United States of America, New York American Walmart Sales Assistant 5 Google'=== rowData){ + if('1 Cara Steves United States of America, New York American Walmart Sales Assistant 5 Google' === rowData){ await counter++; - await console.log('Success 1st row check!!'+ counter); - } - else{ - console.log('error!!'); - } - - if('4 Jenny Chang Singapore, Singapore Chinese Singapore Airlines Regional Director 15 Twitter'===rowData2){ - await counter++; - await console.log('Success 2nd row check!!'+ counter); - } - else{ - await console.log('error2!!'); - } - - if('0 Brenden Wagner United States of America, California American Facebook Software Engineer 8 Facebook'===rowData3){ - await counter++; - await console.log('Success 3rd row check!!'+ counter); - } - else{ - await console.log('error3!!'); - } - + } + if('4 Jenny Chang Singapore, Singapore Chinese Singapore Airlines Regional Director 15 Twitter' === rowData2){ + await counter++; + } + if('0 Brenden Wagner United States of America, California American Facebook Software Engineer 8 Facebook' === rowData3){ + await counter++; + } // await DashboardPage.tableBackPageButton.click(); // go back to first page - - - expect(counter).to.equal(3); - }); \ No newline at end of file + expect(counter).to.equal(3); +}); \ No newline at end of file diff --git a/e2e/src/steps_definition/security_definitions.ts b/e2e/src/steps_definition/security_definitions.ts index d16036f..6316cbc 100644 --- a/e2e/src/steps_definition/security_definitions.ts +++ b/e2e/src/steps_definition/security_definitions.ts @@ -6,15 +6,13 @@ 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') - }); + await browser.get('http://localhost:4200/login') +}); When('I log in', async function () { - await SecurityPage.login(); - }); + await SecurityPage.login(); +}); Then('I should be redirected to the dashboard', async function () { - - expect (await browser.getCurrentUrl(), `the current url is `).to.equal("http://localhost:4200/dashboard"); - - }); \ No newline at end of file + expect (await browser.getCurrentUrl(), `the current url is `).to.equal("http://localhost:4200/dashboard"); +}); diff --git a/e2e/src/steps_definition/update_definition.ts b/e2e/src/steps_definition/update_definition.ts index c270827..931320d 100644 --- a/e2e/src/steps_definition/update_definition.ts +++ b/e2e/src/steps_definition/update_definition.ts @@ -9,45 +9,35 @@ const chai = require('chai').use(require('chai-as-promised')); const expect = chai.expect; Given('I am on the dashboard2', async function () { - console.log('1st hurdle'); - - if(await browser.getCurrentUrl()==="http://localhost:4200/dashboard"){ - return true; - } - else{ - throw Error('The user is not on the dashboard page'); - } - - }); - -When('I updated an Employee', async function () { - + if(await browser.getCurrentUrl() === "http://localhost:4200/dashboard"){ + return true; + } + else{ + throw Error('The user is not on the dashboard page'); + } +}); + +When('I updated an Employee', async function() { await DashboardPage.updateEmployee(); - - }); +}); Then('I should see the updated success message {string}', async function(expectedMessage: string) { const messageObject = MessagePage.updatedMessage; 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); - console.log('1st then working(success)') - }); +}); -Then('I should see the updated data on the table', async function () { +Then('I should see the updated data on the table', async function() { let rowData; - // ​console.log(await DashboardPage.tableRows.getText()) - if (!(await DashboardPage.checkTableRowForData('Japan Japanese Titus'))) { - await DashboardPage.tableNextPageButton.click(); - - - } - ​ - rowData = (await DashboardPage.checkTableRowForData('Japan Japanese Titus') as string); - rowData = (rowData.replace('Delete', '')).trim(); - expect('1 Cara Steves Japan Japanese Titus Sales Assistant 5 Google').to.equal(rowData); - - console.log('final checking success'); - }); + + if (!(await DashboardPage.checkTableRowForData('Japan Japanese Titus'))) { + await DashboardPage.tableNextPageButton.click(); + } + + rowData = (await DashboardPage.checkTableRowForData('Japan Japanese Titus') as string); + rowData = (rowData.replace('Delete', '')).trim(); + expect('1 Cara Steves Japan Japanese Titus Sales Assistant 5 Google').to.equal(rowData); +});