差異處

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

連向這個比對檢視

Both sides previous revision 前次修改
下次修改
前次修改
rf:rf:testkeywords [2014/12/12 23:35]
tony
rf:rf:testkeywords [2023/06/25 09:48] (目前版本)
行 1: 行 1:
 {{tag>​RobotFramework}} {{tag>​RobotFramework}}
 ====== 節省那惱人的試驗時間 ====== ====== 節省那惱人的試驗時間 ======
 +===== Problem =====
 +之前在透過Selenium發送Ctrl+A時,先透過了Firefox Selenium IDE做試驗,再去撰寫Robot。但遇到的問題是,\\
 +  - 待測瀏覽器與試驗瀏覽器XPath有差異。
 +  - Selenium指令Robot與Selenium IDE有差異。
 +  - 使用Robot跑一次測試的時間過長。
 +為了解省這些時間,於是我想透過Runtime發送指令的方式,去解決這個問題。
 +===== How to? =====
 +我想到的方式是:​
 +  - 導到要試驗的測試案例頁面。
 +  - 讀取一個檔案內容。
 +  - 確認檔案內容指令。
 +  - 執行指令。若遇到EXIT即離開。
 +
 +在我的測試程式中,
 +  - 它將開啟網址http://​www.internic.net/​whois.html。
 +  - 接著我會在程式將讀取的檔案中,輸入指令。
 +  - 測試程式將會執行這些指令。
 +  - 最後輸入EXIT離開程式。
 +
 +看看我預先拍好的Demo視頻:​
 +https://​www.youtube.com/​watch?​v=vC8hk-igWCw&​feature=youtu.be
 +
 <code bash> <code bash>
 +*** 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 Test Select All
-    ${filePath} ​   Set Variable ​   /opt/test.txt+    ${filePath} ​   Set Variable ​   ​C:/Users/​TonyLin/​Desktop/test.txt
     ${preModifiedTime} ​   Set Variable ​   ${EMPTY}     ${preModifiedTime} ​   Set Variable ​   ${EMPTY}
-    :FOR    ${index} ​   ​In Range    ​100000+    : FOR    ${index} ​   ​IN RANGE    ​100000
     \    Sleep    1s     \    Sleep    1s
     \    @{checkResult} ​   Run Keyword And Ignore Error    Should Exist    ${filePath}     \    @{checkResult} ​   Run Keyword And Ignore Error    Should Exist    ${filePath}
行 14: 行 50:
     \    ${content} ​   Get File    ${filePath}     \    ${content} ​   Get File    ${filePath}
     \    @{lines} ​   Split To Lines    ${content}     \    @{lines} ​   Split To Lines    ${content}
-    \    log    command=@{lines}[0] +    \    ​${length} ​   Get Length ​   ${lines} 
-    \    @{checkResult} ​   Run Keyword And Ignore Error    Should Be Equal    EXIT    @{lines}[0] +    \    Run Keyword If    ${length}!=0 ​   ​log ​   command=@{lines}[0] 
-    \    Exit For Loop If    '​@{checkResult}[0]'​=='​PASS'​ +    \    @{checkResult} ​   Run Keyword And Ignore Error    Run Keyword If    ${length}!=0 ​   ​Should Be Equal    EXIT 
-    \    Run Keyword And Ignore Error    Run Command ​   @{lines}[0] +    \    ...    ​@{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 Run Command
     [Arguments] ​   ${command}     [Arguments] ​   ${command}
行 24: 行 62:
     ${keyword} ​   Set Variable ​   @{tokens}[0]     ${keyword} ​   Set Variable ​   @{tokens}[0]
     Remove From List    ${tokens} ​   0     Remove From List    ${tokens} ​   0
-    Run Keyword ​   ${keyword} ​   @{tokens} +    ​Run Keyword And Ignore Error    ​Run Keyword ​   ${keyword} ​   @{tokens}
-    ​+
 </​code>​ </​code>​
 +===== Summary =====
 +不管在練習新的Keyword、試驗XPath或是要確認撰寫是否正確,Runtime的執行的確是可以節省許多重新讀取所花費的時間。但在使用一陣子後,目前有幾點問題:​
 +  - 對於執行成功的指令該如何處理?​
 +  - report的內容中,會有相當多無意義的loop log。
 +  - 如果要一次執行多個指令呢?​
 +
 +第一個問題,我們可以將執行成功的指令,輸出到另外一個檔案,也可以直接去從log中複製貼上。如果從log中去複製貼上,就會遇到第二個問題。\\
 +第二個問題可以透過延長log時間,但也等於延長了讀取到指令的時間。之前也想過可以透過Socket方式將指令發送過去執行,但目前還沒有急迫的需求,有需要的可以使用這個方法試試看。另外一個方法是將讀取指令的動作另外寫成一個Keyword,但撰寫會複雜許多。\\
 +第三個問題純粹是讀取指令後的處理,只要針對讀取內容做處理即可。\\
 +
 +友藏內心獨白:​ 最近都在思考如何在有限時間做很多事情。
 +=====    =====
 +----
 +\\
 +~~DISQUS~~