我是Selenium的新手.我生成了我的第一个java selenium测试用例,它已成功编译.但是当我运行该测试时,我得到了以下RuntimeException
java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: Error while launching browser at com.thoughtworks.selenium.DefaultSelenium.start <DefaultSelenium.java:88>
Run Code Online (Sandbox Code Playgroud)
请告诉我如何解决此错误.
这是我想要运行的java文件.
import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
import junit.framework.*;
public class orkut extends SeleneseTestCase {
public void setUp() throws Exception {
setUp("https://www.google.com/", "*chrome");
}
public void testOrkut() throws Exception {
selenium.setTimeout("10000");
selenium.open("/accounts/ServiceLogin?service=orkut&hl=en-US&rm=false&continue=http%3A%2F%2Fwww.orkut.com%2FRedirLogin%3Fmsg%3D0&cd=IN&skipvpage=true&sendvemail=false");
selenium.type("Email", "username");
selenium.type("Passwd", "password");
selenium.click("signIn");
selenium.selectFrame("orkutFrame");
selenium.click("link=Communities");
selenium.waitForPageToLoad("10000");
}
public static Test suite() {
return new TestSuite(orkut.class);
}
public void tearDown(){
selenium.stop();
}
public static void main(String args[]) {
junit.textui.TestRunner.run(suite());
}
}
Run Code Online (Sandbox Code Playgroud)
我首先通过命令提示符启动selenium服务器,然后通过另一个命令提示符执行上面的java文件.
第二个问题:我是否可以使用selenium右键单击网页上的指定位置.
这个问题可能是由已经运行的Selenium服务器实例引起的.新实例需要侦听相同的端口号,但不能,因为端口已在使用中.
假设您的Selenium服务器配置为在端口4444上启动.使用'netstat'命令确定端口是否正在使用中:
在Windows上: netstat -an | find "4444"
期待看到这样的输出:
TCP 0.0.0.0:4444 0.0.0.0:0 LISTENING
TCP [::]:4444 [::]:0 LISTENING
Run Code Online (Sandbox Code Playgroud)
在Linux上,使用: netstat -anp | grep 4444
(没有Linux盒子,所以无法显示示例输出!)
如果您看到任何输出,则需要终止正在侦听Selenium想要使用的端口的进程.在Windows上,用于netstat -anb查找进程名称(它将在指定端口号的行之后列出).使用任务管理器杀死它.在Linux上,进程PID和名称将通过上面的命令列出 - 使用它来杀死它kill <PID>.
如果您使用的是 Selenium RC 的最新版本(1.0 之后),您应该更改以下内容:
setUp("https://www.google.com/", "*chrome");
Run Code Online (Sandbox Code Playgroud)
为了
setUp("https://www.google.com/", "*firefox");
Run Code Online (Sandbox Code Playgroud)
如果这不起作用,请尝试创建一个单独的 Firefox 配置文件并使用该配置文件:
http://seleniumhq.org/docs/05_selenium_rc.html#specifying-the-firefox-profile
| 归档时间: |
|
| 查看次数: |
66380 次 |
| 最近记录: |