Cypress系列(46)- then() 命令详解

简介: Cypress系列(46)- then() 命令详解

如果想从头学起Cypress,可以看下面的系列文章哦

https://www.cnblogs.com/poloyy/category/1768839.html

 

作用


  • 在 Cypress 中,保存一个值或者引用的最好方式是使用闭包
  • then() 就是 Cypress 对闭包的一个典型应用
  • then() 返回的是上一个命令的结果,并将其注入到下一个命令中

 

语法格式


.then(callbackFn)
.then(options, callbackFn)


参数说明

  • options:只有 timeout,4000ms
  • callbackFn:回调函数,需要将上一个命令的结果作为参数进行传递

 

实际栗子


then 回调函数最简单的两种写法

image.png

第一种是箭头函数,第二种就是普通声明函数的方式

 

通过 then 和 should 比较文本是否相等

image.png

相关文章
Cypress系列(80)- setCookie() 命令详解
Cypress系列(80)- setCookie() 命令详解
117 0
Cypress系列(80)- setCookie() 命令详解
Cypress系列(73)- within() 命令详解
Cypress系列(73)- within() 命令详解
239 0
Cypress系列(73)- within() 命令详解
|
JavaScript
Cypress系列(76)- cloest() 命令详解
Cypress系列(76)- cloest() 命令详解
280 0
Cypress系列(76)- cloest() 命令详解
|
测试技术
Cypress系列(81)- clearCookie() 命令详解
Cypress系列(81)- clearCookie() 命令详解
150 0
Cypress系列(81)- clearCookie() 命令详解
Cypress系列(78)- getCookie() 命令详解
Cypress系列(78)- getCookie() 命令详解
263 0
Cypress系列(78)- getCookie() 命令详解
|
JSON 数据格式
Cypress系列(95)- writeFile() 命令详解
Cypress系列(95)- writeFile() 命令详解
208 0
Cypress系列(95)- writeFile() 命令详解
|
测试技术
Cypress系列(82)- clearCookies() 命令详解
Cypress系列(82)- clearCookies() 命令详解
134 0
Cypress系列(82)- clearCookies() 命令详解
Cypress系列(79)- getCookies() 命令详解
Cypress系列(79)- getCookies() 命令详解
200 0
Cypress系列(79)- getCookies() 命令详解
|
索引
Cypress系列(74)- each() 命令详解
Cypress系列(74)- each() 命令详解
282 0
Cypress系列(74)- each() 命令详解
|
索引
Cypress系列(51)- its() 命令详解
Cypress系列(51)- its() 命令详解
202 0