Use Existing Chrome Browser with remote-debugging-port using RobotFramework

大城市里の小女人 提交于 2019-12-11 09:09:19

问题


I am trying to use existing google chrome instance using RobotFramework (SeleniumLibrary). I am starting the chrome instance like this

chrome.exe --remote-debugging-port=9289 --user-data-dir="D:\gcdata"

This my code in robotframework

${options}= Evaluat      sys.modules['selenium.webdriver'].ChromeOptions()  sys,selenium.webdriver  
${prefs}=       Create Dictionary   debuggerAddress     127.0.0.1:9289
Call Method    ${options}           add_experimental_option    prefs    ${prefs}
Create WebDriver    Chrome  chrome_options=${options}       

When I run the RobotFramework code, it invokes a new browser. Can anyone help me here telling what is going wrong and how to fix it.


回答1:


Using the most recent versions of the Python Selenium Module, Chrome and ChromeDriver the following Robot script will connect to an already running chrome that is started using:

chrome.exe --remote-debugging-port=9289 --user-data-dir="C:\temp\gdata"

chrome_debugger.robot

*** Settings ***
Library    SeleniumLibrary  
Library    Collections      

*** Test Cases ***
TC

    ${ChromeOptions}=     Evaluate      sys.modules['selenium.webdriver'].ChromeOptions()  sys,selenium.webdriver 

    # Method debugger_address is not callable so convert to Capabilities Dictionary and set it manually
    ${ChromeCapabilities}=     Call Method     ${ChromeOptions}    to_capabilities
    Set To Dictionary    ${ChromeCapabilities["goog:chromeOptions"]}    debuggerAddress    127.0.0.1:9289

    # Instead of using the Chrome Options use Capabilities.
    Create WebDriver    Chrome    desired_capabilities=${ChromeCapabilities}
    Go To    http://cnn.com

Even though the ChromeOptions class (GitHub) has the debugger_address(self, value) method, calling this method from Robot Framework returns an error. Therefore converting the ChromeOptions class to a Capabilities dictionary and adding it manualy to the dictionary before passing it to the webdriver through the desired_capabilities argument.



来源:https://stackoverflow.com/questions/53322326/use-existing-chrome-browser-with-remote-debugging-port-using-robotframework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!