前端自动化测试框架Cypress(十一)---导航功能(go,reload,visit)

25 篇文章 18 订阅
25 篇文章 18 订阅

web页面上的导航功能,上一页,下一页,重新加载页面,直接访问页面。
.go() 上一页,下一页
语法:

cy.go(direction)
cy.go(direction, options)

使用:

上一页

cy.go(-1) 
cy.go('back') 

下一页

cy.go(1) 
cy.go('forward') 

.reload() 刷新页面
语法:

cy.reload()
cy.reload(forceReload)
cy.reload(options)
cy.reload(forceReload, options)

例:

cy.visit('http://localhost:3000/admin')
cy.get('#undo-btn').click().should('not.be.visible')
cy.reload()
cy.get('#undo-btn').click().should('not.be.visible')

.visit() 访问页面
语法:

cy.visit(url)
cy.visit(url, options)
cy.visit(options)

cy.visit('http://localhost:3000')    // Yields the window of the remote page
cy.visit('./pages/hello.html')

options:

  • url – null 要访问的URL
  • method – GET 请求方法(GET,POST)
  • bpdy – null 随POST请求一起发送的可选主体。如果它是一个字符串,它将不加修改地传递。如果它 是一个对象,它将是URL编码的字符串,并发送一个Content-Type:application/x-www-urlencoded头部
  • headers – {} 请求头部
  • qs – null 附加到请求url的查询参数
  • log – true 日志信息
  • auth – null 添加基本授权头信息
  • failOnStatusCode – 2xx和3xx以外的响应码是否失败
  • onBeforeLoad – function 在页面加载其所有资源之前调用
  • onLoad – function 在页面触发其加载事件后调用。
  • retryOnStatusCodeFailure – false Cypress是否应该在后台自动重试状态代码错误。如果设置为true,
    Cypress将重试请求最多4次
  • retryOnNetworkFailure – true Cypress是否应该自动重试暂态网络错误的引擎盖。如果设置为true,
    Cypress将重试请求最多4次。
  • timeout – pageLoadTimeout 页面超时时间

超时时间设置

cy.visit('/index.html', { timeout: 30000 })

授权 auth

cy.visit('https://www.acme.com/', {
  auth: {
    username: 'wile',
    password: 'coyote'
  }
})

将用户名密码放在URL中

cy.visit('https://wile:coyote@www.acme.com')

onBeforeLoad

cy.visit('http://localhost:3000/#dashboard', {
  onBeforeLoad: (contentWindow) => {
    // contentWindow is the remote page's window object
  }
})

onLoad

cy.visit('http://localhost:3000/#/users', {
  onLoad: (contentWindow) => {
    // contentWindow is the remote page's window object
    if (contentWindow.angular) {
      // do something
    }
  }
})

qs

// visits http://localhost:3500/users?page=1&role=admin
cy.visit('http://localhost:3500/users', {
  qs: {
    page: '1',
    role: 'admin'
  }
})

参数直接通过url传递

// visits http://example.com/users?page=1&admin=true
cy.visit('http://example.com/users?page=1', {
  qs: { admin: true }
})

提交表单

cy.visit({
  url: 'http://localhost:3000/cgi-bin/newsletterSignup',
  method: 'POST',
  body: {
    name: 'George P. Burdell',
    email: 'burdell@microsoft.com'
  }
})

更多系列文章:https://blog.csdn.net/qq_33676825

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值