gpt4 book ai didi

javascript - 我是否误解了 Protractor 和 ControlFlow?

转载 作者:行者123 更新时间:2023-11-28 05:17:06 25 4
gpt4 key购买 nike

在我的工作中,我们有一些测试在我同事的本地计算机上失败,但在我的或我们运行测试的代理上却失败,我们无法弄清楚原因。我的印象是,当您使用 Protractor 时,每个 Protractor 都会在控制流中排队并按顺序执行。我们在我同事的机器上看到的是,尽管之前的 promise 尚未得到解决,但随后的 promise 仍在执行。我已经删除了与工作相关的细节,希望下面的代码片段足以理解正在发生的事情。

我对 Protractor 的理解是错误的还是我同事的机器有问题?

"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);
});

});

如有任何帮助,我们将不胜感激。提前致谢

最佳答案

我会在 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
});

Protractor 应该等待基于angular/jasminewd的it block 内的 promise 解决。对于 controlFlow,selenium-webdriver 将 Promise 排队并按顺序解析它们,因此当您发送 browser.getelement(by.css('')) 时.click,它们按顺序发生。

关于javascript - 我是否误解了 Protractor 和 ControlFlow?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40890386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com