這是本文件的舊版!


減少產生不必要的Log

隨著testcases越來越多,我們這陣子開始有報表無法出現的問題。後來發現是由於output.xml就有46~50MB的大小,在產生報表時會發生out of memory。這大小光要透過編輯器打開就很吃力了。後來暫時解決方式是透過commandline自行產生報表:

java -jar robotframework.jar rebot output.xml
但這方法不治本,所以開始慢慢的調整我們的testcases。

我開始著手這問題時,RobotFramework已升級到3.0版本,而Selenium從SeleniumLibrary(2.9.1)升級到Selenium2Libary(1.7.4),接下來針對這兩個Library我們所做的調整做說明。會有大量log產生的兇手之一為Wait Until Keyword Succeeds,它會將你retry的內容記錄下來,但有時你並不需要它們:

等到網頁不包含XXX

在SeleniumLibrary時,會寫成這樣:

Wait Until Keyword Succeeds | ${timeout} | ${interval} | Page Should Not Contain Element | ${locator}
而Selenium2Library後,可以改成這樣:
Wait Until Page Does Not Contain Element | ${locator} | ${timeout}
可用Keywords: Wait Until Page Does Not Contain Element與Wait Until Page Does Not Contain。

等到網頁包含XXX

不管在Selenium1還是2,可能都有人會透過以下寫法去做等到網頁包含XXX:

Wait Until Keyword Succeeds | ${timeout} | ${interval} | Page Should Contain Element | ${locator}
但其實Selenium本身已支援Wait Until:
Wait Until Page Contains Element | ${locator} | ${timeout}