????? Selenium是集成測(cè)試工具,是ThoughtWorks公司(就是馬同學(xué)的那個(gè)公司,牛的很)的開(kāi)源工具,最近在網(wǎng)上看到介紹的文章,自已也用了一下,它主要包括:Selenium IDE,Selenium Remote Control,Selenium Core,主要的思想我個(gè)理解就是在使用中生成測(cè)試報(bào)告,測(cè)試用例,以前對(duì)這種集成測(cè)試也不是很了解,也不知說(shuō)的對(duì)不對(duì),一般對(duì)開(kāi)發(fā),測(cè)試人員來(lái)說(shuō)通過(guò)Selenium IDE來(lái)生成測(cè)試用例中的代碼,然后再運(yùn)junit來(lái)進(jìn)行測(cè)試,它的測(cè)試用例一般為
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()中看到,它需要用到一個(gè)叫SeleniumServer的服務(wù)器,這個(gè)服務(wù)器的作用主要是代理的作用,因?yàn)閟ame origin policy(就是一個(gè)腳本只能在它自已的源站點(diǎn)上運(yùn)行,我這樣理解的,不了的可以查看官方文檔)的關(guān)系,所以需要加一層去取得網(wǎng)頁(yè)并能在上面運(yùn)行測(cè)試腳本的服務(wù)器,也就是我們的SeleniumServer了,所以才叫Selenium Remote Control,我們的測(cè)試用例主要是去連它,而不是真正直接去連接google進(jìn)行的測(cè)試。以后不用想怎么寫(xiě)測(cè)試用例了,Selenium Core主要是寫(xiě)html來(lái)進(jìn)行測(cè)試,不過(guò)同樣也可以用Selenium IDE來(lái)自動(dòng)生成html,然后將生成的一個(gè)html放到一起,開(kāi)啟TestRunner.html進(jìn)行自動(dòng)測(cè)試,速度分三步,run,walk,step,run模式下看上去還是很過(guò)癮的,原來(lái)javascript可以寫(xiě)出這么牛的軟件,呵呵,java6也支持javascript腳本了,看來(lái)這門(mén)語(yǔ)言還是值得好好研究一下,不能總是停留在看得懂的水平。
注意:上面說(shuō)的服務(wù)器在 \selenium-remote-control-0.8.1\server下面
啟動(dòng)命令為 java -jar selenium-server.jar
參數(shù) -interactive 為使用交互模式,就是可以直接在命令行進(jìn)行測(cè)試
????????? -multiWindow 為多窗體,我試了下,不過(guò)好像不行