Skip to content

Commit

Permalink
Integrating database testing with playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
BakkappaN committed Sep 9, 2024
1 parent e5ebf9b commit a0fedbf
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 5 deletions.
14 changes: 10 additions & 4 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ DOWNLOAD_PATH=../download/downloadedfile.xlsx
SHEET1=Sheet1

# Azure DevOps
UPDATE_TEST_PLAN=No
PIPELINE=No
UPDATE_TEST_PLAN=
PIPELINE=
TC_STATUS_PATH=./Test_Case_Status.xlsx
TC_STATUS_SHEET=Test Case Status
TEST_PLAN_ID=
TEST_SUITE_ID=
TEST_PLAN_GET_API=https://dev.azure.com/{Orgnization}/{Project}/_apis/testplan/Plans/{0}/Suites/{1}/TestPoint?testCaseId={2}&api-version=7.2-preview.2
TEST_PLAN_PATCH_API=https://dev.azure.com/{Orgnization}/{Project}/_apis/test/Plans/{0}/Suites/{1}/points/{2}?api-version=7.2-preview.2
TEST_PLAN_GET_API=https://dev.azure.com/{Orgnization}/Project1/_apis/testplan/Plans/{0}/Suites/{1}/TestPoint?testCaseId={2}&api-version=7.2-preview.2
TEST_PLAN_PATCH_API=https://dev.azure.com/{Orgnization}/Project1/_apis/test/Plans/{0}/Suites/{1}/points/{2}?api-version=7.2-preview.2
AZURE_DEVOPS_USER=
AZURE_DEVOPS_PASS=

# MYSQL DataBase
MYSQL_HOST=
MYSQL_PORT=
MYSQL_USER=
MYSQL_PASSWORD=
MYSQL_DATABASE=
110 changes: 110 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"csv-parse": "^5.5.3",
"dotenv": "^16.4.1",
"luxon": "^3.4.4",
"mysql2": "^3.11.0",
"xlsx": "^0.18.5"
}
}
4 changes: 3 additions & 1 deletion playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require('dotenv').config();
*/
module.exports = defineConfig({
// test timeout
timeout: 4 * 60 * 1000,
timeout: 3 * 60 * 1000,
expect: {
timeout: 90000
},
Expand Down Expand Up @@ -49,6 +49,8 @@ module.exports = defineConfig({

// Collect trace when retrying the failed test
trace: 'on',
actionTimeout: 90 * 1000,
navigationTimeout: 90 * 1000,
},

globalSetup: require.resolve('./globals/global-setup'),
Expand Down
61 changes: 61 additions & 0 deletions tests-e2e/databasetest.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Include playwright module
const { test, expect } = require('@playwright/test');

const connection = require('../utils/mysqldatabase');

const name = 'Testers Talk';
const email = 'testerstalk@example.com';

test.beforeAll('Running before all tests', async () => {
// Setup: Insert test data into the database
await connection.execute('INSERT INTO users (name, email) VALUES (?, ?)', [name, email]);
});

test.afterAll('Running after all tests', async () => {
// Cleanup: Remove test data from the database
await connection.execute('DELETE FROM users WHERE email = ?', ['testerstalk@example.com']);
});

/**
* Bakkappa N
*/
test('Data Base Validation Test 1', { tag: '@DataBaseTest' }, async ({ }) => {
await test.step('Validate name from data base', async () => {

// Playwright actions

// Query the database
const [rows] = await connection.execute('SELECT * FROM users WHERE email = ?', ['testerstalk@example.com']);
const user = rows[0];

// Perform assertions - validating user name
expect(user).toBeDefined();
console.log('name is ' + user.name);
console.log('email is ' + user.email);
expect(user.name).toBe('Testers Talk');

// Playwright actions
})
})

/**
* Bakkappa N
*/
test('Data Base Validation Test 2', { tag: '@DataBaseTest' }, async ({ }) => {
await test.step('Validate email from data base', async () => {

// Playwright actions

// Query the database
const [rows] = await connection.execute('SELECT * FROM users WHERE name = ?', ['Testers Talk']);
const user = rows[0];

// Perform assertions - validating user email
expect(user).toBeDefined();
console.log('name is ' + user.name);
console.log('email is ' + user.email);
expect(user.email).toBe('testerstalk@example.com');

// Playwright actions
})
})
13 changes: 13 additions & 0 deletions utils/mysqldatabase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const mysql = require('mysql2');

const pool = mysql.createPool({
host: process.env.MYSQL_HOST,
user: process.env.MYSQL_USER,
password: process.env.MYSQL_PASSWORD,
database: process.env.MYSQL_DATABASE,
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0
});

module.exports = pool.promise(); // Use promise-based API for async/await support

0 comments on commit a0fedbf

Please sign in to comment.