2017-10-11 61 views
0

尝试运行示例spec,并在脚本中发生如下小改动,并且出现错误。它看起来像在执行断言之前,如果阻止它将URL更改为谷歌,然后检查谷歌页面上的断言。async/await - 与示例规范的问题

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) 
+0

你确定你的意思是'goo凝胶“而不是”谷歌“? “googel.com”在他们的网站上运行Angular的可能性不大(如果它存在的话)。 –

+0

对不起,这是一个错字。但错误是一样的。 – Karthi

回答

2

每次您做出GET请求与browser.get需要的页面是运行AngularJS。谷歌不运行AngularJS,所以你的请求失败。第一个请求(以www.angularjs.org工作,因为它们本身运行AngularJS,并为此量角器能够在该网页上运行。

由于错误消息说,“如果这不是一个角应用程序,你可能需要关闭由browser.get之前运行browser.waitForAngularEnabled(false)等待角”。你可以告诉量角器目标页面是不是一个角应用程序,但请记住,你可能会想在稍后阶段重新打开它!

希望这会有所帮助!:)