Javascript 量角器试验

Javascript 量角器试验,javascript,protractor,automated-tests,Javascript,Protractor,Automated Tests,我需要一些帮助。 这是我的代码片段,我无法从中返回布尔值(“是否存在”) ,所以一切都不正常。我哪里错了 describe("first TEST", function () { var boolean, parsingAllProfiles, getRandomProfile, randomProfile; it("present or not", function () { freelan.notFreelancersFound.isPresent().t

我需要一些帮助。 这是我的代码片段,我无法从中返回布尔值(“是否存在”) ,所以一切都不正常。我哪里错了

describe("first TEST", function () {

    var boolean, parsingAllProfiles, getRandomProfile, randomProfile;

    it("present or not", function () {
        freelan.notFreelancersFound.isPresent().then(function (result) {
            **return boolean = result;**
        })
    })

    if (boolean) {
        console.log("NOTHING!!!!!")
    } else {

        it("array of profiles", function() {
            Promise.resolve(freelan.parsingAllProfilePage()).then(function (profiles) {
                var arrForCheck = freelan.cloneArray(profiles);
                freelan.checkKeywordInProfile(arrForCheck, params.keyword);
                return randomProfile = profiles[Math.floor(Math.random() * profiles.length)];
            })
        });        
    }
});

我不知道有问题的库,但是基于promise的代码是异步的,这意味着这个内部代码
**返回boolean=result**将在主函数中的其他内容之后才会运行

it("present or not", function () {
      freelan.notFreelancersFound.isPresent().then(function (result) {
          **return boolean = result;**
      })
})

你真正需要做的是仔细阅读承诺,然后学习如何连锁。如果您从测试中返回一个承诺,它将等待该承诺得到解决,然后再进行下一个测试。

我不确定您到底想用布尔值做什么,但下面是在带有链接承诺的测试中它可能是什么样子

describe("first TEST", function () {

    var boolean, parsingAllProfiles, getRandomProfile, randomProfile;

    it("present or not", function () {
        freelan.notFreelancersFound.isPresent().then(function(result) {
            if (result) {
                freelan.parsingAllProfilePage().then(function(profiles) {
                    var arrForCheck = freelan.cloneArray(profiles);
                    expect(freelan.checkKeywordInProfile(arrForCheck, params.keyword).toBe(true);
                });
            } else {
                console.log("NOTHING!!!!!");
            }
        });
    });

});

非常感谢你。后来我明白了,那个条件一定是“内链”。这是我第一个关于Proactor的大型测试脚本。