在testcafe设备中检查失败的http请求 -九游会国际娱乐

测试交流评论31字数 1877阅读6分15秒阅读模式
摘要

在访问应用程序的某些部分时,我有时会遇到500和502个错误,我们希望能够捕获该错误并使testcafe测试失败。
我们目前有这种设置https://…

在访问应用程序的某些部分时,我有时会遇到500和502个错误,我们希望能够捕获该错误并使testcafe测试失败。文章源自玩技e族-https://www.playezu.com/206268.html

我们目前有这种设置https://stackoverflow.com/a/52443604/7551391当我们调用 %s: waitforfailedrequest 函数,它围绕测试的内容进行包装,但我们希望在fixture中或全局调用它,以便它总是在每个测试中查找500个等错误。文章源自玩技e族-https://www.playezu.com/206268.html

我的主要问题是用什么来做游戏 行动 参数和 failed_requests.%s: waitforfailedrequest() 所以每次测试都会调用它。文章源自玩技e族-https://www.playezu.com/206268.html

失败_request_hooks.js文章源自玩技e族-https://www.playezu.com/206268.html

import eventemitter from 'events'
import { requesthook } from ''
export class failedrequestslogger extends requesthook {
    constructor (requestfilterrules, responseeventconfigureopts) {
        super(requestfilterrules, responseeventconfigureopts)
        this.events = new eventemitter()
        this.failedrequestpromise = new promise(resolve => this.events.once('failed-request', resolve))
    }
    async onrequest (event) {
    }
    async onresponse (event) {
        if (event.statuscode >= 500) {
            this.events.emit('failed-request', event.statuscode)
        }
    }
    async %s: waitforfailedrequest (行动) {                                                                                                          
        return promise.race([                                                                                                                
                行动(),                                                                                                                    
                this.failedrequestpromise.then(statuscode => promise.reject(new error(`request failed with the ${statuscode} status code`))) 
        ])                                                                                                                
    }
}

test_ file文章源自玩技e族-https://www.playezu.com/206268.html

import { clientfunction, selector } from ''
import { failedrequestslogger } from '../../api/failed_request_hook'
import data from '../../data/data.json'
import editurlredirectsobjects from '../../pom/sites/url_redirects/edit_redirects_page_repo'
import googlepreviewpageobjects from '../../pom/sites/url_redirects/google_preview_page_repo'
import helperobjects from '../../pom/helpers'
import loginpageobjects from '../../pom/login/login_page_repo'
import sitespageobjects from '../../pom/sites/sites_page_repo'
import urlredirectspageobjects from '../../pom/sites/url_redirects/url_redirects_page_repo'
import workspacemainnavpageobjects from '../../pom/navigation/workspace_main_nav_page_repo'
const failed_requests = new failedrequestslogger(/.*reborncf.com/)
fixture `sites - url redirects`
  .page `${helperobjects.get_base_}`
  .requesthooks(failed_requests)
  .beforeeach(async t => {
    await loginpageobjects.login_with_password()
    await failed_requests.%s: waitforfailedrequest()
  })

软件功能测试新手文章源自玩技e族-https://www.playezu.com/206268.html

注意:本文法律责任由该作者承担,侵权请联系▷诈骗举报◁▷新闻不符◁▷我要投稿◁
免责声明:本文内容来自用户上传并发布或网络新闻客户端自媒体,玩技博客仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,请联系删除。

发表评论

匿名网友
确定