gpt4 book ai didi

java - Selenium 服务器和 Java

转载 作者:行者123 更新时间:2023-11-30 04:23:49 25 4
gpt4 key购买 nike

我正在尝试使用 java 来自动化我的 selenium 脚本。我尝试执行的命令是:

/usr/bin/java -jar /javalibs/selenium-server/selenium-server-standalone-2.32.0.jar -htmlSuite "*firefox" "http://www.google.com" "/tmp/googlesearchsuite.html" "/tmp/RESUTL.html"

该命令在我的 Mac 终端上完美执行。现在我想将其转换为Java;这是我为此使用的代码:

public void localRun() {

Process p = null;

try {

String cmd = "/usr/bin/java -jar /javalibs/selenium-server/selenium-server-standalone-2.32.0.jar -debug -htmlSuite \"*firefox\" \"http://www.google.com\" \"/tmp/googlesearchsuite.html\" \"/tmp/RESUTL.html\"";

System.out.print("COMMAND: " + cmd);

System.out.println();

Runtime runtime = Runtime.getRuntime();
p = runtime.exec(cmd);
p.waitFor();

BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader error = new BufferedReader(new InputStreamReader(p.getErrorStream()));

String line = null;

while ((line = input.readLine()) != null) {
System.out.println(line);
}

line = null;

while ((line = error.readLine()) != null) {
System.out.println(line);
}

int exitVal = p.waitFor();

} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
} finally {
p.destroy();
}
}

当我运行该 java 代码时,我收到此日志,其中包含奇怪的错误消息(省略整个日志):

testSuite=/lensoo/googlesearchsuite.html
COMMAND: /usr/bin/java -jar /javalibs/selenium-server/selenium-server-standalone-2.32.0.jar -debug -htmlSuite "*firefox" "http://www.google.com" "/lensoo/googlesearchsuite.html" "/lensoo/RESUTL.html"
14:49:55.619 INFO - Java: Apple Inc. 20.45-b01-451
14:49:55.620 INFO - OS: Mac OS X 10.8.3 x86_64
14:49:55.630 INFO - v2.32.0, with Core v2.32.0. Built from revision 6c40c18
14:49:55.631 INFO - Selenium server running in debug mode.
......
14:49:55.790 INFO - Started HttpContext[/wd,/wd]
14:49:55.801 INFO - Started SocketListener on 0.0.0.0:4444
14:49:55.801 INFO - Started org.openqa.jetty.jetty.Server@152c7568
May 3, 2013 2:49:49 PM org.openqa.grid.selenium.GridLauncher main
INFO: Launching a standalone server
Can't find HTML Suite file:/Users/maksim/IdeaProjects/CMPE287-TaaS/"/tmp/googlesearchsuite.html":
Usage: java -jar selenium-server.jar [-interactive] [options]

-port <nnnn>: the port number the selenium server should use
(default 4444)
-timeout <nnnn>: an integer number of seconds we should allow a
clie.......

这是我收到的完整消息:http://pastebin.com/QzHeQ0Bm

从命令行执行命令和java执行命令有什么区别吗?如果是,那么执行该命令来运行我的 Selenium HTML Suite 的正确方法是什么。

最佳答案

您应该将 String[] 作为第二个参数传递到运行中。改变它,我相信它会起作用。

String cmd ="/usr/bin/java -jar /javalibs/selenium-server/selenium-server-standalone-2.32.0.jar"
String[] args = {"my","-arguments","-to","pass","in"};
p = runtime.exec(cmd, args);

我还找到了这个答案,Passing arguments form java program to bash script that call another java programa with the arguments 。其中显示了运行命令的几种不同方式。

关于java - Selenium 服务器和 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16368449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com