2017-07-27 56 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%为真,因为仍可以执行某些操作)。

因此,请确保您得到正确的元素,也没有多场比赛