使用Selenium/Ant做Web应用远程自动化测试

发表于:2014-6-05 10:40

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:zm_21    来源:51Testing软件测试网采编

  Client端主要是通过一个ant build文件来启动JUnit的TestCase的,进而启动TestCase中的test方法,连接并激活server端进行自动化测试。Client端核心测试单元的代码如下:
package com.tail.p2test;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
public class DemoTest extends TestCase {
private Selenium selenium;
public void setUp() throws Exception {
String url = "http://localhost:8080/";
selenium = new DefaultSelenium("localhost", 4444, "*chrome", url);
selenium.start();
}
protected void tearDown() throws Exception {
selenium.stop();
}
public void testNew() throws Exception {
selenium.setTimeout("100000");
selenium.open("/login.action");
selenium.type("username", "admin");
selenium.type("password", "123");
selenium.click("//input[@value='Log In']");
selenium.waitForPageToLoad("100000");
Thread.sleep(10000);
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (selenium.isElementPresent("signLabel")) break; } catch (Exception e) {}
Thread.sleep(1000);
}
// omit lines
...
selenium.open("/main.action");
}
}
21/212>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号