设为首页  
加入收藏
开班信息  
日期 班名 余位
专家讲座
公司地图  
 
学园天地 当前位置:首页 > 教学管理 > 学园天地 > 详细信息
[转载]Selenium RC for JAVA从零开始<3> 第一个测试脚本 testGoogle
发布时间:2010-6-6 20:27:00 来源:转自网络 关键字:

Selenium RC 从零开始<2>如何配置java 客户端 之后 就要开始第一个 测试脚本了。
就用testGoogle 吧

在配置好的客户端项目里,创建一个新的Java class  叫 TestGoogle 好了



 
复制代码
  1.  
  2. import com.thoughtworks.selenium.*;
  3. import junit.framework.TestCase;
  4.  
  5. public class TestGoogle extends TestCase{
  6.  
  7.     public Selenium selenium;
  8.     
  9.     public void setUp() throws Exception{
  10.         selenium = new DefaultSelenium("localhost",4444,"*chrome","http://www.google.cn");
  11.         selenium.start();
  12.     }
  13.     
  14.     public void testGoogle () throws Exception{        
  15.         selenium.open("http://www.google.cn/");
  16.         selenium.type("q", "selenium");
  17.         selenium.click("btnG");
  18.         selenium.waitForPageToLoad("30000");
  19.         assertEquals("selenium - Google 搜索", selenium.getTitle());
  20.     }
  21.     
  22.     public void tearDown()throws Exception{
  23.         if(selenium!=null){
  24.             selenium.stop();
  25.         }
  26.     }
  27. }


增加以上代码。

然后保存。。然后选中这个文件。选择 Run->Run as ->Junit Test

然后等待奇迹发生吧。哈哈注意:需要实现安装firefox 到默认路径


在线客服乐语