title: Mobile emulator Selenium tests fail in Jenkins but not in cmd
body: <p>I have a test that always fail when running inside Jenkins.</p>
  
  <p>My project includes Selenium webdriver, JAVA, Maven, TestNG, Jenkins, Allure (reports).
  I have a few suites of tests with 100+ test cases, and I iterate them through 3 different browsers (the tests run in parallel using TestNG). They all run (using maven command line) and pass in my development laptop, and on the test server when using a command line.</p>
  
  <p>I have 2 problems regarding Jenkins and separated them into 2 questions- one of them is described in this question, and the other (IE11 issue) is here. </p>
  
  <p>The problem starts when running inside Jenkins in the test server! 
  The test fail in mobile emulator (Chrome browser) - in the test I click on a link to verify that a new window was opened with the correct url.
  I tried 3 types of clicks (Selenium click, Actions, JS) and all returned a null handle. </p>
  
  <p><strong>The code:</strong></p>
  
  <p>Here I create the main window handle and click the link:</p>
  
  <pre><code>String mwh = driver.getWindowHandle();
  WebElement poweredBy = (new WebDriverWait(driver,10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath(Consts.POWERED_BY_XPATH_1000))));
  poweredBy.click();
  </code></pre>
  
  <p>And this is, part of, the method that gets the handle and verify the new window:</p>
  
  <pre><code>public boolean closePopupWindow(String mwh, String mTitle, String layoutNumber) {
  // For IE11- make sure popup blocker is turned off in the options. else it will have only one window handle and fail
  boolean isOpenedWindowCorrect = false; 
  String newWindow = null;
  Set&lt;String&gt; handlers = driver.getWindowHandles();
  
  for (String window : handlers) {
    if (!window.equals(mwh)) {
      newWindow = window;
    }
  }
  // the focus is on the main page. need to switchTo new page and close it
  driver.switchTo().window(newWindow);
  System.out.println("The focus now is on the NEW window");
  String newTitle = driver.getTitle();
  System.out.println(newTitle);
  </code></pre>
  
  <p>This is the error I'm getting:</p>
  
  <blockquote>
    <p>java.lang.NullPointerException: null value in entry: handle=null
        at com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:34)
        at com.google.common.collect.SingletonImmutableBiMap.(SingletonImmutableBiMap.java:42)
        at com.google.common.collect.ImmutableBiMap.of(ImmutableBiMap.java:73)
        at com.google.common.collect.ImmutableMap.of(ImmutableMap.java:123)
        at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:995)
        at il.carambola.pages.Page.closePopupWindow(Page.java:786)</p>
  </blockquote>
  
  <p>Do you think there is a security issue that Jenkins wont open new windows in the browser? Is it VERY slow to open the window?
  The same tests PASS when not using mobile emulator. (I have the same test in Chrome and Firefox and it succeed to click and pass the verification).</p>
  
  <p>JDK 1.8.0_162</p>
  
  <p>Jenkins V 2.121.1</p>
  
  <p>Server- AWS t2.large - 8GB RAM, Windows server 2016 Data center, 64bit</p>