`
cutesunshineriver
  • 浏览: 196356 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

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的模态对话框也是不支持的,网上有方法可以绕过去。


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics