如何使用selenium和java测试Electron应用程序

如何使用selenium和java测试Electron应用程序,selenium,selenium-webdriver,testing,electron,automated-tests,Selenium,Selenium Webdriver,Testing,Electron,Automated Tests,嗨,我在测试电子应用程序时遇到了问题。直到上周,我们的产品还在chrome上运行。但现在,该产品已改为电子桌面应用程序,并且在启动时,该窗口并未启动 流程基本上是我在chrome上打开产品,它显示为一个弹出窗口。以前这只是一个chrome弹出窗口,但现在它是一个电子应用程序。现在我好像要转到这个窗口。我想知道是否有可能在两者之间切换,或者我需要一个不同的驱动程序,只需自己测试电子应用程序 这里显示了我的驱动程序工厂 public class DriverFactory { private st

嗨,我在测试电子应用程序时遇到了问题。直到上周,我们的产品还在chrome上运行。但现在,该产品已改为电子桌面应用程序,并且在启动时,该窗口并未启动

流程基本上是我在chrome上打开产品,它显示为一个弹出窗口。以前这只是一个chrome弹出窗口,但现在它是一个电子应用程序。现在我好像要转到这个窗口。我想知道是否有可能在两者之间切换,或者我需要一个不同的驱动程序,只需自己测试电子应用程序

这里显示了我的驱动程序工厂

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;
}
}

此处对其进行了描述

您只需要设置适当的选项,并为chrome和electron使用相同的代码

@Before
   public void setup() {
       ChromeOptions opt = new ChromeOptions();
       opt.setBinary("/Users/yanir/Downloads/Electron API Demos.app/Contents/MacOS/Electron API Demos");
       DesiredCapabilities capabilities = new DesiredCapabilities();
       capabilities.setCapability("chromeOptions", opt);
       capabilities.setBrowserName("chrome");

       driver = new ChromeDriver(capabilities);
       if (driver.findElements(By.id("button-about")).size() > 0)
           driver.findElement(By.id("button-about")).click();
   }

这回答了你的问题吗?不,实际上我是用Java写的,不是javascript