selenium的使用

来源:互联网 发布:各种门事件网络盘点 编辑:程序博客网 时间:2024/05/16 15:57

Selenium RC:

搭建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.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\

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

将代码出为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.3\selenium-server-1.0.3>目录下。

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

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

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

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

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

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

0 0
原创粉丝点击