如何处理量角器测试以按顺序运行

时间:2017-01-10 08:14:49

标签: protractor synchronous

这是我的Block,其中包含element.element(by.model("$ctrl.benchmark.name")); 这不存在于Dom。它给出了错误,即元素不在页面上,但仍然执行在其后写入的所有代码行。我希望这个按顺序处理,如果上面通过然后转到下一个。如何在Protractor中处理这些类型的问题。

it("Test BenchMark",function(){
    browser.getTitle().then(function (name) {
        console.log(name);

        browser.sleep(2000);
        element(by.linkText("Manage Benchmarks")).click();
        browser.sleep(4000)


        //element(by.xpath("//main[@class='ng-scope']//a[text()='Create Benchmark']")).click();
        console.log("megha");
        element(by.model("$ctrl.benchmark.name")).sendKeys("bench");
        element(by.buttonText("Save")).click();
        console.log(megha);
        element(by.xpath("//button[@class='dropdown-toggle']")).click();
        console.log("dropdown clicked")

    });

2 个答案:

答案 0 :(得分:0)

您期望的行为将不会由Protractor处理,它将通过测试框架(例如:Jasmine)来处理。但

 "Jasmine doesn't support failing early, in a single spec. The idea is to give     
  you all of the failures in case that helps figure out what is really wrong 
  in your spec"

答案 1 :(得分:0)

您可以将browser.wait()Expected Conditions结合使用。

browser.wait()阻止控制流程执行,直到解决了承诺,并且预期条件全部评估为承诺。

因此,在您的情况下,您可以使用presenceOf()和/或visibilityOf()

var EC = protractor.ExpectedConditions;
var el = element(by.model("$ctrl.benchmark.name"));
var present = EC.presenceOf(el); // wait for it to be added to DOM
var visible = EC.visibilityOf(el); // wait for it to be visible on page
browser.wait(EC.and(present, visible), 10000); // wait maximum of 10 seconds
// rest of code
相关问题