1、先启动selenium server,命令:java -jar selenium-server-standalone-2.44.0.jar
注:也可以把命令做成一个批处理文件,和selenium server放在同一级目录下,方便启动。
2、eclipse里面用junit框架验证selenium脚本的运行结果,如下面的例子:
package autotest; import static org.junit.Assert.*; import org.junit.After; import org.junit.Before; import org.junit.Test; import com.thoughtworks.selenium.DefaultSelenium; import com.thoughtworks.selenium.Selenium; @SuppressWarnings("deprecation") public class test12 { private Selenium selenium; @Before public void setUp() throws Exception { selenium = new DefaultSelenium("localhost", 4444, "*firefox C:/program Files (x86)/Mozilla Firefox/firefox.exe", "http://win.emoney.cn/"); selenium.start(); } @Test public void test121() throws Exception { selenium.open("/"); selenium.click("id=ds"); selenium.waitForPageToLoad("30000"); assertEquals("中国操盘手滚雪球炒股大赛正式开赛", selenium.getTitle()); } @After public void tearDown() throws Exception { selenium.stop(); } }
这个java脚本是怎么获得的呢?是在selenium IDE中把selenium语言的脚本用Java/Junit/Remote Control格式导出,如下图: