설명 : "시작됨", "진행 중", "성공", "오류"중 하나로 변경되는 웹 페이지에서 특정 레이블을 읽길 원합니다. 레이블 값이 "success"또는 "error"로 변경되면 더 이상 변경되지 않습니다.자바 스크립트의 재귀 호출에서
문제 : 각도기에서 javascript를 사용하여 레이블 값을 읽을 때 레이블의 텍스트 값이 호출 함수에 반환되지 않습니다. 대신 'undefined'를 반환합니다. 아래는 제 코드입니다. 제발 좀 봐주세요.
CheckColor_Test.js
var commonFunctions = require('../pages/CommonFunctions.js');
describe("Run Test", function() {
it("should stop once the status reached Success or Error", function() {
var processStatus = commonFunctions.refreshTillProcessFinish();
expect(processStatus).toContain('Success','Error');
});
});
각도기에서 실행 CommonFunctions.js
Var CommonFunctions = function(){
var label = element(by.id('Status'));
var refreshStatusBtn = element(by.css('[ng-click="getJob()"]'));
this.getStatusValue = function() {
return label.then(function (headers) {
return headers.getText();
});
};
this.refreshTillRefreshFinish = function() {
var refreshStatusMonitor = function (currentStatus) {
return currentStatus.then(function (Status) {
if (Status == 'Success' || Status.includes("Error")) {
console.log(Status);
return Status;
} else {
refreshStatusBtn.click();
console.log(Status);
browser.sleep(2000);
refreshStatusMonitor (currentStatus);
}
});
};
return refreshStatusMonitor (this.getStatusValue);
};
}
module.exports = new CommonFunctions();
: Webstorm에서 내가 설정 한 각도기, 따라서 나는 그것을 사용하여 실행하는 데 사용됩니다.
예상 결과 : 시험은 성공적으로 얻고
실제 결과를 전달해야합니다 시험은 아래의 오류와 함께 실패합니다.
"C:\Program Files (x86)\JetBrains\WebStorm 2016.1.1\bin\runnerw.exe" "C:\Program Files\nodejs\node.exe" node_modules\protractor\built\cli.js D:\Somesh_HDD\WebstormProjects\ProjectUBET\conf.js
[22:19:59] I/direct - Using ChromeDriver directly...
[22:19:59] I/launcher - Running 1 instances of WebDriver
Spec started
Started
InProgress
Success
Run Test
? should stop once the status reached Success or Error
- Expected undefined to contain 'Success', 'Error'.
**************************************************
* Failures *
**************************************************
1) Run Test should stop once the status reached Success or Error
- Expected undefined to contain 'Success', 'Error'.
Executed 1 of 1 spec (1 FAILED) in 33 secs.
[22:20:36] I/launcher - 0 instance(s) of WebDriver still running
[22:20:36] I/launcher - chrome #01 failed 1 test(s)
[22:20:36] I/launcher - overall: 1 failed spec(s)
[22:20:36] E/launcher - Process exited with error code 1
Process finished with exit code 1
바이올린을 추가하십시오 – YakovL
'currentStatus.then' func의 else 절에 return 문이 필요합니까? – James
@ YakovL 노드 예제가 jsFiddle에서 실행되지 않는다고 생각합니다. – michaPau