---
title: "selenium RC 环境配置"
author: "tify"
date: "2014-06-09T15:27:00Z"
tags: []
slug: "selenium-rc"
draft: false
lastmod: "2014-09-19T14:53:27Z"
id: 2118216
url: "https://tify.iteye.com/blog/2118216"
---

http://www.cnblogs.com/fnng/archive/2011/10/19/2217506.html

在网上搜索了许久，没找到有具体的配置，只是简单了写了几个步骤，自己琢磨了一下，于是，就想整理一篇文章，便于以后温习。

本文是参照官网的步骤进行了，当然了，也不完成相同。在这里我要说的是java的环境，如查你是使用的其它语言，请参考其它文章。

下面我们通过eclipse来搭建自己的环境。

[http://seleniumhq.org/docs/appendix\_installing\_java\_driver\_client.html#configuring-selenium-rc-with-eclipse](http://seleniumhq.org/docs/appendix_installing_java_driver_client.html#configuring-selenium-rc-with-eclipse)

======================环境准备========================================

Eclipse sdk：http://eclipse-sdk.cn.uptodown.com/

Junit 4：[https://github.com/KentBeck/junit/downloads](https://github.com/KentBeck/junit/downloads)我用的是最新版本的，你随意。

Selenium RC：[http://seleniumhq.org/download/](http://seleniumhq.org/download/)这是官网链接，我找了半天没打找到下哪个。在此鄙视一下自己。我是从csdn上下载的：[http://download.csdn.net/detail/fanxinyuan/2695339](http://download.csdn.net/detail/fanxinyuan/2695339)

Firefox：firefox 6.0.2虽然官方说任意版本都可以，但我的firefox7.0.1中安装selenium IDE一直不成功，好吧。再次鄙视一下自己。

selenium IDE:selenium IDE 1.3.0

**Selenium IDE :**

先来简单说说，他作为firefox浏览器的一个插件存在，依附于firefox浏览器，打开它的录制功能，它会忠实的记录，你对firefox的操作，并可以回放它所记录的你的操作。类似于QTP的自动录制功能。你懂的！我这里就不多讲了。

方法一：

下面我们先来安装selenium IDE...

打开firefox浏览器，进入官方网址：[http://seleniumhq.org/download/](http://seleniumhq.org/download/)

找到selenium IDE的下载链接，firefox会有提示安装插件，点击安装即可。

方法二：

当然，你也可以通过另外一种方式。

在firefox的菜单栏中选择tools（工具）---&gt;add-ons Manager（添加组件）然后搜索selenium IDE点击下载安装重启即可。

**Selenium IDE使用:**

打开插件

![](http://pic002.cnblogs.com/images/2011/311516/2011101912222625.png)

好吧！告诉你的操作。（在浏览器中打开一个新的标签----输入百度网址-----在搜索栏输入”“selenium”点击搜索按钮）就这么一个简单的过程。

录制完成后，点击红色的按钮，结束掉录制。

可以点击绿色的三角按钮回放录制的脚本。如我的截图，回放是没有问题的。

关于selenium IDE就不多说了，具体对录制脚本的修改、添加等等操作请参考其他资料。如果我学的更多的东西会拿来和你们分享的。嘻嘻！

======================================================================

**SeleniumRC:**

Selenium RC当然没有selenium IDE那么傻瓜了，表面看它是更专业、功能更强，不在局限于firefox浏览器的插件上那么简单，而且还是支持多种语言的哦。（ps :QTP是只支持VBS脚本的噢！）。Selenium RC支持java、scharp、python、ruby、php、perl等语言环境，貌似很强的说。

下面是亮点，搭建我们java环境。

打开eclipse sdk工具。

**第一步：**创建一个项目，new---Project...

![](http://pic002.cnblogs.com/images/2011/311516/2011101912354345.png)

**第二步：**导入我们需要的包

右键点击我们创建的项目-----Build Path-----Add External Archives...

![](http://pic002.cnblogs.com/images/2011/311516/2011101912240010.png)

完成之后如下：

![](http://pic002.cnblogs.com/images/2011/311516/2011101912383063.png)

**Junit-4.10.jar**：在我们下载的junit 4压缩包里。

**Selenium-java-client-driver.jar**：在我们下载的selenium-remote-control-1.0.3文件夹下。

.(....\\selenium-remote-control-1.0.3\\selenium-java-client-driver-1.0.1\\)

**Selenium-server.jar**：在我们下载的selenium-remote-control-1.0.3文件夹下。

.....\\selenium-remote-control-1.0.3\\selenium-server-1.0.3\\

下面把我们录制的脚本导出并放置到入出。

![](http://pic002.cnblogs.com/images/2011/311516/2011101912402995.png)

将代码出为junit 4类型的代码，我这里保存为test.java并复制到我的项目中。

Src文件夹下的com.test包中：

![](http://pic002.cnblogs.com/images/2011/311516/2011101912444723.png)

代码内容如下：

[![复制代码](http://common.cnblogs.com/images/copycode.gif)]()

```
package com.test;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;

public class test extends SeleneseTestCase {
    @Before
    public void setUp() throws Exception {
        selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.baidu.com/");
//这里如果运行不了，修改浏览器为 *firefox  或  *iexplore
        selenium.start();
    }

    @Test
    public void testTest() throws Exception {
        selenium.open("/");
        //selenium.open("/index.html"); 可以增加页面类型
       //selenium.windowsMaximize();  将来浏览器窗口放大
        selenium.type("id=kw", "selenium");
        selenium.click("id=su");
        //selenium.waitForPageToLoad("30000");
    }

    @After
    public void tearDown() throws Exception {
        selenium.stop();
    }
}
```

[![复制代码](http://common.cnblogs.com/images/copycode.gif)]()

下面要启动服务。

开始---运行---cmd打开命令提示符。

定位到…selenium-remote-control-1.0.3\\selenium-server-1.0.3&gt;目录下。

输入：java -jar selenium-server.jar回车。服务就启动了。

![](http://pic002.cnblogs.com/images/2011/311516/2011101912510760.png)

[]()[]()这种方式比较麻烦，我们可以写一个批处理，完成上面的工作。

打开一个记事本，输入java -jar selenium-server.jar命令。保存为.bat文件。下次双击这个文件就启动了。

![](http://pic002.cnblogs.com/images/2011/311516/2011101912515122.png)

命令后面的 “-interactive”是另一种selenium RC的启动方式。

下面在我们的eclipse是运行，test.java程序。

将自动调用我们的浏览器开始运行了。

希望最多学习，请查找《selenium私房菜系列》