0
문제점 : 페이지의 링크 수를 계산할 수 있습니다.각도기 : httpGet가 정의되지 않았습니다. 하이퍼 링크의 응답 코드 필요
유효한지 테스트하고 싶습니다. .click ->을 사용하면 분지기에 "404 Page Not Found"하이퍼 링크의 유효성을 검사 할 수 있습니다.
오류 코드 또는 응답 코드를 사용하고 싶습니다. 가이 여러 SO 답변입니다,하지만 그들 중 몇 가지 이유 없음에 대한 두 가지 오류 주위에 모든 기초 작업 :
캔트는 HTTP 모듈을
또는
상태 코드가 정의되어 얻을 사용합니다. 어떤 제안?
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