此系列文章会同步发文到个人部落格,有兴趣的读者可以前往观看喔。
终於来到铁人赛第30天!谢谢观看我的文章和留言的所有人,第一次参加铁人赛,每天早上都要提醒自己发文,比赛过程中遇到两个连假,深怕自己会撑不到30天,感谢自己无数个深夜和清晨的努力,才能够顺利的完成比赛。
今天要跟大家分享 cy.intercept()
,在 Cypress 6.0.0 後就不再使用 cy.server()
和 cy.route()
使用 cy.intercept()
在网路层管理 HTTP 请求的行为。
可以用 GET, POST, PUT, PATCH, DELETE 等等
cy.intercept('/users')
// matches this: GET http://localhost/users
// ...and this, too: POST http://localhost/users
cy.intercept('GET', '/users')
// matches this: GET http://localhost/users
// ...but not this: POST http://localhost/users
可以用完整的 URL 或正规表示法
cy.intercept('https://prod.cypress.io/users')
// match any request that exactly matches the URL
cy.intercept('/users?_limit=*')
// match any request that satisfies a glob pattern
cy.intercept(/\/users\?_limit=(3|5)$/)
// match any request that satisfies a regex pattern
语法
// spying only
cy.intercept(url)
cy.intercept(method, url)
cy.intercept(routeMatcher)
动手写程序
describe('测试intercept', function() {
it('url用法', function() {
cy.intercept('https://www.thsrc.com.tw/Event/LanguageSettings.json')
})
it('method用法', function() {
cy.intercept('GET', 'https://www.thsrc.com.tw/Event/LanguageSettings.json', {
statusCode: 200,
})
})
})
最後跟大家分享导入 Cypress 的价值,有机会你也可以试试看自动化测试。
<<: Day 29 : 案例分享(9) 活动 - 线上报名、线上缴费及线上会议
有句话是这样说的 好的管理就是不用管理 如果大家都自动自发的 那鼔能量会很令人敬佩 唷唷唷~~~ ...
前言: ConstraintLayout讲完了,画面画好了那是用在那呢? 那就是要放在 Activi...
昨天我们建立一个File资料表要来储存档案实体路径 CREATE TABLE [dbo].[File...
前言 一个网站要让他更完整,势必就需要当使用者进入网站时,先进行读取,但由於技术成分不足,只好先做...
Chart function 身为一个键盘柯南,最重要的技能之一就是储存和下载分析後的结果。另外c...