selenium学习札记1_hello world

本文介绍如何使用Selenium IDE在Firefox中录制脚本,并通过Selenium RC实现跨环境及跨浏览器的自动化测试。涵盖Selenium IDE安装、Selenium RC服务器配置、Java代码示例等内容。
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全部结束,重新运行即可。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值