在我的工作中,我们有一些测试在我的同事本地机器上失败但不在我的或我们运行测试的代理上,我们无法弄清楚原因。我的印象是,当你使用量角器时,每个它都在控制流中排队并按顺序执行。我们在我的同事机器上看到的是,即使先前的承诺尚未得到解决,其后续执行。我已经删除了与工作相关的细节,希望下面的代码片段足以了解正在发生的事情。
我对量角器的理解是错误的还是我的同事机器上有问题?
"use strict";
describe('Test Title', function() {
let fetchedData,
createdData;
beforeAll(()=> globalHelper.logIn());
afterAll(()=> globalHelper.logOut());
it("Precondition: set to clean state", function () {
environmentHelper.cleanEnvironment();
});
it("Get data from server", function () {
fetchDataFromServer()
.then((result) => {
fetchedData = result;
});//we expect execution of the test to stop until this promise is resolved and an error is thrown or the code inside the then is executed
});
it("Next Step", function () {
//do some things
});
it("Next step", function (){
//do more things
});
it("Navigate to page", () => {
//navigate to page
});
it("create some data", function () {
//create some data
});
it("another step", function () {
//do even more things
});
it("Clean up", function() {
environmentHelper.removeCreatedData(createdData);
});
});
任何帮助将不胜感激。提前致谢
答案 0 :(得分:0)
我会在fetchDataFromServer
上添加额外的日志记录,并且可能有一个catch语句,
it("Get data from server", function () {
fetchDataFromServer().then((result) => {
console.log('data fetched from server complete');
fetchedData = result;
}).catch(err => {
console.error('something bad happened here);
});
//we expect execution of the test to stop until this promise is resolved and an error is thrown or the code inside the then is executed
});
it("Next Step", function () {
console.log("next step");
//do some things
});
量角器应该根据angular/jasminewd
等待承诺在it块内解析。对于controlFlow
,selenium-webdriver将承诺排队并按顺序解析它们,因此当您发送browser.get
或element(by.css('')).click
时,它们会按顺序发生。