使用RobotFramework将现有的Chrome浏览器与远程调试端口一起使用 [英] Use Existing Chrome Browser with remote-debugging-port using RobotFramework
问题描述
我正在尝试通过RobotFramework(SeleniumLibrary)使用现有的Google chrome实例.我正在启动chrome实例
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"
这是我在robotframework中的代码
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}
当我运行RobotFramework代码时,它会调用一个新的浏览器.谁能在这里帮助我说一下出了什么问题以及如何解决.
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.
推荐答案
使用Python Selenium Module,Chrome和ChromeDriver的最新版本,以下机器人脚本将连接到已开始运行的,使用以下命令启动的Chrome:
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.
这篇关于使用RobotFramework将现有的Chrome浏览器与远程调试端口一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!