51Testing软件测试论坛

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

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 5778|回复: 0
打印 上一主题 下一主题

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

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 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.
复制代码
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

本版积分规则

关闭

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

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

GMT+8, 2024-4-27 10:58 , Processed in 0.068303 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

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