Skip to content

Commit

Permalink
added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sadabnepal committed Aug 16, 2023
1 parent 47682ae commit fc67f17
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 23 deletions.
13 changes: 13 additions & 0 deletions tests/data/register.ts → tests/data/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,17 @@ export const RegisterUserData = {
userName: userName,
password: password,
confirm: password
}

export const BillPaymentData = (accountNumber: string, amount: number) => {
return {
PayeeName: faker.person.fullName({ firstName: firstName, lastName: lastName }),
Address: faker.location.streetAddress(),
City: faker.location.city(),
State: faker.location.state(),
ZipCode: faker.location.zipCode(),
PhoneNo: faker.phone.number(),
AccountNumber: accountNumber,
Amount: amount
}
}
2 changes: 1 addition & 1 deletion tests/pages/base.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class BasePage {
logStep(`Clicked on ${await element.selector}`)
}

protected async setData(element: WebElement, value: string) {
protected async setData(element: WebElement, value: string | number) {
await element.setValue(value);
logStep(`Entered '${value}' in ${await element.selector}`)
}
Expand Down
26 changes: 26 additions & 0 deletions tests/pages/bills.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { BillPaymentType } from "../types/custom";
import BasePage from "./base.page";
import { formAmountElementByLabel, formInputElementByLabel } from "./common.element";

class BillsPage extends BasePage {

private get sendPaymentButton() { return $("[value='Send Payment']") }

get billPaymentMessage() { return $("//div[@ng-show='showResult']/p[1]"); }

async billPayment(options: BillPaymentType) {
await this.setData(formInputElementByLabel("Payee Name"), options.PayeeName);
await this.setData(formInputElementByLabel("Address"), options.Address);
await this.setData(formInputElementByLabel("City"), options.City);
await this.setData(formInputElementByLabel("State"), options.State);
await this.setData(formInputElementByLabel("Zip Code"), options.ZipCode);
await this.setData(formInputElementByLabel("Phone #"), options.PhoneNo);
await this.setData(formInputElementByLabel("Account #"), options.AccountNumber);
await this.setData(formInputElementByLabel("Verify Account #"), options.AccountNumber);
await this.setData(formAmountElementByLabel("Amount"), options.Amount);
await this.clickElement(this.sendPaymentButton);

}

}
export default new BillsPage()
4 changes: 4 additions & 0 deletions tests/pages/common.element.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

export const formInputElementByLabel = (label: string) => $(`//b[text()='${label}:']/..//following-sibling::td/input`);

export const formAmountElementByLabel = (label: string) => $(`//b[text()='${label}: $']/..//following-sibling::td/input`)
29 changes: 13 additions & 16 deletions tests/pages/register.page.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
import { CreateAccountType } from "../types/custom";
import BasePage from "./base.page";
import { formInputElementByLabel } from "./common.element";


class RegisterPage extends BasePage {

get pageHeader() { return $(".title") }
get pageHeader() { return $("//div[not(@class='ng-hide')]/h1[@class='title']") }
get registerButton() { return $("[value=Register]") }
get welcomeUser() { return $("#rightPanel>h1") }
get welcomeMessage() { return $("#rightPanel>p") }

private elementByLabel(label: string) {
return $(`//b[text()='${label}:']/..//following-sibling::td/input`);
}

async registerNewUser(options: CreateAccountType) {
await this.setData(this.elementByLabel("First Name"), options.firstName);
await this.setData(this.elementByLabel("Last Name"), options.lastName);
await this.setData(this.elementByLabel("Address"), options.address);
await this.setData(this.elementByLabel("City"), options.city);
await this.setData(this.elementByLabel("State"), options.state);
await this.setData(this.elementByLabel("Zip Code"), options.zipCode);
await this.setData(this.elementByLabel("Phone #"), options.phoneNo);
await this.setData(this.elementByLabel("SSN"), options.ssn);
await this.setData(this.elementByLabel("Username"), options.userName);
await this.setData(this.elementByLabel("Password"), options.password);
await this.setData(this.elementByLabel("Confirm"), options.confirm);
await this.setData(formInputElementByLabel("First Name"), options.firstName);
await this.setData(formInputElementByLabel("Last Name"), options.lastName);
await this.setData(formInputElementByLabel("Address"), options.address);
await this.setData(formInputElementByLabel("City"), options.city);
await this.setData(formInputElementByLabel("State"), options.state);
await this.setData(formInputElementByLabel("Zip Code"), options.zipCode);
await this.setData(formInputElementByLabel("Phone #"), options.phoneNo);
await this.setData(formInputElementByLabel("SSN"), options.ssn);
await this.setData(formInputElementByLabel("Username"), options.userName);
await this.setData(formInputElementByLabel("Password"), options.password);
await this.setData(formInputElementByLabel("Confirm"), options.confirm);
await this.clickElement(this.registerButton);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/specs/features/fileUpload.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Feature: File Upload

Scenario: Test upload file
Given I open herokuapp upload page
Given I open heroku app upload page
When I upload file
Then I validate file is uploaded successfully
5 changes: 5 additions & 0 deletions tests/specs/features/paraBank.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ Feature: Parabank app test
When I user click on "Accounts Overview" link
Then I should be navigated to "Accounts Overview" page
Then I deposit amount via API and validate updated amount
When I user click on "Bill Pay" link
Then I should be navigated to "Bill Payment Service" page
When I make bill payment with amount "6500"
Then I should be navigated to "Bill Payment Complete" page
And I validate bill payment of "6500" is successful
17 changes: 15 additions & 2 deletions tests/specs/steps/account.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Then } from "@wdio/cucumber-framework";
import { Then, When } from "@wdio/cucumber-framework";
import { BillPaymentData } from "../../data/random";
import accountsPage from "../../pages/accounts.page";
import billsPage from "../../pages/bills.page";

let accountNumber: string;

Then(/^I deposit amount via API and validate updated amount$/, async () => {
await accountsPage.waitUntilBalanceDisplayed();
const accountNumber = await accountsPage.accountNumber.getText();
accountNumber = await accountsPage.accountNumber.getText();
const accountBalance = await accountsPage.getAccountBalance();
const depositAmount = 32000;

Expand All @@ -17,4 +21,13 @@ Then(/^I deposit amount via API and validate updated amount$/, async () => {

expect(response.text).toEqual(expectedAPIResponse);
expect(updateAccountBalance).toEqual(accountBalance + depositAmount)
})

When("I make bill payment with amount {string}", async (amount: number) => {
await billsPage.billPayment(BillPaymentData(accountNumber, amount))
})

Then("I validate bill payment of {string} is successful", async (amount: number) => {
const expectedMessage = `Bill Payment to test in the amount of $${amount}.00 from account ${accountNumber} was successful.`;
await expect(billsPage.billPaymentMessage).toHaveText(expectedMessage)
})
4 changes: 2 additions & 2 deletions tests/specs/steps/home.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Then(/^I validate home page logo$/, async () => {
})

Then(/^I validate left menu items$/, async (dataTable) => {
const allMenuItems = dataTable.hashes().map((element: { LeftMenuItems: string }) => element.LeftMenuItems);
expect(await homePage.getAllLeftMenu()).toEqual(allMenuItems);
const expectedMenuItems = dataTable.hashes().map((element: { LeftMenuItems: string }) => element.LeftMenuItems);
expect(await homePage.getAllLeftMenu()).toEqual(expectedMenuItems);
})

Then(/^I user click on "([^"]*)?" link$/, async (linkText: string) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/steps/register.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Then, When } from "@wdio/cucumber-framework";
import { RegisterUserData, userName } from "../../data/register";
import { RegisterUserData, userName } from "../../data/random";
import registerPage from "../../pages/register.page";

Then(/^I should be navigated to "([^"]*)?" page$/, async (pageHeader: string) => {
Expand Down
11 changes: 11 additions & 0 deletions tests/types/custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,15 @@ export type CreateAccountType = {
userName: string,
password: string,
confirm: string
}

export type BillPaymentType = {
PayeeName: string,
Address: string,
City: string,
State: string,
ZipCode: string,
PhoneNo: string,
AccountNumber: string,
Amount: number
}

0 comments on commit fc67f17

Please sign in to comment.