用Selenium IDE 在firefox中录制脚本,生成相应的代码,可以是java C# Ruby Python
用Selenium RC 运行脚本,可以实现在不同的环境,不用的浏览器中进行自动化测试。
[size=medium]一 Selenium IDE 安装[/size]
安装firefox
下载Selenium IDE 插件 selenium-ide-1.0.12.xpi
[url]http://seleniumhq.org/download/[/url]
将selenium-ide-1.0.12.xpi拖到firefox浏览器,提示安装,然后重启。
在菜单栏 工具 中,可以看到selenium IDE
[img]http://dl.iteye.com/upload/picture/pic/93366/e1f82689-1906-3357-8bd0-ad9c79f3f60d.jpg[/img]
[size=medium]二 Selenium RC 安装[/size]
在Eclipse 里用JUnit运行脚本,这里需要安装RC的服务器和相关的jar包。
1.RC服务器:Selenium Server selenium-server-standalone-2.0rc3.jar
下载地址:[url]http://seleniumhq.org/download/[/url]
最新版的selenium-server-standalone-2.0rc3.jar 只支持1.6的JDK
用命令行进入jar包的目录,执行命令
java -jar selenium-server-standalone-2.0rc3.jar
可以直接在jar包的目录写一个bat方便启动
@java -jar selenium-server-standalone-2.0rc3.jar
[img]http://dl.iteye.com/upload/picture/pic/93370/32b4b7d8-e604-3323-93d4-baa29d7c90ce.jpg[/img]
如果JDK的版本不是1.6,这里的RC服务器需要找老版本的jar包
selenium-remote-control-1.0.3.zip
下载地址:[url]http://code.google.com/p/selenium/downloads/list[/url]
2. JUnit需要用到的JAR包 selenium-java-2.0rc3.zip
下载地址:[url]http://seleniumhq.org/download/[/url]
在项目中导入解压后的jar包
[size=medium]三 selenium hello world
[/size]
用Selenium IDE录制打开google 搜索selenium HelloWorld的脚本
导出java代码
[img]http://dl.iteye.com/upload/picture/pic/93368/f62b80d9-4507-3b2e-b77d-610bda6bc0cb.jpg[/img]
打开Eclipse,新建一个java project - JUnit测试
启动Selenium RC服务器
运行seleniumTest.java
如果出现错误,如下,只需要把进程中的iexplore.exe全部结束,重新运行即可。
[img]http://dl.iteye.com/upload/picture/pic/93372/23f5feba-c970-3049-8d73-5e2da2fc1fb2.jpg[/img]
用Selenium RC 运行脚本,可以实现在不同的环境,不用的浏览器中进行自动化测试。
[size=medium]一 Selenium IDE 安装[/size]
安装firefox
下载Selenium IDE 插件 selenium-ide-1.0.12.xpi
[url]http://seleniumhq.org/download/[/url]
将selenium-ide-1.0.12.xpi拖到firefox浏览器,提示安装,然后重启。
在菜单栏 工具 中,可以看到selenium IDE
[img]http://dl.iteye.com/upload/picture/pic/93366/e1f82689-1906-3357-8bd0-ad9c79f3f60d.jpg[/img]
[size=medium]二 Selenium RC 安装[/size]
在Eclipse 里用JUnit运行脚本,这里需要安装RC的服务器和相关的jar包。
1.RC服务器:Selenium Server selenium-server-standalone-2.0rc3.jar
下载地址:[url]http://seleniumhq.org/download/[/url]
最新版的selenium-server-standalone-2.0rc3.jar 只支持1.6的JDK
用命令行进入jar包的目录,执行命令
java -jar selenium-server-standalone-2.0rc3.jar
可以直接在jar包的目录写一个bat方便启动
@java -jar selenium-server-standalone-2.0rc3.jar
[img]http://dl.iteye.com/upload/picture/pic/93370/32b4b7d8-e604-3323-93d4-baa29d7c90ce.jpg[/img]
如果JDK的版本不是1.6,这里的RC服务器需要找老版本的jar包
selenium-remote-control-1.0.3.zip
下载地址:[url]http://code.google.com/p/selenium/downloads/list[/url]
2. JUnit需要用到的JAR包 selenium-java-2.0rc3.zip
下载地址:[url]http://seleniumhq.org/download/[/url]
在项目中导入解压后的jar包
[size=medium]三 selenium hello world
[/size]
用Selenium IDE录制打开google 搜索selenium HelloWorld的脚本
导出java代码
[img]http://dl.iteye.com/upload/picture/pic/93368/f62b80d9-4507-3b2e-b77d-610bda6bc0cb.jpg[/img]
package com.example.tests;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;
public class seleniumTest extends SeleneseTestCase {
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.google.com.hk/");
selenium.start();
}
@Test
public void test() throws Exception {
selenium.open("http://www.google.com.hk/");
selenium.type("q", "selenium HelloWorld");
selenium.click("btnG");
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
}
打开Eclipse,新建一个java project - JUnit测试
启动Selenium RC服务器
运行seleniumTest.java
如果出现错误,如下,只需要把进程中的iexplore.exe全部结束,重新运行即可。
[img]http://dl.iteye.com/upload/picture/pic/93372/23f5feba-c970-3049-8d73-5e2da2fc1fb2.jpg[/img]