????? Selenium是集成測試工具,是ThoughtWorks公司(就是馬同學的那個公司,牛的很)的開源工具,最近在網上看到介紹的文章,自已也用了一下,它主要包括:Selenium IDE,Selenium Remote Control,Selenium Core,主要的思想我個理解就是在使用中生成測試報告,測試用例,以前對這種集成測試也不是很了解,也不知說的對不對,一般對開發,測試人員來說通過Selenium IDE來生成測試用例中的代碼,然后再運junit來進行測試,它的測試用例一般為
package
?com.thoughtworks.selenium;

import
?junit.framework.TestCase;

import
?org.openqa.selenium.server.SeleniumServer;

public
?
class
?GoogleTest?
extends
?TestCase

{
???
private
?Selenium?selenium;


???
public
?
void
?setUp()?
throws
?Exception?
{
????????String?url?
=
?
"
http://www.google.com
"
;
???????selenium?
=
?
new
?DefaultSelenium(
"
localhost
"
,?SeleniumServer.DEFAULT_PORT,?
"
*firefox
"
,?url);
???????selenium.start();
????}
???

???
protected
?
void
?tearDown()?
throws
?Exception?
{
???????selenium.stop();
???}
???

???
public
?
void
?testGoogleTestSearch()?
throws
?Throwable?
{
????????selenium.open(
"
http://www.google.com
"
);
????????assertEquals(
"
Google
"
,?selenium.getTitle());
????????selenium.type(
"
q
"
,?
"
Selenium?OpenQA
"
);
????????assertEquals(
"
Selenium?OpenQA
"
,?selenium.getValue(
"
q
"
));
????????selenium.click(
"
btnG
"
);
????????selenium.waitForPageToLoad(
"
5000
"
);
????????assertTrue(selenium.isTextPresent(
"
openqa.org
"
));
????????assertEquals(
"
Selenium?OpenQA?-?Google?搜索
"
,?selenium.getTitle());
????}
????
}
?可以從setUp()中看到,它需要用到一個叫SeleniumServer的服務器,這個服務器的作用主要是代理的作用,因為same origin policy(就是一個腳本只能在它自已的源站點上運行,我這樣理解的,不了的可以查看官方文檔)的關系,所以需要加一層去取得網頁并能在上面運行測試腳本的服務器,也就是我們的SeleniumServer了,所以才叫Selenium Remote Control,我們的測試用例主要是去連它,而不是真正直接去連接google進行的測試。以后不用想怎么寫測試用例了,Selenium Core主要是寫html來進行測試,不過同樣也可以用Selenium IDE來自動生成html,然后將生成的一個html放到一起,開啟TestRunner.html進行自動測試,速度分三步,run,walk,step,run模式下看上去還是很過癮的,原來javascript可以寫出這么牛的軟件,呵呵,java6也支持javascript腳本了,看來這門語言還是值得好好研究一下,不能總是停留在看得懂的水平。
注意:上面說的服務器在 \selenium-remote-control-0.8.1\server下面
啟動命令為 java -jar selenium-server.jar
參數 -interactive 為使用交互模式,就是可以直接在命令行進行測試
????????? -multiWindow 為多窗體,我試了下,不過好像不行