Skip to content

Commit

Permalink
playwright automation tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
BakkappaN committed Aug 25, 2024
1 parent 2e5f86c commit 57f0c8c
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ URL=https://parabank.parasoft.com/parabank/index.htm
USER_NAME=1234DF
PASSWORD=DFGHJK67

API_BASE_URI=https://restful-booker.herokuapp.com
API_BASE_URI=https://restful-booker.herokuapp.com

DOWNLOAD_PATH=../download/downloadedfile.xlsx
SHEET1=Sheet1
Binary file added download/downloadedfile.xlsx
Binary file not shown.
97 changes: 96 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@azure/keyvault-secrets": "^4.8.0",
"csv-parse": "^5.5.3",
"dotenv": "^16.4.1",
"luxon": "^3.4.4"
"luxon": "^3.4.4",
"xlsx": "^0.18.5"
}
}
24 changes: 24 additions & 0 deletions tests/uitest.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Include playwright module
const { test, expect } = require('@playwright/test');

import path from "node:path";
const xlsx = require('xlsx');
import BaseTest from '../utils/basetest';

const { HomePage } = require('../pages/homepage');
const { ResultPage } = require('../pages/resultpage');
const { PlaylistPage } = require('../pages/playlistpage');
Expand Down Expand Up @@ -32,4 +36,24 @@ test('UI automation test using playwright', { tag: '@UITest' }, async ({ page })
await playlistpage.clickOnVideo();
await page.waitForTimeout(8000);
});
})

/**
* Bakkappa N
*/
test('Verify excel data using playwright', { tag: '@ValidateExcel' }, async ({ page }) => {
const filePath = path.join(__dirname, process.env.DOWNLOAD_PATH);
const workbook = xlsx.readFile(filePath);
const worksheet = workbook.Sheets[process.env.Sheet1];
const data = xlsx.utils.sheet_to_json(worksheet);

expect(data.length).toBeGreaterThan(0);
for (const row of data) {
for (const key in row) {
console.log(`${key} : ` + row[key]);
}
console.log("=======")
}
expect(data[0].Skill1).toEqual('Playwright');
expect(data[0].Skill2).toEqual('Cypress');
})
4 changes: 3 additions & 1 deletion utils/basetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const { test, expect } = require('@playwright/test');
import { qaTestData } from "../test-data/qa/google.json";
import { stageTestData } from "../test-data/stage/google.json";

// create base class
/**
* Bakkappa N
*/
class BaseTest {
/**
*
Expand Down
45 changes: 45 additions & 0 deletions utils/excelhandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const { test, expect } = require('@playwright/test');
const xlsx = require('xlsx');

/**
* Bakkappa N
*/
export async function getExcelDataAsKeyValue(filePath, sheet) {
const workbook = xlsx.readFile(filePath);
const worksheet = workbook.Sheets[sheet];
const data = xlsx.utils.sheet_to_json(worksheet);

if (data.length === 0) {
console.error('Excel file is empty.');
return;
}

const keyValuePairs = [];
for (const row of data) {
const keyValuePair = {};
for (const key in row) {
keyValuePair[key] = row[key];
}
keyValuePairs.push(keyValuePair);
}
return keyValuePairs;
}

/**
* Bakkappa N
*/
export async function printAllRowsData(filePath, sheet) {
const workbook = xlsx.readFile(filePath);
const worksheet = workbook.Sheets[sheet];
const data = xlsx.utils.sheet_to_json(worksheet);

expect(data.length).toBeGreaterThan(0);
for (const row of data) {
for (const key in row) {
console.log(`${key} : ` + row[key]);
}
console.log("=======")
}
// data[0].Skill1 - access using row & key
}

0 comments on commit 57f0c8c

Please sign in to comment.