3

到目前为止,我已经为这个项目总共编写了 12 个测试,并且根据测试的组成,在不同的地方发生了一个错误。

我的问题是关于如何调试这个问题。我将分享错误和测试样本,希望其他人有类似的问题并且对如何解决它有想法。

Uncaught TypeError: Cannot read property 'type' of undefined是有问题的错误,并且没有提到它发生的位置。

从测试的角度来看,下一个动作应该是单击一个按钮并获得一个用于创建新产品的弹出窗口。

该应用程序工作正常且没有问题,它只是报告问题的 e2e 测试。

所报告的测试是孤立地工作的。排除此测试,错误会在另一个测试中出现。

在这篇文章的最后,您将能够看到跳过此测试时引发的错误。

在此处输入图像描述

fixture('Select a product from the list:')
  .page('http://localhost:3000/products');

// @TODO Fix e2e test
test
  .before(generateProducts(page, 1))
  ('clicking the "Close detail" button should return us to the products page.', async t => {
    const productsListItem = await page.listContainer.child(0);
    await t
      .click(productsListItem)
      .click(page.closeDetail)
      .expect(page.productsPageTitle.innerText).eql('PRODUCTS')
  })
  .after(removeGeneratedProducts(detailedProductPage, 1));

test
  .before(generateProducts(page, 2))
  ('selecting another product, while the previous is still opened, should refresh the preview with the new selection.', async(t) => {
    const productListItems = await page.listContainer.find('li');

    const productsListItem0 = await productListItems.nth(0);
    const productsListItem0Title = await productsListItem0.find('[data-test-id="name"]').innerText;

    const productsListItem1 = await productListItems.nth(1);
    const productsListItem1Title = await productsListItem1.find('[data-test-id="name"]').innerText;

    await t
      .click(productsListItem0)
      .expect(page.productTitle.textContent).eql(productsListItem0Title || 'Missing product\'s name')
      .click(productsListItem1)
      .expect(page.productTitle.textContent).eql(productsListItem1Title || 'Missing product\'s name')
  })
  .after(removeGeneratedProducts(detailedProductPage, 2));


fixture('Field state updating when switching between products with an open Quick Edit view')
  .page('http://localhost:3000/products');

test
  .before(async t => {
    await t
      .click(page.showAddProductFormButton)
      .typeText(page.nameField, `${chance.name()} ${Math.floor(Math.random() * 100000) + 1}`)
      .click(page.createNewProductButton)

      .click(page.showAddProductFormButton)
      .click(page.createNewProductButton);
  })
  ('Products quick edit navigation should update the view, and not inherit the values of the previous product', async(t) => {
    const productListItems = await page.listContainer.find('li');
    const productsListItem0 = await productListItems.nth(0);
    const productsListItem1 = await productListItems.nth(1);

    await t
      .click(productsListItem0)
      .expect(page.productTitle.textContent).eql('Missing product\'s name')
      .click(productsListItem1)
      .click(productsListItem0)
      .click(productsListItem1)
      .click(productsListItem0)
      .expect(page.productTitle.textContent).eql('Missing product\'s name')
      .click(productsListItem0)
  })
  .after(removeGeneratedProducts(detailedProductPage, 2));
Don't expect results when running the code. I've used this feature to nicely import the code, nothing more.

跳过原始测试时,在不同的测试中出现相同的错误。 在此处输入图像描述

4

1 回答 1

2

当前产品版本(0.23.0) 中,我们引入了第一次测试失败后停止测试运​​行选项。您现在可以将 TestCafe 配置为在第一次测试失败后停止整个测试运行。当您一一解决测试问题时,这可以节省您的时间。

使用提到的--debug-on-fail选项,您可以指定是否在测试失败时自动进入调试模式。如果启用此选项,TestCafe 会在测试失败时暂停测试。这允许您查看测试页面并确定失败的原因。

此外,您可以使用--debug-mode选项。在这种模式下,测试执行在第一个操作或断言之前暂停,允许您调用开发人员工具和调试。

另请参阅:TestCafe 调试

于 2018-10-29T11:29:52.487 回答