量角器没有识别打开的原生警报

时间:2016-07-18 08:34:51

标签: javascript selenium-webdriver jasmine protractor alertdialog

我试图处理本机打开的警报,但量角器没有识别此警报并向控制台发送错误 -

  

1)测试案例拉 - LiveSite - 调用          信息:            NoSuchAlertError:没有警报打开         (会话信息:chrome = 51.0.2704.103)         (驱动程序信息:chromedriver = 2.14.313457(3d645c400edf2e2c500566c9aa096063e707c9cf),platform = Windows NT 10.0   x86_64)(警告:服务器未提供任何堆栈跟踪   信息)       命令持续时间或超时:9毫秒       构建信息:版本:' 2.45.0',修订版:' 5017cb8',时间:' 2015-02-26 23:59:50'       系统信息:主机:' vCitaQA',ip:' 10.0.0.5',os.name:' Windows 10',os.arch:' amd64',os.version:' 10.0',java.version:' 1.8.0_65'       驱动程序信息:org.openqa.selenium.chrome.ChromeDriver       功能[{applicationCacheEnabled = false,rotate = false,mobileEmulationEnabled = false,   铬= {userDataDir = C:\ Users \用户IDAN \应用程序数据\本地\ TEMP \ scoped_dir3336_20019},   takesHeapSnapshot = true,databaseEnabled = false,handlesAlerts = true,   version = 51.0.2704.103,platform = XP,browserConnectionEnabled = false,   nativeEvents = true,acceptSslCerts = true,locationContextEnabled = true,   webStorageEnabled = true,browserName = chrome,takesScreenshot = true,   javascriptEnabled = true,cssSelectorsEnabled = true}]       会议ID:96c8dfa136495b599f607d50616468de          堆栈跟踪:            NoSuchAlertError:没有警报打开         (会话信息:chrome = 51.0.2704.103)         (驱动程序信息:chromedriver = 2.14.313457(3d645c400edf2e2c500566c9aa096063e707c9cf),platform = Windows NT 10.0   x86_64)(警告:服务器未提供任何堆栈跟踪   信息)       命令持续时间或超时:9毫秒       构建信息:版本:' 2.45.0',修订版:' 5017cb8',时间:' 2015-02-26 23:59:50'       系统信息:主机:' vCitaQA',ip:' 10.0.0.5',os.name:' Windows 10',os.arch:' amd64',os.version:' 10.0',java.version:' 1.8.0_65'       驱动程序信息:org.openqa.selenium.chrome.ChromeDriver       功能[{applicationCacheEnabled = false,rotate = false,mobileEmulationEnabled = false,   铬= {userDataDir = C:\ Users \用户IDAN \应用程序数据\本地\ TEMP \ scoped_dir3336_20019},   takesHeapSnapshot = true,databaseEnabled = false,handlesAlerts = true,   version = 51.0.2704.103,platform = XP,browserConnectionEnabled = false,   nativeEvents = true,acceptSslCerts = true,locationContextEnabled = true,   webStorageEnabled = true,browserName = chrome,takesScreenshot = true,   javascriptEnabled = true,cssSelectorsEnabled = true}]       会议ID:96c8dfa136495b599f607d50616468de           at new bot.Error(C:\ automation \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ atoms \ error.js:113:18)           at Object.bot.response.checkResponse(C:\ automation \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ atoms \ response.js:106:9)           在C:\ automation \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ webdriver \ webdriver.js:377:20           at [object Object] .promise.ControlFlow.runInFrame_(C:\ automation \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ webdriver \ promise.js:1877:20)           在[object Object] .promise.Callback_.goog.defineClass.notify(C:\ automation \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ webdriver \ promise.js:2464:25)           at [object Object] .promise.Promise.notify_(C:\ automation \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ webdriver \ promise.js:563:12)           at Array.forEach(native)           at Object.goog.array.forEach(C:\ automation \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ goog \ array \ array.js:203:43)           在[object Object] .promise.Promise.notifyAll_(C:\ automation \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ webdriver \ promise.js:552:16)           在goog.async.run.processWorkQueue(C:\ automation \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ goog \ async \ run.js:125:21)       来自:任务:异步测试功能:it()           在[object Object]。 (C:\自动化\ NPM \ node_modules \量角器\ node_modules \ jasminewd \ index.js:93:33)           在[object Object]。 (C:\自动化\ NPM \ node_modules \量角器\ node_modules \ minijasminenode \ lib中\异步-callback.js:45:37)           at [object Object] .jasmine.Block.execute(C:\ automation \ npm \ node_modules \ protractor \ node_modules \ minijasminenode \ lib \ jasmine-1.3.1.js:1174:17)           at [object Object] .jasmine.Queue.next_(C:\ automation \ npm \ node_modules \ protractor \ node_modules \ minijasminenode \ lib \ jasmine-1.3.1.js:2209:31)           at [object Object] ._ onTimeout(C:\ automation \ npm \ node_modules \ protractor \ node_modules \ minijasminenode \ lib \ jasmine-1.3.1.js:2199:18)       错误           在[object Object]。 (C:\自动化\测试\测试用例\ NEWAPP \ livesiteClient.js:74:3)           at [object Object] .jasmine.Env.describe_(C:\ automation \ npm \ node_modules \ protractor \ node_modules \ minijasminenode \ lib \ jasmine-1.3.1.js:913:21)           at [object Object] .jasmine.Env.describe(C:\ automation \ npm \ node_modules \ protractor \ node_modules \ minijasminenode \ lib \ jasmine-1.3.1.js:898:15)           at describe(C:\ automation \ npm \ node_modules \ protractor \ node_modules \ minijasminenode \ lib \ jasmine-1.3.1.js:658:27)           在对象。 (C:\自动化\测试\测试用例\ NEWAPP \ livesiteClient.js:1:63)

我已经尝试过使用 -

 describe('vCita Production - Livesite (client side)', function() {

   var EC = protractor.ExpectedConditions;
   var callBtn = $$('div.action-content.layout-align-center.layout-column.flex').get(1); 

      beforeEach(function() {
        browser.ignoreSynchronization = true;
      });

      afterEach(function() {
        browser.ignoreSynchronization = false;
      });

  it('click on call button', function() {
    callBtn.click().then(function(){
      browser.driver.sleep(2000);
      browser.driver.switchTo().alert().dismiss();
    });
  });
});  

以及下面的代码(这实际上是有效的,但它只是忽略了alret并且没有进入"(警报)" if语句 -

browser.getAllWindowHandles().then(function (handles) {      
    browser.switchTo().window(handles[handles.length - 1]);
    var alertDialog = browser.switchTo().alert().thenCatch(function (e) {
        if (e.code !== 27) { throw e; }
    }).then(function (alert) {
        if (alert) {
            expect(alertDialog.getText()).toEqual("External Protocol Request");
            return alert.dismiss();
        }

callBtn.click();

1 个答案:

答案 0 :(得分:0)

问题是,这是"外部协议请求" dialog - 它不是本机警报,是一个浏览器/系统对话框,无法从量角器/ Selenium端控制。以下是chrome

中包含一些其他信息的相关主题

对于Firefox,事情可能会更简单。我的想法是:

  • 首先手动打开Firefox,点击"调用"按钮并选择默认应用程序
  • 转到"帮助" - >"疑难解答信息"然后单击"配置文件夹中的按钮"行
  • 将路径复制到配置文件目录并start protractor+firefox with this profile