0

enter image description here

Above, you can see the input element with the #account_email selector. But a jest functional test which awaits selection and typing in this field fails every time. I can't understand why.

Is there a syntax error below? Is this type of selection prone to error? Any advice on fixing this is welcome.

// A functonal test file being run by jest.js
// jest-puppeteer

test('[functional] log into shopify"', async () => {

      const browser = await puppeteer.launch({headless: false});
      const page = await browser.newPage();

      // go to login page
      await page.goto("https://partners.shopify.com/1185756/apps/3207477/test", {waitUntil : "load"});
      console.log(page.url, `=====arrived at shopify login screen=====`);

      // fill and submit form
      const emailInput = await page.focus("#account_email");
      await emailInput.type(process.env.SHOPIFY_PARTNER_EMAIL);
// error seen in terminal
TypeError: Cannot read property 'type' of undefined

      22 |       // email screen
      23 |       const emailInput = await page.focus("#account_email");
    > 24 |       await emailInput.type(process.env.SHOPIFY_PARTNER_EMAIL);
         |                        ^
      25 |       

// 
hardkoded
  • 18,915
  • 3
  • 52
  • 64
Sean D
  • 3,810
  • 11
  • 45
  • 90

1 Answers1

3

focus doesn't return the element handle. You could do something like this:

const emailInput = await page.waitForSelector("#account_email");
await emailInput.focus();
await emailInput.type(process.env.SHOPIFY_PARTNER_EMAIL);
hardkoded
  • 18,915
  • 3
  • 52
  • 64