xp下 搭建 selenium RC + eclipse +java

上一篇 / 下一篇  2009-06-11 11:12:57 / 个人分类:Selenium

xp下 搭建 selenium RC + eclipse +java
2009-05-26 17:20

下载Selenium RC 包:http://selenium-rc.openqa.org/
是一个Zip包,里面提供了支持各种语言的驱动。核心的是 selenium-server.jar 这个jar包,在下文介绍交互模式(Interactive Mode)时用到的就是它。

准备:JRE1.5+ 和 浏览器要求

Windows
如果你用的是Windows XP 或者是Windows2003,你可以使用IE 浏览器,或者安装Mozilla Firefox 或者Opera浏览器。
如果你是用的是Windows2000,如果想使用IE浏览器,你就需要安装reg.exe,但是如果使用Firefox不需要。我们建议(但不是必须)将你的浏览器执行路径加到你的PATH环境变量中(如果你不知道如何将你的浏览器安装目录加到PATH中,那么你就必须将你的浏览器安装到标准路径下:Firefox的标准路径:"c:\Program Files\Mozilla Firefox\firefox.exe";IE浏览器的标准路径:"c:\Program Files\Internet Explorer\iexplore.exe")

例如:大致步骤如下:

1. 先去 http://selenium-rc.openqa.org/download.jsp 下载selenium包。解压。

2. 用命令行来到解压的文件夹下: \selenium-remote-control-0.9.2\selenium-server-0.9.2

3. 运行: java -jar selenium-server.jar 启动selenium server

4. 在Eclipse创建一个项目,右键项目build path,里面加上junit.jar和selenium-java-client-driver.jar(这个在刚解压的包里面)

5. 然后在Eclipse里运行 “Run As -> unit Test”即可看到自动化的范例

最后粘贴一下那个测试程序:

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

import junit.framework.TestCase;

public class GoogleTest extends TestCase {
private Selenium selenium;

public void setUp() throws Exception {
String url = "http://www.google.com";
selenium = new DefaultSelenium("localhost", 4444, "*firefox", url);//4444 is default server port

selenium.start();
}

protected void tearDown() throws Exception {
selenium.stop();
}

public void testGoogle() throws Throwable {
selenium.open("http://www.google.com/webhp?hl=en");

assertEquals("Google", selenium.getTitle());
selenium.type("q", "Selenium OpenQA");
assertEquals("Selenium OpenQA", selenium.getValue("q"));
selenium.click("btnG");
selenium.waitForPageToLoad("5000");
assertEquals("Selenium OpenQA - Google Search", selenium.getTitle());
}
}

当把firefox改成IEXPLORER时,会报错:

java.lang.RuntimeException: Could not start Selenium session: Internal Server Error
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:89)
at test.mytest.setUp(mytest.java:16)
at junit.framework.TestCase.runBare(TestCase.java:132)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:76)
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)
Caused by: com.thoughtworks.selenium.SeleniumException: Internal Server Error
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)
at com.thoughtworks.selenium.HttpCommandProcessor.getCommandResponseAsString(HttpCommandProcessor.java:168)
at com.thoughtworks.selenium.HttpCommandProcessor.executeCommandOnServlet(HttpCommandProcessor.java:104)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:86)
at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:262)
at com.thoughtworks.selenium.HttpCommandProcessor.start(HttpCommandProcessor.java:223)
at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:81)
... 15 more

此时在服务器启动的cmd窗口中,可看到错误提示:java.lang.RuntimeException: Browser not supported: *IEXPLORER


TAG:

fanxing的个人空间 引用 删除 fanxing   /   2012-08-28 15:28:43
你这个问题解决了没,我在FireFox也遇到了
ym_wei的个人空间 引用 删除 ym_wei   /   2011-05-26 10:13:02
学习下
 

评分:0

我来说两句

日历

« 2024-05-11  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 17487
  • 日志数: 24
  • 文件数: 2
  • 建立时间: 2009-06-11
  • 更新时间: 2010-03-02

RSS订阅

Open Toolbar