无法使用“getByTestID”在测试咖啡馆
我正在尝试使用自定义 data-testID 来识别元素。下面是我的代码 -
import { getByTestId } from '@testing-library/testcafe';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { addTestcafeTestingLibrary } from 'testcafe-testing-library';
import { Selector } from 'testcafe';
export default async function disableVideo(browser) {
await browser.click(getByTestId('Video-Button'));
}
我正在调用disableVideo并看到以下错误 -
选择器代码中发生错误:
错误:无法调用未定义的方法“getByTestId”
我错过了什么吗?以下是我的依赖项 -
“依赖项”:{ "@testing-library/testcafe": "^4.4.0", "chrome-remote-interface": "^0.31.2", "交叉获取": "^3.1.5", "testcafe": "^1.18.4", “testcafe-测试库”:“^1.3.1” }
I am trying to use custom data-testID to identify elements. Below is my code -
import { getByTestId } from '@testing-library/testcafe';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { addTestcafeTestingLibrary } from 'testcafe-testing-library';
import { Selector } from 'testcafe';
export default async function disableVideo(browser) {
await browser.click(getByTestId('Video-Button'));
}
I am calling disableVideo and seeing following error -
An error occurred in Selector code:
Error: Cannot call method 'getByTestId' of undefined
Am I missing something?? Below are my dependencies -
"dependencies": {
"@testing-library/testcafe": "^4.4.0",
"chrome-remote-interface": "^0.31.2",
"cross-fetch": "^3.1.5",
"testcafe": "^1.18.4",
"testcafe-testing-library": "^1.3.1"
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TestCafe 不正式支持
@testing-library/testcafe
包。此外,根据错误文本,问题与testing-library
有关,而不是与testcafe
本身有关。尽管如此,TestCafe 团队将能够帮助解决这个问题。您能否分享一个仅使用 TestCafe 的简单可重现示例?
请注意,TestCafe 不支持 ReactNative 应用程序的测试。
The
@testing-library/testcafe
package is not officially supported by TestCafe. Moreover, according to the error text, the issue is related to thetesting-library
, but not totestcafe
itself.Nevertheless, the TestCafe team will be able to help with solving this problem. Could you please share a simple reproducible example that uses only TestCafe?
Please note that TestCafe doesn't support testing of ReactNative applications.
我也遇到了同样的错误,这是因为我忽略了阅读文档。您需要将其添加到您的 .testcaferc.json 文件中:
I was having the same error, and it was because I neglected to read the documentation. You need to add this to your .testcaferc.json file: