Selenium RC配置

Selenium  RC:

 -----作者: 虫师

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

Selenium RC:http://seleniumhq.org/download/  这是官网链接

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

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

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

打开eclipse sdk 工具。

第一步:创建一个项目,new---Project...

 

第二步:导入我们需要的包

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

 

完成之后如下:

 

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

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

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

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

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

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

 

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

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

 

代码内容如下:

 
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();
}
}
 

下面要启动服务。

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

定位到…selenium-remote-control-1.0.3selenium-server-1.0.3> 目录下。

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

 

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

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

 

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

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

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

原文地址:https://www.cnblogs.com/coolfeng/p/4253125.html