-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrating database testing with playwright
- Loading branch information
Showing
6 changed files
with
198 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |