方法 acceptAlert() 在 Intern/Leadfoot 中不起作用

Method acceptAlert() doesn't work in Intern/Leadfoot

我不明白如何使用 acceptAlert() 方法。它对我不起作用。我尝试接受带有两个按钮的弹出式警报:确定和取消。

这是我的一段测试代码。

queryDatasource: function (kibiUrl, title, description, datasource, query) {
  return this.remote
    .get(require.toUrl(kibiUrl))
    .setFindTimeout(3000)
    .sleep(3000)
    .findByCssSelector('input[ng-model="query.title"]')
      .clearValue()
      .type(title)
      .end()
    .findByCssSelector('input[ng-model="query.description"]')
      .type(description)
      .end()
    .findByCssSelector('option[label="'+ datasource +'"]')
      .click()
      .end()
    .findByName('sqlQuery')
    .findByClassName('ace_text-input')
      .type(query)
      .end()
    .findByXpath('//button[@class="btn btn-success"]')
      .click()
      .end()
    .sleep(1000)
    .acceptAlert()
    .then(function (text) {
      console.log(text);
    });
}

我收到以下错误:

>> FAIL: chrome on any platform - query mysql datasource (3844ms)
UnexpectedAlertOpen: [POST http://localhost:4444/wd/hub/session/0c7cbf33-8724-4cfd-8e9c-4434d4570dbb/element / {"using":"css selector","value":"input[ng-model=\"query.title\"]"}] unexpected alert open: {Alert text : Are you sure you want to overwrite MySQL Datasource?}
  (Session info: chrome=51.0.2704.106)
  (Driver info: chromedriver=2.21.371461 (633e689b520b25f3e264a2ede6b74ccc23cb636a),platform=Linux 4.2.0-41-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1 milliseconds: null
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58'
System info: host: 'Latitude-E5510', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.2.0-41-generic', java.version: '1.8.0_91'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.21.371461 (633e689b520b25f3e264a2ede6b74ccc23cb636a), userDataDir=/tmp/.com.google.Chrome.CXLvym}, takesHeapSnapshot=true, databaseEnable
d=false, handlesAlerts=true, hasTouchScreen=false, version=51.0.2704.106, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: e9d5caeb7c3f4e3e0819b6b65711aa32
* Element info: {Using=css selector, value=input[ng-model="query.title"]}
  at runRequest  <node_modules/intern/node_modules/leadfoot/Session.js:88:40>
  at <node_modules/intern/node_modules/leadfoot/Session.js:109:39>
  at new Promise  <node_modules/intern/node_modules/dojo/Promise.ts:411:3>
  at ProxiedSession._post  <node_modules/intern/node_modules/leadfoot/Session.js:63:10>
  at ProxiedSession.Session.find  <node_modules/intern/node_modules/leadfoot/Session.js:1125:15>
  at Command.<anonymous>  <node_modules/intern/node_modules/leadfoot/Command.js:42:36>
  at <node_modules/intern/node_modules/dojo/Promise.ts:393:15>
  at run  <node_modules/intern/node_modules/dojo/Promise.ts:237:7>
  at <node_modules/intern/node_modules/dojo/nextTick.ts:44:3>
  at nextTickCallbackWith0Args  <node.js:415:9>
  at Command.find  <node_modules/intern/node_modules/leadfoot/Command.js:23:10>
  at Command.prototype.(anonymous function) [as findByCssSelector]  <node_modules/intern/node_modules/leadfoot/lib/strategies.js:24:16>
  at Datasource.queryDatasource  </home/trex/Development/Siren/kibi-integration/tests/functional/support/page/Datasource.js:53:9>
  at Test.query mysql datasource [as test]  </home/trex/Development/Siren/kibi-integration/tests/functional/community/index.js:83:11>
  at <node_modules/intern/lib/Test.js:181:24>
  at <node_modules/intern/browser_modules/dojo/Promise.ts:393:15>
  at runCallbacks  <node_modules/intern/browser_modules/dojo/Promise.ts:11:11>
  at <node_modules/intern/browser_modules/dojo/Promise.ts:317:4>
  at run  <node_modules/intern/browser_modules/dojo/Promise.ts:237:7>
  at <node_modules/intern/browser_modules/dojo/nextTick.ts:44:3>
>> 1/2 tests failed
>> 1/2 tests failed

UnexpectedAlertOpen 错误表示在其中一个查找调用之前打开了一个警告框;查找调用无法继续,因为它被模态警报对话框阻止。

另请注意,acceptAlert 适用于本机浏览器警告框,而不适用于任意框架生成的对话框(此处可能不相关,但请记住一些事项)。