Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Switched to Chrome window does not get focus [switchTo().window(handle)] - Protractor 3/Webdriver 2.53 case #3124

Open
@latobibor

Description

@latobibor

Hi all!

I have a similar problem to this: #55 - though the difference is the expectations working fine, no errors, no exceptions, but it does not switch back to the previous window. I am at my wits end. I tried first with tabs, it did not work, so I switched to windows since them being tabs and not windows is not part of any of our test cases.

How to reproduce it:
http://stackoverflow.com/questions/36578927/protractor-3-0-0-webdriver-2-53-0-switching-tabs-error

it('checks tabs', async () => {
    const url1 = '/login';
    const url2 = config.chatLaunchUrl;

    let windowHandles = {
      oldTab: '',
      newTab: ''
    };

    await browser.get(url1);
    await browser.getWindowHandle().then(handle => {
      windowHandles.oldTab = handle;
    });

    // opening new window sending CTRL+N
    await browser.actions()
      .sendKeys(protractor.Key.chord(protractor.Key.CONTROL, "n"))
      .perform();

    await browser.getAllWindowHandles()
      .then(handles => {
        expect(handles[0]).toEqual(windowHandles.oldTab);

        windowHandles.newTab = handles[1];
        return browser.driver.switchTo().window(windowHandles.newTab);
      })
      .then(() => {
        // this works
        return browser.get(url2);
      })
      .then(() => {
        return browser.driver.switchTo()
          .window(windowHandles.oldTab)
          .then(() => browser.driver.executeScript('window.focus();'));
      })
      .then(() => {
        let handle = browser.driver.getWindowHandle();
        expect(handle).toEqual(windowHandles.oldTab);
      })
      .then(() => browser.sleep(6000));
  });

I have added a sleep to make sure you can see it did not switch. (At least UI is not moved to forward, doesn't get the focus).

Works with FireFox but not with Chrome.
Expectations are all verified in both browsers, though Chrome does not switch, while FireFox does.
I tried out the window.focus() script trick, but it did not switch. On FireFox you don't even need that trick to make it work.


  • Node Version: v5.9.1
  • Webdriver Version: 2.53.0
  • Protractor Version: 3.0.0
  • Browser(s): Chrome
  • Operating System and Version Windows 8.1 x64

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions