0

In my script, I am opening private window of the browser to verify some contents in website. Below is the sample code:

if(osName.contains("Mac")){
    new Actions(tester.getInternalDriver()).keyDown(Keys.COMMAND).keyDown(Keys.SHIFT).sendKeys("P").keyUp(Keys.COMMAND).keyUp(Keys.SHIFT).build().perform();
}
else if (osName.contains("Win") || osName.contains("nux")){
    String pvtWin = Keys.chord(Keys.LEFT_CONTROL,Keys.SHIFT,"p");
     tester.getInternalDriver().findElement(By.cssSelector("body")).sendKeys(pvtWin);
}

The code used to work fine when I was executing these test cases on my local (mac) machine or when Jenkins execute it locally on the Windows server. But now the challenge I am facing when I am running my script on browserstack virtual machine. My local machine is Mac, and when I try to run something on the Windows(virtual) machine, it try to look for COMMAND button on the keyboard and test case fails. Is there any better way (javascript?) to open new private window which can work on any platform and for any browser? I am looking for an option to open new tab, new window & new private window. I know javascript has limitations to override browser behavior.

Vijay
  • 23
  • 1
  • 6

1 Answers1

0

You can execute the following JavaScript, to open a new window in your Selenium tests.

JavascriptExecutor js = null;
 if (driver instanceof JavascriptExecutor) 
js = (JavascriptExecutor)driver;
String scr = "window.open('https://www.google.com','_blank');";
js.executeScript(scr);

That said, any specific reason you wish to open a new window in your tests?

Umang Sardesai
  • 762
  • 6
  • 14
  • Thanks Umang for your answer. Your code is good for opening new window. I am looking for option to open new tab and new private window. I modified my question little bit. Please have a look. – Vijay Jul 01 '15 at 19:01
  • @Vijay Were u able to find solution for this. I am trying to automate same thing on Browserstack – Suraj Gupta Oct 18 '21 at 12:27