這是本文件的舊版!
節省那惱人的試驗時間
Problem
之前在透過Selenium發送Ctrl+A時,先透過了Firefox Selenium IDE做試驗,再去撰寫Robot。但遇到的問題是,
- 待測瀏覽器與試驗瀏覽器XPath有差異。
- Selenium指令Robot與Selenium IDE有差異。
- 使用Robot跑一次測試的時間過長。
為了解省這些時間,於是我想透過Runtime發送指令的方式,去解決這個問題。
How to?
我想到的方式是:
- 導到要試驗的測試案例頁面。
- 讀取一個檔案內容。
- 確認檔案內容指令。
- 執行指令。若遇到EXIT即離開。
Test Select All ${filePath} Set Variable /opt/test.txt ${preModifiedTime} Set Variable ${EMPTY} :FOR ${index} In Range 100000 \ Sleep 1s \ @{checkResult} Run Keyword And Ignore Error Should Exist ${filePath} \ Continue For Loop If '@{checkResult}[0]'!='PASS' \ ${modifiedTime} Get Modified Time ${filePath} \ Continue For Loop If '${modifiedTime}'=='${preModifiedTime}' \ ${preModifiedTime} Set Variable ${modifiedTime} \ ${content} Get File ${filePath} \ @{lines} Split To Lines ${content} \ log command=@{lines}[0] \ @{checkResult} Run Keyword And Ignore Error Should Be Equal EXIT @{lines}[0] \ Exit For Loop If '@{checkResult}[0]'=='PASS' \ Run Keyword And Ignore Error Run Command @{lines}[0] Run Command [Arguments] ${command} @{tokens} Split String ${command} | ${keyword} Set Variable @{tokens}[0] Remove From List ${tokens} 0 Run Keyword ${keyword} @{tokens}
後記
目前使用的方法,在report的內容中,會有相當多無意義的loop log。如果延長了log時間,等於延長指令執行時間。之前也想過可以透過Socket方式將指令發送過去執行,但目前還沒有急迫的需求,有需要的可以使用這個方法試試看。
友藏內心獨白: 最近都在思考如何在有限時間做很多事情。