之前在透過Selenium發送Ctrl+A時,先透過了Firefox Selenium IDE做試驗,再去撰寫Robot。但遇到的問題是,
為了解省這些時間,於是我想透過Runtime發送指令的方式,去解決這個問題。
我想到的方式是:
在我的測試程式中,
看看我預先拍好的Demo視頻: https://www.youtube.com/watch?v=vC8hk-igWCw&feature=youtu.be
*** Settings *** Library Collections Library String Library OperatingSystem Library SeleniumLibrary *** Test Cases *** test [Setup] Start Selenium Server Open Browser http://www.internic.net/whois.html googlechrome Test Select All [Teardown] Run Keywords Close All Browsers Stop Selenium Server *** Keywords *** Test Select All ${filePath} Set Variable C:/Users/TonyLin/Desktop/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} \ ${length} Get Length ${lines} \ Run Keyword If ${length}!=0 log command=@{lines}[0] \ @{checkResult} Run Keyword And Ignore Error Run Keyword If ${length}!=0 Should Be Equal EXIT \ ... @{lines}[0] \ Exit For Loop If '@{checkResult}[0]'=='PASS' and ${length}!=0 \ Run Keyword And Ignore Error Run Keyword If ${length}!=0 Run Command @{lines}[0] Run Command [Arguments] ${command} @{tokens} Split String ${command} | ${keyword} Set Variable @{tokens}[0] Remove From List ${tokens} 0 Run Keyword And Ignore Error Run Keyword ${keyword} @{tokens}
不管在練習新的Keyword、試驗XPath或是要確認撰寫是否正確,Runtime的執行的確是可以節省許多重新讀取所花費的時間。但在使用一陣子後,目前有幾點問題:
第一個問題,我們可以將執行成功的指令,輸出到另外一個檔案,也可以直接去從log中複製貼上。如果從log中去複製貼上,就會遇到第二個問題。
第二個問題可以透過延長log時間,但也等於延長了讀取到指令的時間。之前也想過可以透過Socket方式將指令發送過去執行,但目前還沒有急迫的需求,有需要的可以使用這個方法試試看。另外一個方法是將讀取指令的動作另外寫成一個Keyword,但撰寫會複雜許多。
第三個問題純粹是讀取指令後的處理,只要針對讀取內容做處理即可。
友藏內心獨白: 最近都在思考如何在有限時間做很多事情。