Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
Abstract a Setup/Login Class with Javascript/Puppeteer

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!