【问题标题】:TestCafe throws an References error for a page element that is not being used in testsTestCafe 为未在测试中使用的页面元素引发引用错误
【发布时间】:2018-12-27 05:48:00
【问题描述】:

我刚开始研究这个名为“testCafe”的测试自动化工具。以下是工具详情:https://devexpress.github.io/testcafe/

在我的第一个测试中,我使用深度 URL 浏览了 2 个页面。这是一个场景 1)点击主页网址 2) 使用另一个 URL 导航到另一个页面 3) 在第 2 页执行断言

我收到以下错误:
1) 页面“https://page2url.com”上的错误:
ReferenceError: initFooterSiteSwitcher 未定义

这是我的代码-firsttest.js

import { Selector } from 'testcafe';
import Page from './homepage-model';
import finAdv from './finAdvisorpage-model';

const page = new Page();
const page_finAdv = new finAdv();


fixture `Getting Started`
.page `https://homepageurl.com`;

test('My first test', async t =>{
    await t
    .navigateTo('page2url.com')    
    .click(page_finAdv.gottoLink)
    .expect(page_finAdv.linktext).eql('Sample text');

});

我查看了 page2url.com 的 DOM,并在 DOM 中找到了这个函数:initFooterSiteSwitcher()。但是正如您所看到的,我在测试中没有与此交互,但我得到了一个错误,并且测试不会继续到测试用例中的下一步。有人可以分享一些关于它的见解。这是应用本身的 HTML 问题还是我的测试?

【问题讨论】:

  • 如果您搜索他们的 github,该功能不会显示,因此很可能是您的网站有问题。当您加载您的网站并打开 F12(开发者工具 chrome)时,它是否显示相同的错误。
  • 您应该在TestCafe命令行中添加--skip-js-errors选项,以防止TestCafe在被测网页出现JS错误时停止执行。
  • 感谢您的快速响应。这有帮助:)

标签: javascript testing automated-tests e2e-testing testcafe


【解决方案1】:

这似乎是应用程序的问题。要检查它,请在浏览器中打开 DevTools,导航到没有 TestCafe 的页面,然后检查控制台选项卡中的输出。

如果您在没有 TestCafe 的情况下可以在控制台选项卡中看到错误,并且网站仍然可以正常运行,则可以在运行测试时使用-e 开关忽略此错误:https://devexpress.github.io/testcafe/documentation/using-testcafe/command-line-interface.html#-e---skip-js-errors

如果没有 TestCafe 没有出现错误,则可能是由 TestCafe 中的错误引起的。在这种情况下,您可以向 TestCafe 存储库提交错误报告:https://github.com/DevExpress/testcafe/issues/new?template=bug-report.md

【讨论】:

  • 谢谢。是的,我检查了控制台,控制台中似乎有错误。所以,我用这个“testcafe chrome test.js -e”作为我的运行命令。谢谢你的帮助!
猜你喜欢
  • 2018-01-24
  • 1970-01-01
  • 1970-01-01
  • 2010-11-14
  • 2023-03-24
  • 2013-05-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多