selenium remote control 实例(java code)

本文将step by step的讲述第一个selenium实例:
step1:下载selenium-remote-control.下载地址: http://www.openqa.org/selenium-rc/download.action
step2:打开eclipse 新建java project.
step3:将junit.jar,selenium-remote-control-0.9.0/selenium-java-client-driver 以及selenium-remote-control-0.9.0/server/selenium-server添加至新建项目的编译路径下.
step4:新建Testgoogle.java,代码如下.
package test;

import junit.framework.TestCase;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;


public class TestGoogle extends TestCase {

    private Selenium selenium;
   
    public void setUp() throws Exception{
        String url="http://www.google.cn";
        selenium=new DefaultSelenium("localhost",4444, "*firefox", url);
        System.out.println("init selenium");
        selenium.start();
        System.out.println("start successfully");
    }
   
    public void tearDown() throws Exception{
        selenium.stop();
    }
   
    public void testGoogleTestSearch() throws Throwable { 
        System.out.println("enter testGoogleTestSearch");
         selenium.open("/");  
         System.out.println("open the google.com");
         selenium.type("q", "selenium");
         System.out.println("input type condition");
         selenium.click("btnG");
         System.out.println("begin search");
         
        selenium.waitForPageToLoad("30000");  
         assertTrue(selenium.isTextPresent("s"));  
         System.out.println("finsh assert");
             }   
}

 step5:右键选择testGoogle.java,选择run as junit.
                看到junit的绿色通过提示条.

remark:1.firefox的安装路径为默认路径,如果为非默认路径安装,需要把firefox.exe的路径写入环境变量path中.
              2 出现location.href权限不足错误,在url路径后加"/",另外要确保你的浏览器能够打开www.google.com.
                  本文代码中用了www.google.cn,因为本人浏览器中会自动跳转到cn,而不是com.selenium在录制时候, 这种跳转对应关系录制不到.
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值