javascript - 使用测试对象的全局导入访问 TestCafe `t.testRun` 数据
问题描述
我正在尝试向我们发送的请求添加一些跟踪标头(作为我们自动化测试的一部分),以帮助调试。我希望使用t.testRun.test.id
,以便我们可以将所有请求链接回测试......但是我不断得到TypeError: Cannot read property 'test' of undefined
.
我正在使用t
. 除了将测试对象 ( t
) 传递给每个函数之外,还有什么方法可以访问 testRun 对象吗?
要重现,只需执行
import { t } from 'testcafe';
fixture('<name>')
.page('<page>')
.beforeEach(async () => {
console.log(await t.testRun.test.id);
};
test('<name>', async () => {/*...*/});
解决方案
您只能从从or钩子t
获得的对象访问测试运行信息:test
beforeEach/afterEach
.beforeEach(async t => {
console.log(await t.testRun.test.id);
});
全局导入的t
对象仅包含可用的操作,如 click、typeText 等。
请注意,您使用非公开的未记录 API 需要您自担风险。
推荐阅读
- ruby-on-rails - 如何在 Rails 中使用 Bootstrap 在页脚中添加模态并传递参数?
- javascript - 如何显示
仅在加载组件中(Ant Design) - python - 如何使用 Groupby 函数找到移动平均线?
- python - np.empty.mean 文档中的给定声明是什么?
- mysql - 带有两个日期列的 sql 查询“where 子句”
- ruby - 使用 send 从 ruby 中的对象实例调用时指定父类
- django - 尝试迁移表时出现 STATICFILES_DIRS 错误 - django heroku
- java - JavaFX:将 ObservableList 绑定到哪个视图?
- javascript - 'then' 和 'catch' 一个接一个的叫
- css - 使用 vuetify 将 btn 定位到对话框的绝对右上角