Selenium功能测试

这两天初步接触了一下ThoughtWork出品的Selenium测试框架,主要用来做web的功能测试。
1、首先让你的web应用兼容firefox浏览器。
2、下载firefox的Selenium IDE插件。
3、用Selenium IDE插件录制页面操作的脚本。
4、下载Selenium IDE: Java Formatters插件,将步骤3录制的脚本转成Junit测试用例。
5、去Selenium的官网上下载selenium-remote-control组件,将selenium-server.jar和selenium-java-client-driver.jar放到你的Project的类库中。
6、启动Selenium的Server。
package integrate.server;

import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.SeleniumServer;

import util.GlobalTestConfig;

public class SelenuimServer {

private static String portStr = GlobalTestConfig.instance.getProperty("SeleniumServerPort");

public static void main(String[] args) throws Exception {
RemoteControlConfiguration rcc = new RemoteControlConfiguration();
try {
rcc.setPort(Integer.parseInt(portStr));
SeleniumServer SELENIUM_SERVER = new SeleniumServer(rcc);
SELENIUM_SERVER.start();
} catch (Exception e) {
}
}

}


7、定义一个客户端Selenium测试的基类程序。
package integrate;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;

import util.GlobalTestConfig;

public class SeleniumTest extends SeleneseTestCase {

Selenium user;

private static String portStr = GlobalTestConfig.instance.getProperty("SeleniumServerPort");
private static String browserType = GlobalTestConfig.instance.getProperty("BrowserType");
private static String browserHost = GlobalTestConfig.instance.getProperty("BrowserHost");
private static String browserPort = GlobalTestConfig.instance.getProperty("BrowserPort");

@Before
public void setUp() throws Exception {
super.setUp();

user = new DefaultSelenium(browserHost, Integer.parseInt(portStr),
browserType, ("http://" + browserHost + ":" + browserPort + "/"));
user.start();
}

@After
public void tearDown() throws Exception {
super.tearDown();

user.stop();
}
}


8、跑步骤4得到的测试用例。
package integrate;

import org.junit.Test;

public class FramesViewTest extends SeleniumTest {

@Test
public void testSelenium() throws Exception {
user.open("/ysbase/fakeMain.html");
user.selectFrame("leftFrame");
user.click("link=单位管理");
user.click("link=用户管理");
user.selectFrame("relative=up");
user.selectFrame("mainFrame");
}

}


-------------------------------------------------
ps: Selenium不支持frame框架,最好对frame进行open操作。
Selenium本身对IE的模态对话框也是不支持的,网上有方法可以绕过去。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值