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 |       

// 
4

1 回答 1

1

focus不返回元素句柄。你可以这样做:

const emailInput = await page.waitForSelector("#account_email");
await emailInput.focus();
await emailInput.type(process.env.SHOPIFY_PARTNER_EMAIL);
于 2020-02-04T17:02:18.770 回答