2017-07-27 69 views
0

我是量角器的新手,正在閱讀教程。設置和步驟0工作對我很好,但我不得不在Step 1意外的錯誤:量角器教程一步投擲「元素不可見」

$ protractor conf.js 
[13:11:41] I/launcher - Running 1 instances of WebDriver 
[13:11:41] I/hosted - Using the selenium server at http://localhost:4444/wd/hub 
Started 
seeking `first` 
seeking `second` 
seeking `gobutton` 
seeking `latest` 
F 

Failures: 
1) Protractor Demo App should add one and two 
    Message: 
    Failed: element not visible 
     (Session info: chrome=60.0.3112.78) 
     (Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Linux 4.4.0-87-generic x86_64) (WARNING: The server did not provide any stacktrace information) 
    Command duration or timeout: 43 milliseconds 
    Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' 
    System info: host: 'pfuntner1', ip: '9.42.83.35', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-87-generic', java.version: '1.8.0' 
    Driver info: org.openqa.selenium.chrome.ChromeDriver 
    Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8), userDataDir=/tmp/.org.chromium.Chromium.ZhadTr}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=60.0.3112.78, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=}] 
    Session ID: cf611f619dbf2069413885ed9bcbba17 
    Stack: 
    ElementNotVisibleError: element not visible 
     (Session info: chrome=60.0.3112.78) 
     (Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Linux 4.4.0-87-generic x86_64) (WARNING: The server did not provide any stacktrace information) 
    Command duration or timeout: 43 milliseconds 
    Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' 
    System info: host: 'pfuntner1', ip: '9.42.83.35', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-87-generic', java.version: '1.8.0' 
    Driver info: org.openqa.selenium.chrome.ChromeDriver 
    Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8), userDataDir=/tmp/.org.chromium.Chromium.ZhadTr}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=60.0.3112.78, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=}] 
. 
. 
. 

我添加調試語句spec.js,試圖找出哪些因素無法找到。它似乎找到了兩個輸入字段和按鈕,但沒有找到輸出字段。

這裏是我的spec.js

// spec.js 
describe('Protractor Demo App', function() { 
    it('should add one and two', function() { 
    browser.get('http://juliemr.github.io/protractor-demo/'); 
    console.log("seeking `first`"); 
    element(by.model('first')).sendKeys(1); 
    console.log("seeking `second`"); 
    element(by.model('second')).sendKeys(2); 

    console.log("seeking `gobutton`"); 
    element(by.id('gobutton')).click(); 

    console.log("seeking `latest`"); 
    expect(element(by.binding('latest')).getText()).toEqual('5'); // This is wrong! 
    }); 
}); 

我做錯什麼了嗎?

+0

安置自己的天賦JS也 –

+0

'// spec.js 描述(「量角器演示應用」,函數(){ 它( 'should add one and two',function(){browser.get('http://juliemr.github.io/protractor-demo/'); console.log(「seek'first'」); element (by.model('first'))。sendKeys(1); console.log(「seeking'second'」); element(by.model('second'))。sendKeys(2); console .log(「seek'gobutton'」); 元素(by.id('gobutton'))。click(); console.log(「seeking'latest'」); (元素(by.binding('latest')).getText())。toEqual('5'); //這是錯誤的! }); });' – pfuntner

回答

0

現在有幾個可能的事情發生在這裏

  1. 由元素返回的元素(by.binding(「最新」))不正確的

  2. 有多種元素匹配元素(by.binding('latest')),第一個返回給您

返回給您的元素在屏幕上不可見。當涉及對用戶可見的元素採取行動時,Chromedriver非常具體。如果元素對用戶不可見,則自動化不應該能夠模擬對其的操作(不是100%爲真,因爲仍可以執行某些操作)。

因此,請確保您得到正確的元素,也沒有多場比賽