量角器E2E测试错误:对象[对象]没有方法'getWindowHandle' [英] Protractor E2E Testing Error : Object [object Object] has no method 'getWindowHandle'

查看:109
本文介绍了量角器E2E测试错误:对象[对象]没有方法'getWindowHandle'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过点击按钮检查弹出的Facebook登录开始。

I am trying to check the pop up for facebook login opening on click of button .

Error : Object [object Object] has no method 'getWindowHandle'.

代码片段生成错误:

describe('Tests', function() {
  var ptor;
  var handlePromise;
  var util = require('util');

  beforeEach(function() {
    ptor = protractor.getInstance();
    handlePromise = ptor.getAllWindowHandles();
    var handlesDone = false;
    ptor.get('/SiteB_Upgrade_Device/app/index.html#/Recommendations#page');
    ptor.findElement(by.id('fb')).click();
    ptor.ignoreSynchronization = true;
  });

  describe('login', function() {
    return it('should switch to popUp\'s handle', function() {
      handlePromise.then(function(handles) {
        var popUpHandle = handles[0];
        var handle = browser.driver.switchTo().window(popUpHandle).getWindowHandle();
        expect(handle).toEqual(popUpHandle);
      });
    },30000);
  });
});


推荐答案

以下是我目前用于浏览弹出窗口的内容/标签:

Here is what I currently use to navigate through popups/tabs :

// do stuff that will trigger the popup
// ...
browser.getAllWindowHandles().then(function (handles) {
  // switch to the popup
  browser.switchTo().window(handles[1]);
  // make sure the popup is now focused
  expect(browser.getCurrentUrl()).toEqual('popup/url');
  // do stuff with the popup
  // ...
  // go back to the main window
  browser.switchTo().window(handles[0]);
  // make sure we are back to the main window
  expect(browser.getCurrentUrl()).toEqual('original/url');
});

你只需要确保你的弹出窗口真的是一个新窗口而不是某种弹出窗口(在这种情况下,您可以使用css选择器来定位它)。

You just need to make sure that your popup is really a new window and not juste some kind of popover ( in which case you can just target it with css selectors ).

当你更改标签/弹出窗口时,要记住的另一件事是目标页面可能没有加载angularjs,这会渲染量角器用法。如果你遇到这种情况,你只需使用 browser.driver 代替浏览器来导航非角度页面。

Another thing to keep in mind when you change tabs/popups it that the target page might not have angularjs loaded in it, which will render protractor useles. If you face this case you can simply use browser.driver as a replacement for browser to navigate a non angular page.

希望这会有所帮助。

这篇关于量角器E2E测试错误:对象[对象]没有方法'getWindowHandle'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆