Cypress系列(32)- url() 命令详解

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

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

 

作用

  • 获取页面当前的 url
  • 等价于 cy.location('href') 

 

语法格式

cy.url()
cy.url(options)

options:只有 timeout 和 log,不再展开讲了

 

正确写法

cy.url()

 

实际栗子

测试文件代码

 

测试结果

 

url() 命令在 console 会输出啥

 

location(href) 命令在 console 会输出啥

 

结论

  • 可以看到 cy.url() 和 cy.location('href') 是等价效果的
  • 其实还有更多等价的写法,看下面

 

三种等价的断言方式

测试文件代码

 

测试结果

 

结尾

我的博客即将同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=12vd92hxgwgj1

posted @ 2020-06-16 23:07  小菠萝测试笔记  阅读(2871)  评论(2编辑  收藏  举报