Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 是否可以使用一些额外参数(如文件路径)在浏览器中打开WebDriver路径?_Java_Windows_Selenium_Selenium Webdriver_Selenium Chromedriver - Fatal编程技术网

Java 是否可以使用一些额外参数(如文件路径)在浏览器中打开WebDriver路径?

Java 是否可以使用一些额外参数(如文件路径)在浏览器中打开WebDriver路径?,java,windows,selenium,selenium-webdriver,selenium-chromedriver,Java,Windows,Selenium,Selenium Webdriver,Selenium Chromedriver,我正在尝试在测试基于chromium的应用程序时导入文件。我试过: 在Selenium代码中将文件路径推送到input type=file,但它没有 工作,刚刚在我的应用程序中出现错误“文件被其他程序使用” 只需单击即可上载文件,但此机制会打开WPF窗口,无法使用Selenium处理它。需要避免使用Sikuli或AutoIT bec等工具时,测试应在没有VNC的无头环境中进行 我想使用Windows机制打开文件-path-to-app.exe-path-to-file.jpg,并通过以下方式

我正在尝试在测试基于chromium的应用程序时导入文件。我试过:

  • 在Selenium代码中将文件路径推送到input type=file,但它没有 工作,刚刚在我的应用程序中出现错误“文件被其他程序使用”

  • 只需单击即可上载文件,但此机制会打开WPF窗口,无法使用Selenium处理它。需要避免使用Sikuli或AutoIT bec等工具时,测试应在没有VNC的无头环境中进行

  • 我想使用Windows机制打开文件-
    path-to-app.exe-path-to-file.jpg
    ,并通过以下方式创建Chrome驱动程序:

    System.setProperty("webdriver.chrome.driver", driverPath);
    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.setBinary(appPath);
    chromeOptions.addArguments(" \"C:\\file.jpg\"");
    chromeOptions.addArguments("--remote-debugging-port=9222");
    ChromeDriver chromeDriver = new ChromeDriver(chromeOptions);
    
    在应用程序启动时打开文件。使用这些参数,应用程序以正确的方式启动-打开文件。但我无法使用驱动程序来控制应用程序。错误:

    org.openqa.selenium.WebDriverException: 
    chrome not reachable
    

    刚刚在windows headless Environment中找到了一些将文件上传到基于chromium的应用程序的解决方案。使这个ChromeDriver创建类并将测试推送到Jenkins,成功完成

        Runtime rt = Runtime.getRuntime();
        pr = rt.exec(
                this.appPath
                        + " src/main/resources/models/inputs/marvin.STL"
                        + " --headless"
                        + " --remote-debugging-port=9222"
                        + " --user-data-dir=\"src/main/resources/chromiumprofile\"");
        System.out.println("Process opened with filepath as argument:");
        System.out.println(pr.info());
        System.out.println("PID: " + pr.pid());
        System.out.println("Is process alive: " + pr.isAlive());
        System.setProperty("webdriver.chrome.driver", "src/main/resources/drivers/chromedriver.exe");
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setBinary(this.appPath);
        chromeOptions.setHeadless(true);
        chromeOptions.setExperimentalOption("debuggerAddress", "127.0.0.1:9222");
        ChromeDriver chromeDriver = new ChromeDriver(chromeOptions);
        System.out.println("Chromium process founded by Chrome Driver");
        System.out.println("Is process alive: " + pr.isAlive());
        return chromeDriver;
    
    使用此类关闭驱动程序:

    pr.destroy();
    threadSleep(3000);
    System.out.println("Process killed");
    System.out.println("Is process alive: " + pr.isAlive());
    
    xoxo