Protractor E2E Testing Error : Object [object Object] has no method 'getWindowHandle'

心不动则不痛 提交于 2019-12-07 07:41:50

问题


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

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

Code Snippet generating error :

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);
  });
});

回答1:


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');
});

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 ).

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.

Hope this helps.



来源:https://stackoverflow.com/questions/21700162/protractor-e2e-testing-error-object-object-object-has-no-method-getwindowha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!