gpt4 book ai didi

javascript - Nightmare JS返回页面状态码

转载 作者:行者123 更新时间:2023-12-03 06:29:15 25 4
gpt4 key购买 nike

我想使用 Nightmare JS 通过检查状态代码 200 来确定页面是否正在加载。我查看了 goto 选项,但无法弄清楚。大家有什么想法吗?

var Nightmare = require('nightmare');
var should = require('chai').should();

describe('PageLoad Test', function () {
var url = 'http://www.yahoo.com';
describe('Browse Page', function () {
it('should return 200 status', function (done) {
this.timeout(15000);
new Nightmare()
.goto(url)
.wait(1000)
.evaluate(function () {
return document.querySelector('div.items').innerHTML;
})
.then(function (element) {
element.should.equal(element);
done();
})
.catch(function (error) {
console.error('page failed to load', error);
done('epic failure')
})
});
});
});

最佳答案

这对我检查 200 状态很有用。

    var expect = require('chai').expect;
require('mocha-generators').install();
var Nightmare = require('nightmare');
var nightmare = Nightmare({
show: false,
ignoreSslErrors: true,
webSecurity: false
});

describe('NightmareJS', function () {
this.timeout(15000);
it('should not be a nightmare', function* () {
var status;
yield nightmare
.goto('http://www.google.de')
.end()
.then((gotoResult) => {
status = gotoResult.code;
});
expect(status).to.equal(200);
});

});

关于javascript - Nightmare JS返回页面状态码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38513304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com