差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

rf:rf:reducelog [2017/03/09 15:13]
tony [設定Retry/Wait Keyword的Log Level]
rf:rf:reducelog [2023/06/25 09:48]
行 1: 行 1:
-====== 減少產生不必要的Log ====== 
-===== Introduction ===== 
-隨著testcases越來越多,我們這陣子開始有報表無法出現的問題。後來發現是由於output.xml就有46~50MB的大小,在產生報表時會發生out of memory。這大小光要透過編輯器打開就很吃力了;後來暫時解決方式是透過commandline自行產生報表:​ 
-<code bash> 
-java -jar robotframework.jar rebot output.xml 
-</​code>​ 
-但這方法不治本,所以開始慢慢的調整我們的testcases。 
-===== How to? ===== 
-我開始著手這問題時,RobotFramework已升級到3.0版本,而Selenium從SeleniumLibrary(2.9.1)升級到Selenium2Libary(1.7.4),接下來針對這兩個Library我們所做的調整做說明。會有大量log產生的兇手之一為**Wait Until Keyword Succeeds**,它會將你retry的內容記錄下來,但有時你並不需要它們:​ 
-==== 等到網頁不包含XXX ==== 
-在SeleniumLibrary時,會寫成這樣:​ 
-<​code>​ 
-Wait Until Keyword Succeeds | ${timeout} | ${interval} | Page Should Not Contain Element | ${locator} 
-</​code>​ 
-而Selenium2Library後,可以改成這樣:​ 
-<​code>​ 
-Wait Until Page Does Not Contain Element | ${locator} | ${timeout} 
-</​code>​ 
-**可用Keywords:​** **Wait Until Page Does Not Contain Element**與**Wait Until Page Does Not Contain** 
-==== 等到網頁包含XXX ==== 
-不管在Selenium1還是2,可能都有人會透過以下寫法去做等到網頁包含XXX:​ 
-<​code>​ 
-Wait Until Keyword Succeeds | ${timeout} | ${interval} | Page Should Contain Element | ${locator} 
-</​code>​ 
-但其實Selenium本身已支援Wait Until: 
-<​code>​ 
-Wait Until Page Contains Element | ${locator} | ${timeout} 
-</​code>​ 
-**可用Keywords:​** **Wait Until Page Contains Element**與**Wait Until Page Contains**。 
-==== 檔案內容是否包含 ==== 
-有時我們會檢查某個檔案內容是否包含特定字串:​ 
-<​code>​ 
-${content} | Get File | ${file} 
-Should Contain | ${content} | ${expect_str} 
-</​code>​ 
-在發生錯誤時,會將整個檔案內容給log下來。如果檔案內容是值得參考的,也許你會直接log下來;但我會將當時的檔案複製一份,再透過log去連結它:​ [[rf:​rf:​reservefile|link]]。如果抓取檔案不是問題,接下來就是減少錯誤發生時所造成的大量log。我透過Grep File,去取代Get File: 
-<​code>​ 
-${ret} | Grep File | ${file} | ${expect_str} 
-Should Not Be Empty | ${ret} 
-</​code>​ 
-另外一個方式是將,Should Contain的values參數設定為False:​ 
-<​code>​ 
-${content} | Get File | ${file} 
-Should Contain | ${content} | ${expect_str} | values=False 
-</​code>​ 
-不少判斷內容的keyword都支援此參數,缺點是Get File的動作還是會log部分內容。\\ 
-**可用Keywords:​** **Grep File** 
-==== 設定Retry/​Wait Keyword的Log Level ==== 
-這部分可參考另外一篇:​ 
-  * [[rf:​rf:​unnecessaryLog|設定某些Keyword的Log Level]] @TODO@ 
-==== Set Log Level ==== 
-在某些retry動作前,可以透過Set Log Level為NONE去避免不必要的LOG,然後在teardown在回復成INFO。 
  
-===== Reference ===== 
-  * [[http://​robotframework.org/​robotframework/​latest/​RobotFrameworkUserGuide.html#​standalone-jar-distribution|RobotFrameworkUserGuide.html#​standalone-jar-distribution]] 
-  * [[http://​robotframework.org/​Selenium2Library/​doc/​Selenium2Library.html|Selenium2Library]] 
-  * [[http://​robotframework-seleniumlibrary.googlecode.com/​hg/​doc/​SeleniumLibrary.html|SeleniumLibrary]] 
-  * [[http://​robotframework.org/​robotframework/​latest/​libraries/​BuiltIn.html|Builtin]] 
-  * [[http://​robotframework.org/​robotframework/​latest/​libraries/​OperatingSystem.html|OperatingSystem]]