量角器:未定义 httpGet;需要来自超链接的响应代码
Protractor: httpGet is not defined; Need Response codes from Hyperlinks
问题:我能够计算页面上的链接数。
我想测试它们是否有效。虽然我可以使用 .click -> 这将验证指向 Protractor 的超链接,即“404 页面未找到”。
我想使用错误代码或响应代码。对此有几个 SO 答案,但出于某种原因 none 其中的答案都基于两个错误:
无法使用 http get 模块
或
状态代码未定义。有什么建议吗?
Spec.js:
browser.waitForAngularEnabled(false);
describe('Clicks on the correct Drupal hyperlink', function() {
it('should find all links', function () {
browser.get('file:///C:/Users/Dasman/Documents/PROTRACTOR_E2E_TESTING/TestSite.html');
let allLinks = element.all(by.tagName('a'));
allLinks.count().then(function(link_tally){
console.log('There are a total of ' + link_tally + " links on this page with proper tags.")
})
browser.sleep(2000);
// A Protracterized httpGet() promise
function httpGet(siteUrl) {
var http = require('http');
var defer = protractor.promise.defer();
http.get(siteUrl, function(response) {
var bodyString = '';
response.setEncoding('utf8');
response.on("data", function(chunk) {
bodyString += chunk;
});
response.on('end', function() {
defer.fulfill({
statusCode: response.statusCode,
bodyString: bodyString
});
});
}).on('error', function(e) {
defer.reject("Got http.get error: " + e.message);
});
return defer.promise;
}
it('should return 200 and contain proper body', function() {
httpGet(allLinks).then(function(result) {
allLinks.count().then(function(statusCode){
console.log('Status code is: ' + statusCode)
})
expect(result.statusCode).toBe(200);
expect(result.bodyString).toContain('Apache');
});
});
});
});
Conf.js:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js']
};
错误:
1) Clicks on the correct Drupal hyperlink should find all links
Message:
Failed: httpGet is not defined
在其他问题的帮助下,我能够解决这个问题!
https://github.com/SDasman/Angular_Protractor_End2End_Tests/tree/master/LinkCheck
问题:我能够计算页面上的链接数。
我想测试它们是否有效。虽然我可以使用 .click -> 这将验证指向 Protractor 的超链接,即“404 页面未找到”。
我想使用错误代码或响应代码。对此有几个 SO 答案,但出于某种原因 none 其中的答案都基于两个错误:
无法使用 http get 模块
或
状态代码未定义。有什么建议吗?
Spec.js:
browser.waitForAngularEnabled(false);
describe('Clicks on the correct Drupal hyperlink', function() {
it('should find all links', function () {
browser.get('file:///C:/Users/Dasman/Documents/PROTRACTOR_E2E_TESTING/TestSite.html');
let allLinks = element.all(by.tagName('a'));
allLinks.count().then(function(link_tally){
console.log('There are a total of ' + link_tally + " links on this page with proper tags.")
})
browser.sleep(2000);
// A Protracterized httpGet() promise
function httpGet(siteUrl) {
var http = require('http');
var defer = protractor.promise.defer();
http.get(siteUrl, function(response) {
var bodyString = '';
response.setEncoding('utf8');
response.on("data", function(chunk) {
bodyString += chunk;
});
response.on('end', function() {
defer.fulfill({
statusCode: response.statusCode,
bodyString: bodyString
});
});
}).on('error', function(e) {
defer.reject("Got http.get error: " + e.message);
});
return defer.promise;
}
it('should return 200 and contain proper body', function() {
httpGet(allLinks).then(function(result) {
allLinks.count().then(function(statusCode){
console.log('Status code is: ' + statusCode)
})
expect(result.statusCode).toBe(200);
expect(result.bodyString).toContain('Apache');
});
});
});
});
Conf.js:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js']
};
错误:
1) Clicks on the correct Drupal hyperlink should find all links
Message:
Failed: httpGet is not defined
在其他问题的帮助下,我能够解决这个问题!
https://github.com/SDasman/Angular_Protractor_End2End_Tests/tree/master/LinkCheck