Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Testcafe-如何使用JSON响应数据作为变量_Json_Testing_Automated Tests_Httpresponse_Testcafe - Fatal编程技术网

Testcafe-如何使用JSON响应数据作为变量

Testcafe-如何使用JSON响应数据作为变量,json,testing,automated-tests,httpresponse,testcafe,Json,Testing,Automated Tests,Httpresponse,Testcafe,我想添加一个testcafe步骤,在该步骤中,我调用一个API GET,并使用JSON响应体中的一些内容作为输入到字段中的测试 如何在TestCafe中实现此功能 我试图使用RequestLogger,但它不起作用,它没有发出任何请求 以下是在console中使用时工作的获取: var smscodefeld=document.querySelector`inputcode` 取来 //调用API以获取SMS代码 `https://app.website.com/api/test-helper/

我想添加一个testcafe步骤,在该步骤中,我调用一个API GET,并使用JSON响应体中的一些内容作为输入到字段中的测试

如何在TestCafe中实现此功能

我试图使用RequestLogger,但它不起作用,它没有发出任何请求

以下是在console中使用时工作的获取:

var smscodefeld=document.querySelector`inputcode` 取来 //调用API以获取SMS代码 `https://app.website.com/api/test-helper/getLastSMS` .thenresponse=>response.json //使用代码值作为预定义字段SMScodeField的输入 .thendata=>{smscodefeld.value=data.sms[0].code} 我也有来自Cypress的工作代码

cy.request(`https://app.website.com/api/test-helper/getLastSMS`)
  .then((response) => {
     let body = JSON.parse(response.body)
     cy.get(`input#code`).type(body._embedded.sms[0].code)
   })

如何在TestCafe中实现此行为?我只需要在调用时从JSON响应中获取代码,并将其用作字段SMScodeField的输入。您可以在TestCafe测试中使用标准nodejs代码。只需使用axios或node fetch获取数据,并在稍后的测试中使用它们

npm i -D axios @types/axios
参考资料:
您可以在TestCafe测试中使用标准nodejs代码。只需使用axios或node fetch获取数据,并在稍后的测试中使用它们

npm i -D axios @types/axios
参考资料:
这是一种解决方法,但可以使用节点获取


我还没有试过,但我真的想使用TestCafe的原生功能这是一个解决方法,但是可以使用节点获取

我还没试过,但我真的很想用TestCafe自带的东西