量角器,当我应该使用则()点击后()量角器、当我

由网友(月照入星海)分享简介:我运行的应用程序角度和量角器测试点击()的时候,我不知道什么时候我应该可以解决了则()。我发现这对量角器API:  当点击命令完成,将解决的希望。所以,我应该使用点击()。那么()在每个点击?解决方案   所以,我应该在每次点击使用点击()。那么()?非也。 这是没有必要的,因为量角器/ WebDriverJS有这种机...

我运行的应用程序角度和量角器测试点击()的时候,我不知道什么时候我应该可以解决了则()。

我发现这对量角器API:

  

当点击命令完成,将解决的希望。

所以,我应该使用点击()。那么()在每个点击

解决方案   

所以,我应该在每次点击使用点击()。那么()?

非也。

这是没有必要的,因为量角器/ WebDriverJS有这种机制称为控制流这基本上是一个需要解决的承诺队列:

  

WebDriverJS保持未决承诺队列,称为控制  流动,以保持组织执行

和量角器等待角自然和外的开箱:

  用刻度尺和量角器在图中找一点P,使点P满足两个条件 1到射线OA好OB的距离相等 2到点C好点D的距离相等.

您不再需要添加等待,可供您的测试。量角器  可以在测试自动执行下一步骤的时刻  网页完成尚未完成的任务,所以您不必担心  等待您的测试和网页同步。

这导致了相当直接的测试code:

  VAR elementToBe present =元素(by.css(anotherelementclass。))是present()。期待(elementToBe present.is present())TOBE(假)。元件(by.css(#myButton的))点击()。期待(elementToBe present.is present())TOBE(真)。 

虽然有时,如果你遇到同步/时序问题,或在测试您的应用程序是无棱角,你可以通过用则(),继续点击回调里面:

 预期(elementToBe present.is present())TOBE(假)。元素(by.css(#则myButton))。点击()。然后(函数(){    期待(elementToBe present.is present())TOBE(真)。}); 

有也明确等待来在这些情况下的救援,但它不是与此有关。

I'm running an Angular app and when testing on protractor a click(), I don't know when should I resolve the promise with a then().

I found this on Protractor API:

A promise that will be resolved when the click command has completed.

So, should I use click().then() in every click?

解决方案

So, should I use click().then() in every click?

Definitely not.

It's not needed because Protractor/WebDriverJS has this mechanism called "Control Flow" which is basically a queue of promises that need to be resolved:

WebDriverJS maintains a queue of pending promises, called the control flow, to keep execution organized.

and Protractor waits for Angular naturally and out-of-the-box:

You no longer need to add waits and sleeps to your test. Protractor can automatically execute the next step in your test the moment the webpage finishes pending tasks, so you don’t have to worry about waiting for your test and webpage to sync.

Which leads to a quite straight-forward testing code:

var elementToBePresent = element(by.css(".anotherelementclass")).isPresent();

expect(elementToBePresent.isPresent()).toBe(false);
element(by.css("#mybutton")).click();
expect(elementToBePresent.isPresent()).toBe(true);

Sometimes though, if you experience synchronization/timing issues, or your app under test is non-Angular, you may solve it by resolving the click() explicitly with then() and continue inside the click callback:

expect(elementToBePresent.isPresent()).toBe(false);
element(by.css("#mybutton")).click().then(function () {
    expect(elementToBePresent.isPresent()).toBe(true);
});

There are also Explicit Waits to the rescue in these cases, but it's not relevant here.

阅读全文

相关推荐

最新文章