Selenium测试脚本

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值