05:robotframework條件判斷、初始化清除與evaluate


01:條件判斷

  • RF中用Run Keyword if  關鍵字做條件判斷
  1. 條件表達式參數給python的eval函數
  2. run keyworld if ‘2019’ in $html  log to  console 內容
  • 參數放在下一行

run keyword if  ‘2019’ in $html and  'UTC' in $html

...                        log to console   \n 2019年的,UTC時間

*** Test Cases ***
測試1
        ${html}  getwebinfo
        #判斷html是否包含對應信息
        run keyword if    '2020' in $html  log to console 今年是2020年

02:ELSE分支

run keyword if  '2019' in $html and 'UTC' in $html
...             log  to  console  \n2019年的,UTC時間
      ...    ELSE     log  to  console   \n不是2019年的時間

ELSE  IF  參數

run keyword  if  '2019' in $html and 'UTC' in $html
...          log to  console  \n 2019年的,UTC時間
    ...   ELSE IF   '2019' in $html  log to console  \n2019年的
    ...   ELSE IF   'UTC'  in $html  log to  console  \nUTC時間
    ...   ELSE                       log  to  console  \n以上都不是

03:循環里面的判斷

  • Exit For  Loop  與 Continue  For  Loop
*** Test Cases ***
測試1
        FOR  ${i} IN RANGE  9999
            ${weigt}  get value from user   請輸入你的體重
            run keyword if  $weight=='cont'   continue for loop
            run keyword if  $weight=='break'  exit for loop
            log to console   體重${weight}
            run keyword if  int($weight) >60  log to console  超重了要減肥
 
        END

 ##簡寫
*** Test Cases ***
測試1
        FOR  ${i} IN RANGE  9999
            ${weigt}  get value from user   請輸入你的體重
            continue for loop if    $weight=='cont'
            exit for loop if  $weight=='break'
            log to console   體重${weight}
            run keyword if  int($weight) >60  log to console  超重了要減肥

        END

04:collection 標准庫

官方文檔介紹:collection是用來處理robotframework列表和字典的庫

  • 針對List 和Diction 的處理
  • 創建並添加元素
  • 數字變量 ${1}  ${2}
*** Settings ***
Library   Collections

*** Test Cases ***
測試1
        ${list}=  create list   a   b   c
        Append To List    ${list}   hello  #增加
        remove from list  ${list}  0   #刪除
        set List Value   ${list}  0  he  #替換
        log to console   ${list}

05:Evaluate

官方文檔介紹:Evaluate是執行python表達式,並返回執行結果

  • 直接用python代碼表達式來生成一個結果
  • ${var}=  set variable  ${890}

完全可以寫成

${var}= evaluate  890

  • 復雜的表達式

${var}= evaluate  ['hello']*10

image.png

由python文件函數,使用RF導入

 image.png


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM