1

I'm trying to set up my webdriver so that it can execute tests in parallel from the xml sheet, this it does, but I find sometimes it opens up blank chrome windows of "data;"

I've researched around other questions and all the answers seem to say things about putting the webdriver as a new threadlocal<RemoteWebDriver>, which I am already doing.

This is the WebDriverSetup.java file I am using:

public class WebDriverSetup {

    private static ThreadLocal<RemoteWebDriver> threadDriver = null;

    public WebDriver driver(){
        return threadDriver.get();
    }

    @BeforeMethod
    public void setUp() throws MalformedURLException {
        //Set up the path to the chromedriver so that the user will not have problems if they don't have the system path variable set up.
        System.setProperty("webdriver.chrome.driver", TestExecutor.projectDirectory + "/chromedriver.exe");

        //Set the hub URL
        String seleniumUrl = "http://" + TestExecutor.hubUrl + "/wd/hub";

        //Turn off logging because as of selenium-standalone-server-3.0.1, there
        //is an "INFO" message that appears in console that could be mistaken for
        //an error message.
        Logger.getLogger("org.openqa.selenium.remote").setLevel(Level.OFF);

        //threadDriver needs to be on its own local thread
        threadDriver = new ThreadLocal<RemoteWebDriver>();

        //Set chromeoptions so they open headless on the VM, but the VM imagines the
        //tests as if chrome was running full screen on a desktop session.
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--headless");
        options.addArguments("--window-size=1920,1080");

        //Apply the options to the chromedriver session.
        URL seleniumHubURL = new URL(seleniumUrl);
        threadDriver.set(new RemoteWebDriver(seleniumHubURL, options));
    }
}

and this is how I am calling it from my test:

public class Demo_1_Filter_Users_By_Firstname extends TestBase.ClassGlobals 
{

    private WebDriverSetup webDriverSetup;
    private EventFiringWebDriver driver;
    private File logFile;

    @Test
    public void main(){
        //The main method
        driver.get("web_application_url");
    }

    @BeforeMethod
    public void testSetup() throws IOException {
        //Setup the webdriver
        webDriverSetup = new WebDriverSetup();
        driver = new EventFiringWebDriver( webDriverSetup.driver() );

        //Set up an eventhandler on the event so that all the logging functions work
        EventHandler handler = new EventHandler();
        driver.register( handler );

        //Setup the logfile
        logFile = commonMethods.newLogFile();

        //Log
        commonMethods.log(logFile, "------TEST STARTED------");
    }

    @AfterMethod
    public void testClosure(){
        //Close webdriver session, log test done etc
    }

}

The error that I am experiencing doesn't happen every time, and I don't understand why the window is hanging on data; even though the first line of my main method is to create a new webdriver session, and then using that session, open the web application through driver.get()

I am using chromedriver version 2.41

Harvey Fletcher
  • 1,167
  • 1
  • 9
  • 22

1 Answers1

0

The latest stable version of ChromeDriver (88.0.4324.96) appears to have fixed this:

Resolved issue 3641: Page not getting loaded/rendered when browser window is not in focus with Chrome Beta v87 and chromedriver v(87/86)

I've been having this issue for a while and updating my chromedriver.exe file finally solved it.

Pikamander2
  • 7,332
  • 3
  • 48
  • 69