3.在不同浏览器上执行selenium IDE测试。
selenium IDE只能在friefox上运行,但是通过selenium IDE 开发的自动化测试,可以在其他浏览器上运行。只要使用一条简单的命令唤醒 selenium RC 服务器就可以了。
如果浏览器不被直接支持,那么通过使用" *custom "运行模式,你依然可以在浏览器上运行selenium 测试案例。
cmd=getNewBrowserSession&1=*custom c:\Program Files\Mozilla Firefox\MyBrowser.exe&2=http://fnng.cnblogs.com |
如下一段代码:
package com.example.tests;
import com.thoughtworks.selenium.*; import org.junit.After; import org.junit.Before; import org.junit.Test; import java.util.regex.Pattern;
public class test extends SeleneseTestCase { @Before public void setUp() throws Exception { selenium = new DefaultSelenium("localhost", 4444, "*chrome", http://fnng.cnblogs.com/); //可以用下面一行的代码来替换上面一行代码 //cmd=getNewBrowserSession&1=*custom c:\Program Files\Mozilla Firefox\MyBrowser.exe&2=http://fnng.cnblogs.com //如果是IE浏览器的话,可以直接修改浏览器名称,代码如下: //selenium = new DefaultSelenium("localhost", 4444, " *iexplore", http://fnng.cnblogs.com/); 这种方式更为简便。
selenium.start(); }
@Test public void testTest() throws Exception { selenium.open("/"); selenium.click("id=homepage1_HomePageDays_DaysList_DayItem_0_DayList_0_TitleUrl_0"); selenium.waitForPageToLoad("30000"); }
@After public void tearDown() throws Exception { selenium.stop(); } } |
如何配置java环境来验证我面的一段代码,请参考,我的《selenium RC 环境搭建》
注意:如果通过这种方式启动浏览器,你必须手动配置浏览器,以便将selenium Server 作为代理,通常这仅仅意味着打开你的浏览器参数文件,并指明“localhost:4444”作为HTTP代理。但是,不同浏览器的指令可能完全不一样,这就需要从你的浏览器支持文档中寻找更多细节。
相关文章:
菜鸟学自动化测试(一)----selenium IDE