selenium RC使用简单温习
今天有个朋友问起selenium RC怎么使用,一时居然想不起来怎么开始着手。问了同事,看了个小例子,稍微回忆起来一点。
?
唉,上一个项目使用了selenium RC做自动化测试,这个项目一换工具就往的一干二净,看来还是要经常温故而知新啊。
?
我这里用java,Eclipse来举例。
?
简单的来说,
1. 先去 http://selenium-rc.openqa.org/download.jsp 下载selenium包。解压。?
2. 用命令行来到解压的文件夹下: \selenium-remote-control-0.9.2\selenium-server-0.9.2
3. 运行: java -jar selenium-server.jar 启动selenium server
4. 在Eclipse创建一个项目,在项目的build path里面加上junit.jar和selenium-java-client-driver.jar(这个在刚解压的包里面)
5. 在项目里面新建一个junit文件,比如说openQA这个网站上的GoolgeTest文件
6. 在红色波浪线的那些地方,比如Selenium, DefaultSelenium上面‘Ctrl+1’来增加相应要import的类
7. 然后在Eclipse里运行 “Run As -> unit Test”即可看到自动化的范例
?
最后粘贴一下那个测试程序
?
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
import junit.framework.TestCase;
public class GoogleTest extends TestCase {
??? private Selenium selenium;
??? public void setUp() throws Exception {
??????? String url = "http://www.google.com";
??????? selenium = new DefaultSelenium("localhost", 4444, "*firefox", url);? //4444 is default server port
?? selenium.start();?????
??? }
??? protected void tearDown() throws Exception {
??????? selenium.stop();
??? }
??? public void testGoogle() throws Throwable {
??????? selenium.open("http://www.google.com/webhp?hl=en");
??????? assertEquals("Google", selenium.getTitle());
??????? selenium.type("q", "Selenium OpenQA");
??????? assertEquals("Selenium OpenQA", selenium.getValue("q"));
??????? selenium.click("btnG");
??????? selenium.waitForPageToLoad("5000");
??????? assertEquals("Selenium OpenQA - Google Search", selenium.getTitle());
??? }
}
?
?
?
?
?
1 楼 keke020 2008-09-28 tearDown() 这个方法放在testGoogle() 的上面,这样运行后,会提示:selenium空指针的吧???? 2 楼 抛出异常的爱 2008-09-28 keke020 写道tearDown() 这个方法放在
testGoogle() 的上面,这样运行后,会提示:selenium空指针的吧????
不会..
3 楼 keke020 2008-10-07 用showModelessDialog弹出一个新窗口后,如何在selenium获得新弹出这个窗口里面的元素呢?
谢谢. 4 楼 kqy929 2008-10-24 请教:该怎么把selenium工程完全导入到Eclipse下?
这样还可以扩展“独特”的功能~