日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Robot framework 引入 Selenium2Library 类库:

發(fā)布時(shí)間:2023/12/31 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Robot framework 引入 Selenium2Library 类库: 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

在用robotframework-selenium2library做web自動化測試時(shí)候,首先要將Selenium2Library導(dǎo)入到Test Suite中,在導(dǎo)入Selenium2Library時(shí)可以指定以下可選參數(shù):

  • timeout=5.0
  • implicit_wait=0.0
  • run_on_failure=Capture Page Screenshot
  • screenshot_root_directory=None

?

  • 導(dǎo)入Selenium2Library庫時(shí),設(shè)置timeout參數(shù)值為0。
*** Settings *** Library Selenium2Library timeout=0*** Test Cases *** loginOpen Browser http://www.126.comInput Text id=idInput emailfortest2016Input Password id=pwdInput 111112Click Element id=loginBtnWait Until Element Is Visible link=退出Click Element link=退出Close Browser

  

  • 在測試用例中通過關(guān)鍵字Set SeleniumTimeout設(shè)置參數(shù)值為0。
*** Settings *** Library Selenium2Library*** Test Cases *** loginOpen Browser http://www.126.comInput Text id=idInput emailfortest2016Input Password id=pwdInput 111112Click Element id=loginBtnSet Selenium Timeout 0Wait Until Element Is Visible link=退出Click Element link=退出Close Browser

  

?

  • 在使用Wait Until Element IsVisible關(guān)鍵字時(shí)指定timeout參數(shù)值為0。
*** Settings *** Library Selenium2Library*** Test Cases *** loginOpen Browser http://www.126.comInput Text id=idInput emailfortest2016Input Password id=pwdInput 111112Click Element id=loginBtnWait Until Element Is Visible link=退出 timeout=0Click Element link=退出Close Browser

  

?

如果三種方式對timeout參數(shù)設(shè)置了不同的值,根據(jù)就近原則關(guān)鍵字參數(shù)中設(shè)置的timeout參數(shù)會對當(dāng)前關(guān)鍵字生效,但是通過導(dǎo)入?yún)?shù)和通過Set SeleniumTimeout設(shè)置參數(shù)改變的是全局的timeout值。?
個(gè)人認(rèn)為在實(shí)際的通常項(xiàng)目的測試過程中全局默認(rèn)的5s超時(shí)時(shí)間比較合理,所以不需要在導(dǎo)入Selenium2Library庫時(shí)指定timeout參數(shù),也不需要通過Set SeleniumTimeout在測試用例中修改timeout參數(shù)值,當(dāng)特殊的測試測試步驟或者測試場景需要修改timeout參數(shù)值時(shí),可以通過在關(guān)鍵字中指定timeout參數(shù)值使其在局部生效。

implicit_wait


implicit_wait是selenium查找元素時(shí)的一個(gè)隱含超時(shí)時(shí)間,默認(rèn)值為0。對上面的用例做一點(diǎn)修改,不采用Wait Until Element Is Visible來判斷元素是否可見,而直接操作元素,用例腳本如下:

*** Settings *** Library Selenium2Library*** Test Cases *** loginOpen Browser http://www.126.comInput Text id=idInput emailfortest2016Input Password id=pwdInput 111112Click Element id=loginBtnClick Element link=退出Close Browser

  

?

執(zhí)行測試用例時(shí)會報(bào)查找不到元素的錯(cuò)誤,因?yàn)樵趫?zhí)行Click Element link=退出?時(shí)頁面還沒加載完成,implicit_wait的值為0,selenium在查找不到元素時(shí)立刻返回錯(cuò)誤。?
我們在導(dǎo)入selenium庫時(shí)將implicit_wait設(shè)置為5秒,用例腳本如下:

*** Settings *** Library Selenium2Library implicit_wait=5*** Test Cases *** loginOpen Browser http://www.126.comInput Text id=idInput emailfortest2016Input Password id=pwdInput 111112Click Element id=loginBtnClick Element link=退出Close Browser

  

?

再次執(zhí)行用例腳本可正常執(zhí)行。?
也可以通過關(guān)鍵字Set Selenium Implicit Wait來設(shè)置全局的implicit_wait值,如下用例腳本也能正常執(zhí)行。

*** Settings *** Library Selenium2Library*** Test Cases *** loginOpen Browser http://www.126.comInput Text id=idInput emailfortest2016Input Password id=pwdInput 111112Click Element id=loginBtnSet Selenium Implicit Wait 5Click Element link=退出Close Browser

  

?

個(gè)人認(rèn)為在實(shí)際測試過程中不需要設(shè)置implicit_wait值,在對頁面或者元素進(jìn)行操作前都通過Wait …關(guān)鍵字先判斷頁面是否加載完成或者元素是否可見,這樣測試腳本的健壯性會更好。

run_on_failure


當(dāng)Selenium2Library某個(gè)關(guān)鍵字執(zhí)行失敗時(shí)將指定運(yùn)行關(guān)鍵字run_on_failure。?

*** Settings *** Library Selenium2Library run_on_failure=Capture Page Screenshot

?

默認(rèn)可以使用Capture Page Screenshot來截取當(dāng)前頁面內(nèi)容。使用值’Nothing’可以完全禁用該功能。

screenshot_root_directory


screenshot_root_directory指定了Capture Page Screenshot關(guān)鍵字截取頁面圖片的存放路徑。如果沒有指定那么截圖圖片會默認(rèn)存放在robotframework日志文件存放路徑。

總結(jié)

以上是生活随笔為你收集整理的Robot framework 引入 Selenium2Library 类库:的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。