51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

测试开发精英班,通向高级软件测试工程师【周活动】 找茬--心里圈的故事 !【长期招募】博为峰网校招聘兼职讲师!横扫BAT,Python全栈测试开发技能大全
【106期】:如何树立正确使用Python做开发的习惯 【征稿】提交你的测试成绩单! 【专题】用尽一切办法只为让你学好用例 自学软件测试那点事
查看: 474|回复: 0

强大的全新 Web UI 测试框架 Cypress - Cypress 处理新页签

[复制链接]

该用户从未签到

发表于 2019-4-16 14:18:21 | 显示全部楼层 |阅读模式
场景
点击某个链接或按钮,在新页面(设为新tab)打开了某个地址

解决办法
将这个测试用例分成两个:第一个,监听window.open函数是否被调用过(如果是其他方式,可以采用同样的道理);第二个,直接通过cy.visit访问这个url,然后检查或做后续的步骤...
  1. Accessing new windows via Cypress is not possible in its current version.

  2. However, there are many ways this functionality can be tested in Cypress now. You can split up your tests into separate pieces and still have confidence that your application is covered.

  3. Write a test to check that when performing the action in your app, the window.open event is called by using cy.spy() to listen for a window.open event.
  4. In a new test, use cy.visit() to go to the url that would have opened in the new window, fill in the fields and click the buttons like you would in a Cypress test.
复制代码


  1. cy.visit('http://localhost:3000', {
  2.   onBeforeLoad(win) {
  3.     cy.stub(win, 'open')
  4.   })
  5. }

  6. // Do the action in your app like cy.get('.open-window-btn').click()

  7. cy.window().its('open').should('be.called')

  8. cy.visit('http://localhost:3000/new-window')

  9. // Do the actions you want to test in the new window
  10. Fullly working test example can be found here.
复制代码
回复

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /2 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2019-9-16 10:29 , Processed in 0.061137 second(s), 25 queries .

Powered by Discuz! X3.2

© 2001-2019 Comsenz Inc.

快速回复 返回顶部 返回列表