使用量角器编辑ui-grid单元格值

时间:2015-04-28 10:52:35

标签: angularjs testing protractor angular-ui-grid end-to-end

我使用量角器来测试角1.3.13和ui-grid 3.0。网格中的所有单元格均可编辑。在我的测试中,我可以使用以下方法获取单元格:

dataCell: function( gridId, fetchRow, fetchCol ) {
    var row = this.getGrid( gridId ).element(by.css('.ui-grid-render-container-body')).element( by.repeater('(rowRenderIndex, row) in rowContainer.renderedRows track by $index').row( fetchRow )  );
    return row.element( by.repeater('(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name').row( fetchCol ));
}
来自https://github.com/angular-ui/ng-grid/blob/master/test/e2e/gridTestUtils.spec.js

从第一行获得第一个单元格后,当我尝试将值发送到单元格

cell.click();
cell.sendKeys("newCellValue");

测试休息。我收到以下错误消息:

    - Failed: unknown error: cannot focus element
    (Session info: chrome=40.0.2214.115)
    (Driver info: chromedriver=2.14.313457
    (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Linux 3.13.0-49-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 35 milliseconds
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'xxxxxxxxx', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-49-generic', java.version: '1.8.0_40'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=/tmp/.com.google.Chrome.LHfq2F}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=40.0.2214.115, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 50857fdfa10a4bc75444d21f2d04359e
(Session info: chrome=40.0.2214.115)
(Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Linux 3.13.0-49-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 35 milliseconds
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'xxxxxxxxx', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-49-generic', java.version: '1.8.0_40'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=/tmp/.com.google.Chrome.LHfq2F}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=40.0.2214.115, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 50857fdfa10a4bc75444d21f2d04359e
  at /usr/lib/node_modules/protractor/node_modules/jasminewd2/index.js:102:16
  at [object Object].promise.ControlFlow.runInFrame_ (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1877:20)
  at [object Object].promise.Callback_.goog.defineClass.notify (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:2464:25)
  at [object Object].promise.Promise.notify_ (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:563:12)

调用sendKeys方法时会出现问题。有没有人知道使用量角器改变细胞价值的正确方法?

1 个答案:

答案 0 :(得分:1)

解决了它。您需要关注单元格并访问输入元素:

cell.click();
cell.element(by.css(".ui-grid-cell-focus input")).sendKeys("newCellValue");

编辑: 在较旧的浏览器版本上存在一些问题,最好使用:

cell.click();
cell.element(by.css("input")).sendKeys("newCellValue");

编辑:

另一个问题是Firefox,其中cell.click()无法正常工作。 解决方法/黑客:https://stackoverflow.com/a/23370177