reactjs - 使用 ReactSelector for TestCafe 时不断收到 `ReExecutablePromise { _then: [], _fn: [Function], _taskPromise: null }`

标签 reactjs automated-tests e2e-testing web-testing testcafe

我正在尝试使用 TestCafe 在 React 网站上实现测试。我想使用 getReact() 打印各种 Prop /属性。但是,当打印到控制台时,我总是得到 ReExecutablePromise { _then: [], _fn: [Function], _taskPromise: null }

这是我的代码:

var sideBar = ReactSelector('Sidebar').getReact();
console.log(sideBar);

我也尝试过获得实际属性(property):

sideBarprops = checkListPage.sideBar.getReact(({ props }) => props.isChecklistVisible);
console.log(sideBar);

任一项目始终打印 ReExecutablePromise { _then: [], _fn: [Function], _taskPromise: null }

我需要能够打印 ReactSelector 的属性、类名、状态、键等的实际值。

最佳答案

getReact() 返回一个 Promise,您需要解析它。您可以这样做

ReactSelector('Sidebar').getReact().then(props => {
   console.log(props);
})

或者这个

var sideBar = ReactSelector('Sidebar').getReact();
console.log(await sideBar);

或者这个

var sideBar = await ReactSelector('Sidebar').getReact();
console.log(sideBar);

关于reactjs - 使用 ReactSelector for TestCafe 时不断收到 `ReExecutablePromise { _then: [], _fn: [Function], _taskPromise: null }`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56669302/

相关文章:

javascript - 回流 : having multiple components access the same Store

selenium - 启动 : Windows opens many instances of Edge, 每个都带有 "ERROR:file_io_win.cc(180)] CreateFile settings.dat: Access is denied. (0x5)"

javascript - componentWillUpdate 在 React 中被弃用,我该如何替换它?

testing - 如何将随机参数传递给 SilkTest Workbench 或 Classic Record&Play Scenario

javascript - 如何从 WebDriver Sampler 中设置 JMeter Vars?

testing - TestCafe工作室: Is it possible to check smetrics records in the network tab of the Google Chrome dev tool through Deep equal assertion?

testing - 在断言上继续测试用例

responsive-design - 使用 TestCafe 进行响应式设计测试

javascript - React 路由器不允许加载图像

javascript - 在 react 中使用javascript闰年 react 问题