I am trying to create a "Sessions" class using Javascript/Puppeteer and I am absolutely not familiar enough with either JS or Puppeteer to make it work.
I imagine I am just running into a limitation with async functions, but honestly I have no idea.
Puppeteer successfully opens the browser and goes to the web site, but it gets stuck at the beginning of the login function "Testing1" and never makes it to "Testing2"
Can anyone look at the below code and tell me where I am going wrong? There are 30-40 test classes and I would like to abstract the setup/login function out of every class.
So I have a "Sessions" Class that looks like this.
import {puppeteer} from "../types.cjs";
import {PuppetOptions} from "../data.js";
export class Session {
glPage;
glBrowser;
constructor(url) {
puppeteer.launch(PuppetOptions)
.then(async (browser) => {
this.glBrowser = browser
this.glPage = await browser.newPage();
await this.glPage.goto(url);
});
}
async login(username, password) {
console.log("testing")
await this.glPage.waitForSelector('#idp-discovery-username')
console.log("testing2")
await this.glPage.type("#idp-discovery-username", username);
await this.glPage.evaluate(() => {
document.querySelector('#idp-discovery-submit').click();
});
await this.glPage.waitForSelector('#okta-signin-password')
await this.glPage.type("#okta-signin-password", password)
await this.glPage.evaluate(() => {
document.querySelector('#okta-signin-submit').click();
});
}
}
And I am trying to use it in my test class as follows -
describe("GL Flow", () => {
before ( function () {
let test = new Session(AccountInfo.qa.url)
test.login(AccountInfo.qa.username, AccountInfo.qa.password)
});
it("Test 1 ", async () => {
expect(true)
});
it("Test2", async () => {
expect(true)
});
})
Thank you for all the help.