logging in with cypress/puppeteer

Viewed 1160

I have an application that uses Okta to log in. I am trying to set up an automation test using Cypress with Puppeteer. The problem I am having is that when I launch puppeteer with {headless: true}, it doesn't fill in the login form. {headless: false} opens another browser window outside of Cypress and works as expected. It fills in the login form, logs in correctly, but I can't run any cypress tests in that window.

on('task', {
  login({username, password}) {
    return (async () => {
      const browser = await puppeteer.launch({headless: false});
      const page = await browser.newPage();
      await page.goto(config.baseUrl);
      await page.waitForNavigation();
      await page.waitFor('#okta-signin-username');
      await page.type('#okta-signin-username', username, {delay: 100});
      await page.waitFor('#okta-signin-password');
      await page.type('#okta-signin-password', password, {delay: 100});
      await page.click('#okta-signin-submit');
      await page.waitForNavigation();
      return true;
    };
  });

Here's how it's being used:

it('my test', () => {
  cy.visit('/');
  cy.viewport(1280, 1024);
  cy.login('username', 'password');

  //tests go here
});

The above code opens Chromium and correctly logs in but then the tests fail. It doesn't log in with {headless: true}. Am I missing something here? Any help would be appreciated.

Thanks

0 Answers
Related