webDriver模拟点击对web工程测试还是挺方便的.

package suite;

import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver; public class WebTest {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer(); @Before
public void setUp() throws Exception {
// System.setProperty(
// "webdriver.chrome.driver",
// "C:\\Program Files (x86)\\Google\\Chrome\\Application\\48.0.2564.109\\chromedriver_x64.exe");
// driver = new ChromeDriver();
driver = new HtmlUnitDriver(true);
baseUrl = "http://10.10.10.10:8080/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
} @Test
public void testWeb() throws Exception {
driver.get(baseUrl + "strutsDemo/index.jsp");
driver.findElement(By.id("sender")).click();
driver.findElement(By.id("sender")).click();
driver.findElement(By.id("sender")).click();
driver.findElement(By.id("sender")).click();
driver.findElement(By.id("sender")).click();
driver.findElement(By.id("sender")).click();
driver.findElement(By.id("sender")).click();
driver.findElement(By.id("sender")).click();
driver.findElement(By.id("sender")).click();
driver.findElement(By.id("sender")).click();
driver.findElement(By.id("sender")).click();
driver.findElement(By.id("sender")).click();
driver.findElement(By.id("sender")).click();
driver.findElement(By.id("sender")).click();
driver.findElement(By.id("sender")).click();
driver.findElement(By.id("sender")).click();
driver.findElement(By.id("sender")).click();
driver.findElement(By.id("receiver")).click();
driver.findElement(By.id("sender")).click();
driver.findElement(By.id("sender")).click();
driver.findElement(By.id("receiver")).click();
driver.findElement(By.id("start")).click();
driver.findElement(By.id("add")).click();
driver.findElement(By.id("show")).click();
} @After
public void tearDown() throws Exception {
driver.quit();
} private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
} private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException e) {
return false;
}
} private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert) {
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}

  程序将会模拟打开浏览器点击并测试.测试代码是用selenium ide录制过来的,想要自己写也可以,只不过麻烦一些.如果当前工程部署在linux主机上要把chrome改成

HTMLUnitDriver,代码中我注释了,毕竟linux安装不了chrome,这边用chrome主要是为了看得清楚.

selenium2.0集成测试案例的更多相关文章

  1. selenium2.0(WebDriver) API

    1.1  下载selenium2.0的包 官方download包地址:http://code.google.com/p/selenium/downloads/list 官方User Guide:  h ...

  2. 在selenium2.0中使用selenium1.0的API

    Selenium2.0中使用WeDriver API对页面进行操作,它最大的优点是不需要安装一个selenium server就可以运行,但是对页面进行操作不如selenium1.0的Selenium ...

  3. selenium2.0处理case实例(二)

    本文通过具体代码处理过程, 来展示selenium中一些比较不常用的类的用法 1.javascriptExcutor,通过将driver强转成JavascriptExecutor类型, 调用execu ...

  4. selenium2.0的初步封装(java版本)

    我们都知道, 在本地创建java项目后,引入selenium-java-2.35.0.jar   selenium-support-2.35.0.jar junit-4.8.1.jar等等jar包之后 ...

  5. selenium2.0 处理各种窗口问题解决方法

    selenium2.0处理muti-Windows . Frames .Popup Dialogs selenium2.0处理多窗口,弹窗等,只需要调用WebDriver 嵌套类:TargetLoca ...

  6. selenium1.0和selenium2.0页面等待处理详解

    一.selenium1.0页面等待 1.……AndWait 经常会看到, selenium action命令中很多有这种……AndWait后缀, 例如click和clickAndWait命令: cli ...

  7. 转:Selenium2.0之grid学习总结

    (一)介绍: Grid的功能: 并行执行 通过一个中央管理器统一控制用例在不同环境.不同浏览器下运行 灵活添加变动测试机 (二)快速开始 这个例子将介绍如何使用selenium2.0的grid,并且注 ...

  8. 转:Selenium2.0 click()不生效的解决办法

    除了http://573301735.com/?p=5126讲的,昨天又发现一个让我1个小时生不如死的问题,就是使用两个不同的配置文件来初始化driver,findelement方法获取到的坐标居然不 ...

  9. selenium win7+selenium2.0+python环境搭建

    win7+selenium2.0+python环境搭建 by:授客 QQ:1033553122 步骤1:下载python 担心最新版的支持不太好,这里我下载的是python 2.7(selenium之 ...

随机推荐

  1. Spring Security(09)——Filter

    目录 1.1     Filter顺序 1.2     添加Filter到FilterChain 1.3     DelegatingFilterProxy 1.4     FilterChainPr ...

  2. 【Python】@property的用法

    设想我们要给一个student()类的一个实例s,添加一个score的属性,比如: s.score=999999 这个值明显是不合理的,但是它却是可行的,怎么能改变这种情况?我们能想到的就是用类方法 ...

  3. Maven项目问题

    Maven项目部署 svn检出的为普通项目 1.普通项目转换为Maven项目: 选择项目右击->Maven4MyEclipse->Update Project 2.tomcat项目空间WE ...

  4. kettle连接Hbase中数据导入(8)

    http://wiki.pentaho.com/display/BAD/Loading+Data+into+HBase 1)下载样本文件 到官网去下载

  5. [ An Ac a Day ^_^ ] CodeForces 586C Gennady the Dentist 模拟

    题意: n个小朋友去拔牙 每个小朋友在拔牙的时候会哭 哭声是vi分贝 距离门口vi远的小朋友听到了哭声会害怕 他们的勇气值p会减少d 如果勇气值p小于等于零 他们就会在门外哭并立即离开拔牙队列(回家找 ...

  6. ios 中Category类别(扩展类)小结

    类别 类别是一种为现有的类添加新方法的方式.利用Objective-C的动态运行时(runtime)分配机制,可以为现有的类添加新方法,这种为现有的类添加新方法的方式称为类别catagory,他可以为 ...

  7. 网页 HTML表单

    今天,我首先先学习了图片热点和在原来页面嵌入其他页面. 图片热点:<img src="" usemap="#ditu"/> <map name ...

  8. wpf之ListBox中ListBoxItem横向排列

    ListBox中ListBoxItem默认是纵向排列,可以通过自定义样式,让其横向排列, 如下Demo: XAML: <Window x:Class="ListBoxItemStyle ...

  9. mysql编码设置 [http://blog.knowsky.com/254652.htm]

    MYSQL 2009-09-11 15:37 阅读73 评论1 字号: 大大 中中 小小mysql> SHOW VARIABLES LIKE 'character_set_%';+------- ...

  10. HDU 5778 abs

    题意转化一下就是寻找一个数P,要求P质因素分解完后,质因素没有重复,还要保证abs(P*P-x)最小. 暴力,在sqrt(x)附近向下向上分别枚举一下. #pragma comment(linker, ...