Selenium测试脚本
2014-11-10 17:13
155 查看
Selenium有两种工作模式,Selenium Test Runner (Selenium Core) 和 Selenium Driven (Selenium Rremote Control, 简称RC )。
(一)Selenium Test Runner模式
该模式下,可以直接录制脚本,也可以用HTML表布局来编写测试用例:
<table border="1">
<tr>
<td>open</td>
<td>\test\hello.html</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>Target</td>
<td>Hello World</td>
</tr>
</table>
(二)Selenium RC (Remote Control) 模式
该模式下,用各种语言来编写测试脚本,如Java, Python, C#等。
Selenium RC原理: 客户端向Selenium Server发送指令,SeleniumServer接收到测试指令后,启动浏览器并将自己的JavaScript文件嵌入网页中,通过JavaScript调用实现对Html页面的全面追踪,然后把执行结果返回给客户端。
下面是一段Java的测试脚本(参考[2]):
package Selenium.Test;
import com.thoughtworks.selenium.*;
public class seleniumTest {
private Selenium selenium;
public void setUp() {
selenium = new DefaultSelenium("10.5.41.55",
4444, "*iexplore", "http://www.google.com/");
selenium.start();
}
public void testGoogle() {
selenium.open("/");
selenium.type("q", "selenium");
selenium.click("btnG");
selenium.waitForPageToLoad("30000");
boolean testResult = (selenium.isTextPresent("Selenium web application testing system"));
if (testResult){
//用例成功
System.out.print("Search selenium web is ok!");
} else {
//用例失败
System.out.print("selenium web not found!");
}
}
public static void main(String[] args) {
seleniumTest st = new seleniumTest();
st.setUp();
st.testGoogle();
}
}
参考:
[1]. 用Selenium自动化验收测试. http://www.ibm.com/developerworks/cn/java/wa-selenium-ajax/
[2].Selenium简介(三)--基于RC的简单应用
. http://blog.csdn.net/iamqa/article/details/4409209
(一)Selenium Test Runner模式
该模式下,可以直接录制脚本,也可以用HTML表布局来编写测试用例:
<table border="1">
<tr>
<td>open</td>
<td>\test\hello.html</td>
<td></td>
</tr>
<tr>
<td>verifyTextPresent</td>
<td>Target</td>
<td>Hello World</td>
</tr>
</table>
(二)Selenium RC (Remote Control) 模式
该模式下,用各种语言来编写测试脚本,如Java, Python, C#等。
Selenium RC原理: 客户端向Selenium Server发送指令,SeleniumServer接收到测试指令后,启动浏览器并将自己的JavaScript文件嵌入网页中,通过JavaScript调用实现对Html页面的全面追踪,然后把执行结果返回给客户端。
下面是一段Java的测试脚本(参考[2]):
package Selenium.Test;
import com.thoughtworks.selenium.*;
public class seleniumTest {
private Selenium selenium;
public void setUp() {
selenium = new DefaultSelenium("10.5.41.55",
4444, "*iexplore", "http://www.google.com/");
selenium.start();
}
public void testGoogle() {
selenium.open("/");
selenium.type("q", "selenium");
selenium.click("btnG");
selenium.waitForPageToLoad("30000");
boolean testResult = (selenium.isTextPresent("Selenium web application testing system"));
if (testResult){
//用例成功
System.out.print("Search selenium web is ok!");
} else {
//用例失败
System.out.print("selenium web not found!");
}
}
public static void main(String[] args) {
seleniumTest st = new seleniumTest();
st.setUp();
st.testGoogle();
}
}
参考:
[1]. 用Selenium自动化验收测试. http://www.ibm.com/developerworks/cn/java/wa-selenium-ajax/
[2].Selenium简介(三)--基于RC的简单应用
. http://blog.csdn.net/iamqa/article/details/4409209
相关文章推荐
- 一、酷狗 歌词搜索 Indy TIdhttp
- oracle 字符串转数组的函数
- hdu 2680 Choose the best route
- 8种不同类型的数据库对比!
- IPv6 地址格式
- 【学习笔记----数据结构16-图的存储结构】
- HTML+CSS小结
- 【jquery】幻灯片效果
- 安装ipython以及完善ipython等功能
- 搜索Maven仓库 获取 groupid artifactId
- zabbix监控nginx、php-fpm的状态
- 第11周项目6素数
- uva-111 G - History Grading
- cocos2d-x 3.0屏幕 抖动特效 重写CCShake
- Redis与Memcached的区别
- STL中lower_bound()、 upper_bound()的返回值
- Xamarin.Android之下拉刷新
- PHP之文件目录基础操作
- Android开发之ScrollView中嵌套ListView的解决方案
- Linq之查询表达式语法详解