I am new to playwright (Automation tool).
Scenario: Need to connect to Vertica DB, fetch required record and compare the result with UI values.
I am using following Javascript through which I am able to connect to DB successfully.
console.log("Hello")
console.log("Entering the test")
const {Client} = require('vertica-nodejs')
const connectionString = 'vertica://'
+ 'xxx' + ':'
+ 'xyz' + '@'
+ 'abcdefg' + ':'
+ 5433 + '/'
+ 'abc';
const client = new Client({
connectionString,
});
client.connect()
client.query("SELECT 'success' as connectionWithString", (err, res) => {
console.log(err || res.rows[0])
client.end()
})
OUTPUT:
PS C:\Stab\Automation\ConnectVertica> node .\temp.js
Hello
Entering the test
{ connectionWithString: 'success' }
PS C:\Stab\Automation\ConnectVertica>
Using same code when I am trying to connect to DB from Playwright script, not seeing console log which says connectionWithString: 'success'.
import { test, expect } from '@playwright/test';
const {Client} = require('vertica-nodejs')
const connectionString = 'vertica://'
+ 'xxx' + ':'
+ 'xyz' + '@'
+ 'abcdefg' + ':'
+ 5433 + '/'
+ 'abc';
const client = new Client({
connectionString,
});
async function connectAndQuery() {
try {
console.log("Connecting to Vertica DB")
await client.connect();
const res = await client.query("SELECT 'Connection successful' as message");
console.log(res.rows[0]);
} catch (err) {
console.error(err);
} finally {
await client.end();
}
}
test('test db connection', async () => {
connectAndQuery();
});
OUTPUT:
Running 1 test using 1 worker
[chromium] › tests\testVertica.spec.js:25:5 › test db connection
Connecting to Vertica DB
1 passed (3.9s)
Can anyone help me here to understand what I am missing here.
await connectAndQuery();in the last block, but I'm not sure why you'd want to connect to a database in a Playwright test in the first place. Since it's an E2E test, you generally want to manipulate everything as a user would, from the UI. Also not sure why this is tagged playwright-java.