|
|
|
|
| [转载]Selenium RC for JAVA从零开始<3> 第一个测试脚本 testGoogle |
发布时间:2010-6-6 20:27:00 来源:转自网络 关键字: |
|
|
Selenium RC 从零开始<2>如何配置java 客户端 之后 就要开始第一个 测试脚本了。
就用testGoogle 吧
在配置好的客户端项目里,创建一个新的Java class 叫 TestGoogle 好了
|
复制代码
-
- import com.thoughtworks.selenium.*;
- import junit.framework.TestCase;
-
- public class TestGoogle extends TestCase{
-
- public Selenium selenium;
-
- public void setUp() throws Exception{
- selenium = new DefaultSelenium("localhost",4444,"*chrome","http://www.google.cn");
- selenium.start();
- }
-
- public void testGoogle () throws Exception{
- selenium.open("http://www.google.cn/");
- selenium.type("q", "selenium");
- selenium.click("btnG");
- selenium.waitForPageToLoad("30000");
- assertEquals("selenium - Google 搜索", selenium.getTitle());
- }
-
- public void tearDown()throws Exception{
- if(selenium!=null){
- selenium.stop();
- }
- }
- }
|
增加以上代码。
然后保存。。然后选中这个文件。选择 Run->Run as ->Junit Test
然后等待奇迹发生吧。哈哈注意:需要实现安装firefox 到默认路径 |
|
|