簡體   English   中英

Robot Framework:如何在Robot Framework中使用用戶創建的瀏覽器實例

[英]Robot Framework: How to use User created browser instance in Robot framework

我創建了一個python代碼來初始化chrome瀏覽器,並且希望將此驅動程序實例傳遞給Robot Framework,以便RF的關鍵字可以在該實例上使用。 請讓我知道我該怎么做。 用於初始化文件的Py代碼為:

'class SeleniumKeywords:

    ROBOT_LIBRARY_SCOPE = 'GLOBAL'

    def __init__(self):
        self.driver = None

    def open_browser(self, browser="chrome"):
        driver_class = drivers[browser]
        self.driver = driver_class()

    def go_to(self, url):
        self.driver.get(url)'

現在,在Robot框架中使用它時,瀏覽器將打開,但RF關鍵字不能在其上使用(selenium2library關鍵字)。 基本上,我使用custom關鍵字打開瀏覽器實例,並在RF中最大程度地使用selenium2library關鍵字。 不幸的是,它不起作用。 請讓我知道如何將此瀏覽器實例傳遞給RF:

'*** Settings ***
Library    ExtendedSelenium2Library
Library    ../Resources/SeleniumKeywords.py    
Resource    ../Global/GlobalConfig.robot




*** Test Cases ***
Reuse Session ID
    SeleniumKeywords.Open Browser    chrome
    maximize browser window  
    SeleniumKeywords.Go To    ${URL}  '

最大化瀏覽器窗口是RF關鍵字,我希望它可以在我的瀏覽器實例上運行

我已經編寫了自己的庫,但是擴展了Selenium2Library,可以將Selenium2Library關鍵字與自己的關鍵字混合使用。 Selenium2Library或您的情況下,ExtendedSelenium2Library將無法識別您剛剛在Python中啟動的會話,並顯示“未打開瀏覽器”錯誤。 “最大化瀏覽器窗口”關鍵字依賴於以前使用“打開瀏覽器”關鍵字打開的瀏覽器。

如果您確實需要自己的Selenium庫,則可以執行以下操作:

class SeleniumKeywords(ExtendedSelenium2Library):

    def go_to(self, url, browser="chrome"):
        self.open_browser(url, browser)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM