`
br1823
  • 浏览: 13105 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

selenium学习笔记1_hello world

阅读更多
用Selenium IDE 在firefox中录制脚本,生成相应的代码,可以是java  C#  Ruby  Python

用Selenium RC 运行脚本,可以实现在不同的环境,不用的浏览器中进行自动化测试。


一 Selenium IDE 安装

安装firefox
下载Selenium IDE 插件 selenium-ide-1.0.12.xpi

http://seleniumhq.org/download/
将selenium-ide-1.0.12.xpi拖到firefox浏览器,提示安装,然后重启。
在菜单栏 工具 中,可以看到selenium IDE




二 Selenium RC 安装

在Eclipse 里用JUnit运行脚本,这里需要安装RC的服务器和相关的jar包。

1.RC服务器:Selenium Server   selenium-server-standalone-2.0rc3.jar

下载地址:http://seleniumhq.org/download/


最新版的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



如果JDK的版本不是1.6,这里的RC服务器需要找老版本的jar包
selenium-remote-control-1.0.3.zip

下载地址:http://code.google.com/p/selenium/downloads/list

2. JUnit需要用到的JAR包  selenium-java-2.0rc3.zip
下载地址:http://seleniumhq.org/download/

在项目中导入解压后的jar包

三 selenium hello world


用Selenium IDE录制打开google 搜索selenium HelloWorld的脚本
导出java代码


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全部结束,重新运行即可。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics