async / await - 示例规范问题

时间:2017-10-11 22:01:40

标签: async-await protractor

在尝试运行示例spec时,脚本中的更改如下所示并低于错误。它看起来像在执行断言之前阻止它将URL更改为谷歌然后检查谷歌页面上的断言。

import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor';

describe('async function', function() {
  it('should wait on async function in conditional', async function(): Promise<any> {
    await browser.get('http://www.angularjs.org');
    const todoList = element.all(by.repeater('todo in todoList.todos'));
    if ((await todoList.count()) > 1) {
      expect((await todoList.get(1).getText())).toEqual('build an AngularJS app');
    }
        await browser.get('http://www.google.com');
      });
    });

错误:

[10:58:03] E/protractor - Could not find Angular on page http://www.google.com/ : retries looking for angular exceeded

  async function
    ✗ should wait on async function in conditional
      - Failed: Angular could not be found on the page http://www.google.com/.If this is not an Angular application, you may need to turn off waiting for Angular.
                                Please see 
                                https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular-on-page-load
                                Please see 
                                https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular-on-page-load
          at executeAsyncScript_.then (/node_modules/protractor/lib/browser.ts:936:29)

1 个答案:

答案 0 :(得分:2)

您向GET发出browser.get请求的每个页面都需要运行AngularJS。 Google没有运行AngularJS,因此您的请求失败了。第一个请求(到www.angularjs.org 工作,因为它们自己运行AngularJS,因此Protractor能够在该页面上运行。

正如错误消息所示,&#34; 如果这不是Angular应用程序,您可能需要关闭等待Angular &#34;。您可以通过在browser.waitForAngularEnabled(false)之前运行browser.get告诉Protractor目标页面不是Angular应用程序,但请记住,您可能希望稍后再重新打开它!

希望这有帮助! :)