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

Edit ui-grid cell value using protractor

我正在使用量角器测试 angular 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方法时出现问题。有谁知道使用量角器更改单元格值的正确方法?

解决了。您需要聚焦单元格并访问输入元素:

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() 无法正常工作。 Workaround/hack: