[英]Can I install Selenium2Library for RobotFramework without installing Python?
[英]RobotFramework - Browser opened with custom library cannot be recognized in selenium2library
我是Python和Robot框架的入門者。 我正在嘗試在我的機器人框架測試套件中創建並學習使用自定義庫。
我用以下代碼創建了一個自定義庫:
from selenium import webdriver
import time
class CustomLibrary:
def Open_My_Browser(self):
browser = webdriver.Chrome()
browser.maximize_window()
browser.get("http://demo.guru99.com/V4/")
time.sleep(5)
我導入了此自定義庫,並指定了關鍵字“打開我的瀏覽器”。 這個關鍵字從我的自定義庫中執行代碼,但是接下來的步驟就像單擊按鈕一樣來自selenium2library。
執行停止,我收到消息“未打開瀏覽器”。 我知道我的selenium2library無法識別由我的自定義庫打開的瀏覽器。 但我無法解決此問題。 任何人都可以請一些建議
我的機器人文件:
Documentation Test the Guru99 Banking Website
Library Selenium2Library
Library CustomLibrary.py
*** Test Cases ***
Test Case: 001 - The user should be able to navigate to Guru99
[Tags] Smoke
Open the Guru99 website
*** Keywords ***
Open the Guru99 website
Open My Browser ```
好吧,當然,瀏覽器會話將不會被重用-它由一個單獨的對象擁有,SeleniumLibrary / Selenium2Library不了解或無法訪問它。
就像您手動建立數據庫或ssh連接,然后期望庫只是開始使用它一樣,這不會發生。
如果要在SeleniumLibrary中使用關鍵字,則需要使用其Open Browser
,因此它具有對它的引用(瀏覽器)。
您可以將外部Python類(關鍵字)添加為plugins 。
*** Settings ***
Library SeleniumLibrary plugins=${CURDIR}/Plugin.py
*** Test Cases ***
Open My Browser
Open My Browser
Plugin.py
內容如下:
from SeleniumLibrary import BrowserManagementKeywords
from robot.api.deco import keyword
import time
class Plugin(BrowserManagementKeywords):
@keyword
def open_my_browser(self):
self.open_browser("http://demo.guru99.com/V4/", "chrome")
self.driver.maximize_window()
time.sleep(5)
順便說一句,您還可以通過擴展SeleniumLibrary創建一個新的庫。 然后將Library Selenium2Library
替換為Library <YourSeleniumLibrary>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.