jeudi 18 mars 2021

How to test Electron app using selenium and java

Hi Im having an issue with testing an electron app. Up until last week our product was ran on chrome. But now the product has been changed to an electron desktop app and when launched the window isnt picked up.

The flow is basically I open the product on chrome and it appears as a pop up. Previously this was just a chrome pop up but now its an electron app. And now i cnat seem to switch to this window. Im wondering is it possible to switch between the two or do i need a different driver and just test he electron app by itself?

My driver factory is shown here

public class DriverFactory {

private static WebDriver driver;

public static WebDriver startDriver() {

    String projectLocation = System.getProperty("user.dir");

    // add in elements for logging into the mobile application also - Android and
    // iOS.
    if (OSValidator.isMac()) {
        System.setProperty("webdriver.chrome.driver", projectLocation + "/chromedriver_mac");
    } else if (OSValidator.isWindows()) {
        System.setProperty("webdriver.chrome.driver", projectLocation + "/chromedriver.exe");
    } else {
        System.setProperty("webdriver.chrome.driver", projectLocation + "/chromedriver_linux");
    }

    if (System.getProperty("app.env") != null) { // If coming from Jenkins/Maven goal..
        // This is for logging results. Added when investigating crashes on chrome driver. Can be disabled when not needed. 26/03/2020
        System.setProperty("webdriver.chrome.verboseLogging", "true");
    }


    unknown-error-devtoolsactiveport-file-doesnt-exist-while-t
    ChromeOptions options = new ChromeOptions();
    options.addArguments("start-maximized");
    options.addArguments("disable-infobars");
    options.addArguments("--disable-extensions");
    options.addArguments("--window-size=1920x1080");
    options.addArguments("--disable-cache");
    //options.addArguments("--headless");
    options.addArguments("--disable-application-cache");
    options.addArguments("--disk-cache-size=0");
    options.addArguments("--disable-gpu"); // applicable to windows os only
    options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
    options.addArguments("--dns-prefetch-disable");
    //options.addArguments("--no-sandbox"); // Bypass OS security model
    options.setPageLoadStrategy(PageLoadStrategy.NORMAL);
    driver = new ChromeDriver(options);
    //--------------------


    return driver;
}

}

Aucun commentaire:

Enregistrer un commentaire