以编程方式从 Grid 进程生成第二个 Selenium Grid 节点作为另一个进程时出现

我正在设置 Selenium Grid,它可以从 Grid Servlet 端点上的 HTTP 请求生成新的节点实例:SpawnNodeServlet。GET 请求上的 Servlet 正在创建新的 Selenium 网格节点,并配置将其注册到集线器。这样我就可以在需要时通过在 下发送 GET 请求来添加节点http://localhost:4444/grid/admin/SpawnNodeServlet。一切正常,直到我想生成第二个或下一个节点。只有第一个工作正常,之后我得到了 ParameterException (下面的所有代码)。由于第一个节点正确注册,参数应该没问题。有什么想法可能是错的吗?我认为,问题可能出在流程创建实施中。


我尝试从 Runtime exec 作为普通命令执行 jar,但这也无法正常工作。


final Runtime runtime = Runtime.getRuntime();

final Process command = runtime.exec(executionArgs.toArray(new String[0]));

下面是InstanceExecutor创建新 Node 实例的主要代码:


public class InstanceExecutor {


    private final Logger logger = Logger.getLogger(getClass().getName());


    private BufferedReader errorBufferedReader;

    private BufferedReader outputBufferedReader;

    private int exitValue;


    public void execute(List<String> args) throws InstanceExecutorException {


        final List<String> executionArgs = new ArrayList<String>();

        executionArgs.add(0, "java");

        executionArgs.addAll(args);


        try {

            final ProcessBuilder processBuilder = new ProcessBuilder(executionArgs.toArray(new String[0]));

            Process process = processBuilder.start();


            logger.info("processBuilder.start()");


            this.errorBufferedReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));

            this.outputBufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));


            logger.info("BufferedReader's");


            process.waitFor();

            this.exitValue = process.exitValue();


            if (this.exitValue != 0) {

                throw new IOException("Failed to execute jar, " + this.getExecutionLog());

            }

        } catch (final IOException | InterruptedException e) {

            throw new InstanceExecutorException(e);

        }

    }


慕的地8271018
浏览 89回答 1
1回答

交互式爱情

在SpawnNodeServlet中,您应该删除类字段nodeArgs,并将nodeArgs定义为本地方法变量。您有实例字段:private final List<String> nodeArgs = new ArrayList<String>();第一次服务调用后列表包含:&nbsp; &nbsp; "-Dwebdriver.chrome.driver=\"libs//chromedriver\""&nbsp; &nbsp; "-cp"&nbsp; &nbsp; "hub/target/hub-1.0.0-jar-with-dependencies.jar:node/target/node-1.0.0-jar-with-dependencies.jar"&nbsp; &nbsp; "org.openqa.grid.selenium.GridLauncherV3"&nbsp; &nbsp; "-role"&nbsp; &nbsp; "node"&nbsp; &nbsp; "-nodeConfig"&nbsp; &nbsp; "node/config.json"第二次调用后:&nbsp; &nbsp; "-Dwebdriver.chrome.driver=\"libs//chromedriver\""&nbsp; &nbsp; "-cp"&nbsp; &nbsp; "hub/target/hub-1.0.0-jar-with-dependencies.jar:node/target/node-1.0.0-jar-with-dependencies.jar"&nbsp; &nbsp; "org.openqa.grid.selenium.GridLauncherV3"&nbsp; &nbsp; "-role"&nbsp; &nbsp; "node"&nbsp; &nbsp; "-nodeConfig"&nbsp; &nbsp; "node/config.json"&nbsp; &nbsp; "-Dwebdriver.chrome.driver=\"libs//chromedriver\""&nbsp; &nbsp; "-cp"&nbsp; &nbsp; "hub/target/hub-1.0.0-jar-with-dependencies.jar:node/target/node-1.0.0-jar-with-dependencies.jar"&nbsp; &nbsp; "org.openqa.grid.selenium.GridLauncherV3"&nbsp; &nbsp; "-role"&nbsp; &nbsp; "node"&nbsp; &nbsp; "-nodeConfig"&nbsp; &nbsp; "node/config.json"然后您将此列表传递给执行者:instanceExecutor.execute(nodeArgs);这不是有效的 java 参数列表。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java