Puppeteer无法正常运行:true

时间:2019-10-23 09:53:51

标签: javascript puppeteer jest-puppeteer

我有一个测试用例,它从列表中选择发布,然后单击其上的转发按钮以触发模式,然后将其插入DOM并具有2个按钮(确认和取消)。

无头:false-一切正常,显示并单击模态: https://i.imgur.com/oDgFzxC.png

在无头情况下:true-永远不会打开模式: https://i.imgur.com/KTQo91a.png

测试代码

test('should repost conversation', async () => {
    const options = {
      showOwnedBtn: 'showOwned-link',
      ideaSelector: 'searchbar-idea',
      retweetBtn: 'retweet-button',
      selectedPublication: 'The looming challenge to South Korea competitiveness',
      titleSelector: 'publicationTitle-link',
      repostBtn: 'repost-button',
    }
    await login.user(users.hubert, 'wubs', path);
    await navbar.removeFilter(options.showOwnedBtn, path);
    await navbar.searchFilter(options.ideaSelector, path, null);

    await publication.selectPublicationRetweetByTitle(options.titleSelector, options.selectedPublication, path);
    await page.waitForSelector(options.repostBtn)
    await modal.confirm(options.repostBtn, path);

    await navbar.goto('flow', path);

    await screenshot.take(path);
    await logout.user(users.hubert, 'wubs', path);
  });

问题方法:

async selectPublicationRetweetByTitle(selector, text, path) {
    const retweetSelector = dataAutomation('retweet-button');
    const pub = dataAutomation('publication')
    const publicationSelector = await page.$$(pub);
    let selected = null;
    for (const publication of publicationSelector) {
      const pubTitleSelector = await publication.$('[data-automation="publicationTitle-link"]');
      const pubTitle = await pubTitleSelector.getProperty('innerText');
      const titleText = await pubTitle.jsonValue();
      if (titleText === text){
        selected = await publication.$(retweetSelector);
      }
    }
    await screenshot.take(path);
    await selected.click();

    await screenshot.take(path);
  }

0 个答案:

没有答案