天天看点

Selenium RC在Eclipse中的使用

  2、在eclipse中新建java project

  3、build path-->add external archives, 将selenium server和selenium client都添加到项目中

  4、新建class

import com.thoughtworks.selenium.*;

import java.util.regex.pattern;

public class testcase extends selenesetestcase {

public void setup() throws exception {

setup("http://www.google.com/", "*firefox");

}

public void testnew() throws exception {

selenium.open("/");

selenium.type("q", "selenium rc");

selenium.click("btng");

selenium.waitforpagetoload("30000");

}}

  1、按照网上的一些方法做的时候,运行的时候报错:java.lang.runtimeexception: could not start selenium session: failed to start new browser。。。。

  找了很久网上的解答办法是:报如上错误,原因是加入了老版本的selenium jar包,更新到最新版的即可解决。

  然后重新下载了最新版的jar包,就成功了。

  2、在添加了新的jar包后运行上面的程序,还是报错了:com.thoughtworks.selenium.seleniumexception: timed out after 30000ms

at com.thoughtworks.selenium.httpcommandprocessor.throwassertionfailureexceptionorerror(httpcommandprocessor.java:109)

at com.thoughtworks.selenium.httpcommandprocessor.docommand(httpcommandprocessor.java:103)

at com.thoughtworks.selenium.defaultselenium.waitforpagetoload(defaultselenium.java:678)

at testcase.testnew(testcase.java:11)

at sun.reflect.nativemethodaccessorimpl.invoke0(native method)

at sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39)

at sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25)

at java.lang.reflect.method.invoke(method.java:597)

at junit.framework.testcase.runtest(testcase.java:176)

at junit.framework.testcase.runbare(testcase.java:141)

at com.thoughtworks.selenium.selenesetestcase.runbare(selenesetestcase.java:248)

at junit.framework.testresult$1.protect(testresult.java:122)

at junit.framework.testresult.runprotected(testresult.java:142)

at junit.framework.testresult.run(testresult.java:125)

at junit.framework.testcase.run(testcase.java:129)

at junit.framework.testsuite.runtest(testsuite.java:255)

at junit.framework.testsuite.run(testsuite.java:250)

at org.junit.internal.runners.junit38classrunner.run(junit38classrunner.java:84)

at org.eclipse.jdt.internal.junit4.runner.junit4testreference.run(junit4testreference.java:38)

at org.eclipse.jdt.internal.junit.runner.testexecution.run(testexecution.java:38)

at org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:460)

at org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:673)

at org.eclipse.jdt.internal.junit.runner.remotetestrunner.run(remotetestrunner.java:386)

at org.eclipse.jdt.internal.junit.runner.remotetestrunner.main(remotetestrunner.java:196)

  网上说可能是这个方法的问题,因为把这句代码删了后就运行正常了

最新内容请见作者的github页:http://qaseven.github.io/

继续阅读