dimanche 26 avril 2020

Chromedriver open a blank page instead of the target website in selenium web driver

I have using chromedriver for running automation test in selenium webdriver and i am using MacOS, chrome version 83, selenium version 3.141.59 and TestNG 7.1.0. Please let me know if I am missing something.

~ public class ChromeDrive extends Base implements DriverLoader {

@Override
public WebDriver load() {

    try {
        ChromeOptions options = new ChromeOptions();
        setArguments(options);
        driver.set(new ChromeDriver(options));
        Dimension targetSize = new Dimension(1500, 1000); //your screen resolution here
        driver.get().manage().window().setSize(targetSize);
    } catch (Exception e) {
        throw new RuntimeException("Please check Browser is exist Browser Unable to start");
    }
    return driver.get();
}

@Override
public WebDriver loadParallel() {
    try {
        ChromeOptions options = new ChromeOptions();
        DesiredCapabilities capabilities = new DesiredCapabilities();
        setArguments(options);
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "chrome");
        capabilities.setCapability("name", currentTestName);

        if (ReadData("isRemote").equalsIgnoreCase("true")) {
            String hubUrl = "http://192.168.3.2:4444/wd/hub";
            driver.set(new RemoteWebDriver(new URL(hubUrl), capabilities));
        } else {
            driver.set(new ChromeDriver(options));
        }
    } catch (Exception e) {
        throw new RuntimeException("Please check Browser is exist Browser Unable to start" + e);
    }

    Dimension targetSize = new Dimension(1500, 1000); //your screen resolution here
    driver.get().manage().window().setSize(targetSize);
    return driver.get();
}


private void setArguments(ChromeOptions options) {
    boolean isUnix = setChromeBrowser(OsValidator.getDeviceOs());
    isUnix(options, isUnix);
    Map<String, Object> prefs = new HashMap<>();
    prefs.put("profile.default_content_setting_values.notifications", 2);
    options.setPageLoadStrategy(PageLoadStrategy.NONE);
    options.addArguments("--no-sandbox");
    options.addArguments("--start-maximized");
    //options.addArguments("--always-authorize-plugins");
    //options.addArguments("enable-automation");
    options.addArguments("--disable-web-security");
    options.addArguments("-incognito");
    options.setExperimentalOption("prefs", prefs);
    options.addArguments("--allow-running-insecure-content");
}

private void isUnix(ChromeOptions options, boolean isUnix) {
    if (isUnix) {
        options.addArguments("--headless");
    }
}

Aucun commentaire:

Enregistrer un commentaire