Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions e2e/src/features/employee/employee.feature
Original file line number Diff line number Diff line change
@@ -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

8 changes: 8 additions & 0 deletions e2e/src/features/security/security.feature
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions e2e/src/hooks/generic.hook.ts
Original file line number Diff line number Diff line change
@@ -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);
});
37 changes: 37 additions & 0 deletions e2e/src/po/dashboard.po.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
19 changes: 19 additions & 0 deletions e2e/src/po/employee.po.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
29 changes: 29 additions & 0 deletions e2e/src/po/form.po.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
38 changes: 38 additions & 0 deletions e2e/src/po/form2.po.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
9 changes: 9 additions & 0 deletions e2e/src/po/message.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { element, by } from 'protractor';

export class MessagePage {
static get successMessage() {
return element(by.id('success-message'));
}


}
20 changes: 20 additions & 0 deletions e2e/src/po/security.po.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
144 changes: 144 additions & 0 deletions e2e/src/step_definition/employee.definition.ts
Original file line number Diff line number Diff line change
@@ -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';

});

18 changes: 18 additions & 0 deletions e2e/src/step_definition/security.definition.ts
Original file line number Diff line number Diff line change
@@ -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);
});