0
問題:ページ上のリンク数をカウントできます。分度器:httpGetは定義されていません。ハイパーリンクのレスポンスコードが必要
有効かどうかをテストします。 .click - >これを使うと、 "404ページが見つかりませんでした"というハイパーリンクを分かりやすいものにすることができます。
エラーコードまたは応答コードを使用します。 2つのエラーの周りに基づいて、すべてがあり、この上のいくつかのSOの答えがありますが、何らかの理由でそれらのどれも動作しません:
カントは、HTTP GETモジュール
OR
ステータスコードが定義されていない使用します。助言がありますか?
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
「httpGet」は明確に定義されていません。 [here](https://stackoverflow.com/questions/41467777/protractor-http-response-testing)の例に従おうとしている場合は、httpget関数をコピーしてください。また、 'http'ライブラリには行が必要です同じように。ありがとう。 – alecxe