Skip to content

Commit

Permalink
Added fixtures for global aftereach and beforeeach hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
BakkappaN committed Sep 15, 2024
1 parent 5efd281 commit 6b11f63
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 36 deletions.
53 changes: 53 additions & 0 deletions fixtures/testfixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const debug = require('debug');
const fs = require('fs');
const { test: base, expect } = require('@playwright/test');

import { writeTestStatusToExcelFile } from '../utils/excelhandler';

const { RegistrationPage } = require('../pages/registrationpage');
const { LoginPage } = require('../pages/loginpage');
const { ParaBankHomePage } = require('../pages/parabankhomepage');
const { OpenNewAccountPage } = require('../pages/opennewaccountpage');

// Extend the base test to include a custom fixture
const test = base.extend({

registrationPage: async ({ page }, use) => {
const registrationPage = new RegistrationPage(page);
await use(registrationPage);
},
loginPage: async ({ page }, use) => {
const loginPage = new LoginPage(page);
await use(loginPage);
},
paraBankHomePage: async ({ page }, use) => {
const paraBankHomePage = new ParaBankHomePage(page);
await use(paraBankHomePage);
},
openNewAccountPage: async ({ page }, use) => {
const openNewAccountPage = new OpenNewAccountPage(page);
await use(openNewAccountPage);
},
// Optionally, expose the raw page instance
pageInstance: async ({ page }, use) => {
await use(page);
},
saveLogs: [async ({ }, use, testInfo) => {
// Collecting logs during the test
// const logs = [];
// debug.log = (...args) => logs.push(args.map(String).join(''));
// debug.enable('myserver');
await use();

// After the test, check whether the test passed or failed
// if (testInfo.status !== testInfo.expectedStatus) {
// // `outputPath()` API guarantees a unique file name
// const logFile = testInfo.outputPath('logs.txt');
// await fs.promises.writeFile(logFile, logs.join('\n'), 'utf8');
// testInfo.attachments.push({ name: 'logs', contentType: 'text/plain', path: logFile });
// }
await writeTestStatusToExcelFile(testInfo);
}, { auto: true }],
});

module.exports = { test, expect };
10 changes: 2 additions & 8 deletions tests-e2e/uitest.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Include playwright module
const { test, expect } = require('@playwright/test');
const { test} = require('../fixtures/testfixture');
const { expect } = require('@playwright/test');

import path from "node:path";
const xlsx = require('xlsx');
Expand All @@ -9,12 +9,6 @@ const { HomePage } = require('../pages/homepage');
const { ResultPage } = require('../pages/resultpage');
const { PlaylistPage } = require('../pages/playlistpage');

import { writeTestStatusToExcelFile } from '../utils/excelhandler';

test.afterEach('Running after each test...', async ({ page }, testInfo) => {
await writeTestStatusToExcelFile(testInfo);
});

/**
* Bakkappa N
*/
Expand Down
33 changes: 6 additions & 27 deletions tests/parabank.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// Include playwright module
const { test, expect } = require('@playwright/test');
import path from "node:path";
const { test, expect } = require('../fixtures/testfixture');

const { RegistrationPage } = require('../pages/registrationpage');
const { LoginPage } = require('../pages/loginpage');
const { ParaBankHomePage } = require('../pages/parabankhomepage');
const { OpenNewAccountPage } = require('../pages/opennewaccountpage');
import path from "node:path";

import { pbanktestdata } from "../test-data/qa/parabank.json";
import { runtimetestdata } from '../test-data/runtimetestdata.json'
Expand All @@ -14,19 +10,10 @@ import { updateJsonFile } from '../utils/helper';

const filePath = path.join(__dirname, "../test-data/runtimetestdata.json");

import { writeTestStatusToExcelFile } from '../utils/excelhandler';

test.afterEach('Running after each test...', async ({ page }, testInfo) => {
await writeTestStatusToExcelFile(testInfo);
});

/**
* Bakkappa N
*/
test('[2] Automate User Registration process', { tag: '@ParaBankTest' }, async ({ page }) => {

const registrationPage = new RegistrationPage(page);
const loginPage = new LoginPage(page);
test('[2] Automate User Registration process', { tag: '@ParaBankTest' }, async ({page, registrationPage, loginPage }) => {

const newUserName = pbanktestdata.firstname + "_" + pbanktestdata.lastname + "_" + faker.number.int(10000);

Expand Down Expand Up @@ -62,9 +49,7 @@ test('[2] Automate User Registration process', { tag: '@ParaBankTest' }, async (
/**
* Bakkappa N
*/
test('[9] Verify that user is able to login successfully in the ParaBank application after providing the valid username and password', { tag: '@ParaBankTest' }, async ({ page }) => {

const loginPage = new LoginPage(page);
test('[9] Verify that user is able to login successfully in the ParaBank application after providing the valid username and password', { tag: '@ParaBankTest' }, async ({ page, loginPage }) => {

await test.step('Open browser with Para Bank URL', async () => {
await loginPage.goto();
Expand All @@ -82,11 +67,7 @@ test('[9] Verify that user is able to login successfully in the ParaBank applica
/**
* Bakkappa N
*/
test('[12]Verify that user can see the Account types in dropdown', { tag: '@ParaBankTest' }, async ({ page }) => {

const loginPage = new LoginPage(page);
const paraBankHomePage = new ParaBankHomePage(page);
const openNewAccountPage = new OpenNewAccountPage(page);
test('[12]Verify that user can see the Account types in dropdown', { tag: '@ParaBankTest' }, async ({ page, loginPage, paraBankHomePage, openNewAccountPage }) => {

await test.step('Open browser with Para Bank URL', async () => {
await loginPage.goto();
Expand All @@ -110,9 +91,7 @@ test('[12]Verify that user can see the Account types in dropdown', { tag: '@Para
/**
* Bakkappa N
*/
test('[14] Verify that user is not able to login into application when user entered invalid userid', { tag: '@ParaBankTest' }, async ({ page }) => {

const loginPage = new LoginPage(page);
test('[14] Verify that user is not able to login into application when user entered invalid userid', { tag: '@ParaBankTest' }, async ({ page, loginPage}) => {

await test.step('Open browser with Para Bank URL', async () => {
await loginPage.goto();
Expand Down
2 changes: 1 addition & 1 deletion utils/azuredevops.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AzureDevOps {
const testPointId = await this.getTestPoint(testPlanId, testSuiteId, testCaseId);
await this.updateTestPointStatus(testPlanId, testSuiteId, testPointId, testCaseStatus.charAt(0).toUpperCase() + testCaseStatus.slice(1));
console.log('row is : ' + row);
console.log(`Test Case ID - ${testCaseId} is : ${testCaseStatus}`);
console.log(`Updated Test Case ID - ${testCaseId} : ${testCaseStatus} in test plan`);
}
console.log(`Completed updating test case status for : ${data.length}`);
} catch (error) {
Expand Down

0 comments on commit 6b11f63

Please sign in to comment.