0

in my test I'm trying to download file from server, verify (if its downloaded) and delete it. But everytime I run my test with remote server (Selenium Grid, Chrome version=59.0.3071.115), I receive NullPointer during verification.

If I try run the test locally it passes without any problems.

My remote driver class

private WebDriver getRemoteDriver(Browser browser) throws MalformedURLException {
    DesiredCapabilities desiredCapabilities = getCapabilities(browser);
    desiredCapabilities.setCapability("platform", "LINUX");

    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    desiredCapabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
    String downloadFilepath = System.getProperty("user.dir") + File.separator + "downloads";

    HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
    chromePrefs.put("profile.default_content_settings.popups", 0);
    chromePrefs.put("download.default_directory", downloadFilepath);
    chromePrefs.put("download.directory_upgrade", true);
    chromePrefs.put("download.extensions_to_open", "");
    chromePrefs.put("download.prompt_for_download", false);
    chromePrefs.put("plugins.always_open_pdf_externally", false);
    ChromeOptions options = new ChromeOptions();
    HashMap<String, Object> chromeOptionsMap = new HashMap<String, Object>();
    options.setExperimentalOption("prefs", chromePrefs);

    desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap);
    desiredCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options);

    final RemoteWebDriver remoteWebDriver = new RemoteWebDriver(new URL(remoteUrl), desiredCapabilities);
    remoteWebDriver.setFileDetector(new LocalFileDetector());

    return new Augmenter().augment(remoteWebDriver);
}

And part of the test looks like this: Click button to download file, wait for new file and verify it, delete file.

driver.findElement(By.xpath(".//*[@id='browseOrders:browseView:browseViewPdfExpTblLnk']/span[1]"))
                .click();

    File file = navigationUtil.WaitForNewFile(download_folder, ".pdf", 60);

    String fname = file.getName();
    logger.info(fname);

    boolean success = file.exists();

    Assert.assertTrue(success);

    file.delete();

Im constantly getting java.lang.NullPointerException in line String fname = file.getName(); So I assume that the file is never downloaded.

Why there is a problem on remote server to find and click some elements. In this case there is menu that shows up after clicking "Gear button" and download button, but remote machine can't find the "Gear button" even when I try different ways to find it.

kpioro
  • 3
  • 2
  • Where does the browser run? Remote machine or your machine? – Tarun Lalwani Aug 29 '17 at 10:43
  • Definitely sounds like file is null hence the NPE when you try .getName(). It sounds like a timing issue, perhaps locally it runs fast enough that everything is there, have you tried playing around with putting in some implicit waits? – so cal cheesehead Aug 29 '17 at 15:55
  • @TarunLalwani I run it on Chrome browser. Test passes locally but fails on remote machine. – kpioro Aug 30 '17 at 10:18
  • @socalcheesehead I use TakeScreenshot to make sure what fails. In this scenario, screenshot shows only page, without popup window with download button and without label with downloaded file. I tried to use wait.until after clicking download button but result was the same. Even test with fake xpath showed me on screenshot that this additional popup window is triggered. – kpioro Aug 30 '17 at 10:18
  • So you're using a wait.until to wait for the file to download? – so cal cheesehead Aug 30 '17 at 18:24
  • @socalcheesehead I tried using driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); or method try { wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("hypnotizer"))); } catch (NoSuchElementException ignored) { } catch (StaleElementReferenceException ignored) { } catch (TimeoutException ignored) { } after clicking download button, but result was the same. – kpioro Aug 31 '17 at 08:52

0 Answers0