2017-10-12 75 views
0

首先我使用的版本:量角器總是失敗的第一個測試

量角器V5.1.2 chromedriver v2.33 節點v6.11.4 NPM 3.10.10 硒的webdriver V3.0.1

我是量角器的新手,我只是試圖在量角器本身給出的測試上運行它。 它看起來像這樣

describe('angularjs homepage', function() { 
    it('should greet the named user', function() { 
    browser.get('http://www.angularjs.org'); 

    element(by.model('yourName')).sendKeys('Julie'); 

    var greeting = element(by.binding('yourName')); 

    expect(greeting.getText()).toEqual('Hello Julie!'); 
    }); 

    describe('todo list', function() { 
    var todoList; 

    beforeEach(function() { 
     browser.get('http://www.angularjs.org'); 

     todoList = element.all(by.repeater('todo in todoList.todos')); 
    }); 

it('should list todos', function() { 
     expect(todoList.count()).toEqual(2); 
     expect(todoList.get(1).getText()).toEqual('build an AngularJS app'); 
    }); 

    it('should add a todo', function() { 
     var addTodo = element(by.model('todoList.todoText')); 
     var addButton = element(by.css('[value="add"]')); 

    addTodo.sendKeys('write a protractor test'); 
    addButton.click(); 

    expect(todoList.count()).toEqual(3); 
    expect(todoList.get(2).getText()).toEqual('write a protractor test'); 
    }); 
    }); 
}); 

這這裏是conf.js

exports.config = { 
    directConnect: true, 

    // Capabilities to be passed to the webdriver instance. 
    capabilities: { 
    'browserName': 'chrome' 
    }, 

    // Framework to use. Jasmine is recommended. 
    framework: 'jasmine', 

    // Spec patterns are relative to the current working directory when 
    // protractor is called. 
    specs: ['example_spec.js'], 

    // Options to be passed to Jasmine. 
    jasmineNodeOpts: { 
    defaultTimeoutInterval: 30000 
    } 
}; 

當我嘗試運行此它給了我下面的錯誤:

Failures: 
1) angularjs homepage should greet the named user 
    Message: 
    Failed: Timed out waiting for asynchronous Angular tasks to finish after 11 seconds. This may be because the current page is not an Angular application. Please see the FAQ for more details: https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular 
    While waiting for element with locator - Locator: by.model("yourName") 
    Stack: 
    ScriptTimeoutError: asynchronous script timeout: result was not received in 11 seconds 
     (Session info: chrome=60.0.3112.113) 
     (Driver info: chromedriver=2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4),platform=Linux 3.16.0-4-amd64 x86_64) 
     at WebDriverError (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/error.js:27:5) 
     at ScriptTimeoutError (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/error.js:203:5) 
     at Object.checkLegacyResponse (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/error.js:505:15) 
     at parseHttpResponse (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/http.js:509:13) 
     at doSend.then.response (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/http.js:440:13) 
     at process._tickCallback (internal/process/next_tick.js:109:7) 
    From: Task: Protractor.waitForAngular() - Locator: by.model("yourName") 
     at Driver.schedule (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:816:17) 
     at ProtractorBrowser.executeAsyncScript_ (/usr/lib/node_modules/protractor/lib/browser.ts:609:24) 
     at angularAppRoot.then (/usr/lib/node_modules/protractor/lib/browser.ts:643:23) 
     at ManagedPromise.invokeCallback_ (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1366:14) 
     at TaskQueue.execute_ (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2970:14) 
     at TaskQueue.executeNext_ (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2953:27) 
     at asyncRun (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2813:27) 
     at /usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:676:7 
     at process._tickCallback (internal/process/next_tick.js:109:7)Error 
     at ElementArrayFinder.applyAction_ (/usr/lib/node_modules/protractor/lib/element.ts:482:23) 
     at ElementArrayFinder.(anonymous function) [as sendKeys] (/usr/lib/node_modules/protractor/lib/element.ts:96:21) 
     at ElementFinder.(anonymous function) [as sendKeys] (/usr/lib/node_modules/protractor/lib/element.ts:873:14) 
     at UserContext.<anonymous> (/home/kunstmann/Downloads/node-v6.11.4-linux-x64/lib/node_modules/npm/node_modules/protractor/example/example_spec.js:5:35) 
     at /usr/lib/node_modules/protractor/node_modules/jasminewd2/index.js:112:25 
     at new ManagedPromise (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1067:7) 
     at ControlFlow.promise (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2396:12) 
     at schedulerExecute (/usr/lib/node_modules/protractor/node_modules/jasminewd2/index.js:95:18) 
     at TaskQueue.execute_ (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2970:14) 
     at TaskQueue.executeNext_ (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2953:27) 
    From: Task: Run it("should greet the named user") in control flow 
     at UserContext.<anonymous> (/usr/lib/node_modules/protractor/node_modules/jasminewd2/index.js:94:19) 
    From asynchronous test: 
    Error 
     at Suite.<anonymous> (/home/kunstmann/Downloads/node-v6.11.4-linux-x64/lib/node_modules/npm/node_modules/protractor/example/example_spec.js:2:3) 
     at Object.<anonymous> (/home/kunstmann/Downloads/node-v6.11.4-linux-x64/lib/node_modules/npm/node_modules/protractor/example/example_spec.js:1:63) 
     at Module._compile (module.js:570:32) 
     at Object.Module._extensions..js (module.js:579:10) 
     at Module.load (module.js:487:32) 
     at tryModuleLoad (module.js:446:12) 

3 specs, 1 failure 
Finished in 17.5 seconds 

[11:34:30] I/launcher - 0 instance(s) of WebDriver still running 
[11:34:30] I/launcher - chrome #01 failed 1 test(s) 
[11:34:30] I/launcher - overall: 1 failed spec(s) 
[11:34:30] E/launcher - Process exited with error code 1 

正如我所說的,我沒有寫這些。該代碼由量角器本身在名爲example的文件夾中提供。 但是,現在我嘗試切換測試用例,因爲我不明白爲什麼第一個測試用例會失敗。它看起來完全適合我。 現在這裏是奇怪的。當我把一個不同的測試用例放在新的測試用例的頂部時(現在處於頂部)將會失敗,但是之前用過的測試用例不會再有任何問題。我可以在每個測試案例中做到這一點,第一個案例總是會失敗,但只要我將它從頂端移開,它就會突然生效。

我已經試過在錯誤消息中的鏈接,但它沒有爲我做任何事情。我也更新了一百次,但沒有任何改變。

是否anyboby知道這是什麼?這真是奇怪......

+0

瀏覽器是否打開'http://www.angularjs.org'頁面。 –

+0

是的,角度頁面打開,我可以看到除第一個之外的所有測試。 –

回答

1

你需要告訴量角器不等待角$ http和$超時,像這樣:

老棄用方式:

browser.ignoreSynchronization = true; 

新正確的方法:

browser.waitForAngularEnabled(false); 

這有幫助嗎?

+0

我在哪裏準確地把它放在我的測試?我很抱歉,我是量角器新手,並沒有完全瞭解所有的東西...... –

+0

它的工作原理!但是,這實際上是在做什麼? –

+0

使用此命令Protractor不會等待$ http或$ timeout任務, 請參見[量角器](http://www.protractortest.org/#/api?view=ProtractorBrowser.prototype.waitForAngularEnabled) 請接受我的回答,如果它工作;-) – Batajus