如何使用 Selenium2Library 在 Robot Framework 中向我的 chromedriver 添加扩展并远程启动 [英] How can I add an extension to my chromedriver at the Robot Framework with Selenium2Library and launch remotely

查看:48
本文介绍了如何使用 Selenium2Library 在 Robot Framework 中向我的 chromedriver 添加扩展并远程启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了类似 如何使用 Selenium2Library 在机器人级别为我的 chromedriver 添加扩展程序,但我正在尝试在远程计算机上启动浏览器.

I got stuck with scenario like How can I add an extension to my chromedriver at the Robot level with Selenium2Library , but i am trying to launch browser on a remote machine.

上述问题的答案在本地机器上运行良好.但是关于如何向 chrome 浏览器添加扩展并在远程机器上启动.

Answer present on the above question works well on local machine. But to how to add an extension to chrome browser and launch on remote machine.

使用python获取chrome选项

Using python to get chrome options

def launchbrowserwithextension():
options = webdriver.ChromeOptions()
options.add_argument('--load-and-launch-app=path_to_extension')
return chrome_options

我写的机器人测试用例如下

I wrote robot test case as below

${options}=    launchbrowserwithextension
${executor}=    Evaluate    str('http://xx.xx.xx.xx:5558/wd/hub')
${desired capabilities}=    Evaluate    { "browserName": "chrome", "version": "", "platform": "VISTA", "javascriptEnabled": True}
Create Webdriver    Remote    desired_capabilities=${desired capabilities}    command_executor=${executor}    chrome_options=${options}

出现异常init() 得到了一个意外的关键字参数‘chrome_options’"

got exception "init() got an unexpected keyword argument 'chrome_options'"

其次我尝试了以下

def launchbrowserwithextension():
options = webdriver.ChromeOptions()
options.add_argument('--load-and-launch-app=path_to_extension')
driver = webdriver.Remote('http://xx.xx.xx.xx:5558/wd/hub', options.to_capabilities())

使用 python,我可以添加扩展并在带有扩展的远程机器上启动浏览器.然后我使用机器人框架登录到使用 python 打开的扩展.所以我写了使用机器人框架关键字输入用户名和密码的步骤.

With python i am able to add extension and launch browser on remote machine with extension. Then I am using robot framework to login to the extension which got opened using python. So i wrote steps for entering username and password using robot framework keywords.

在这里我也得到了错误没有打开浏览器".但是浏览器和扩展都在远程机器上打开,机器人框架无法识别

Here too i ended up getting error 'No browser is open'. But both the browser and extension was opened on remote machine, robot framework is not able to identify it

推荐答案

在远程服务器上打开加载了第三方扩展的浏览器,我使用了以下功能.它从运行 selenium 节点的远程服务器上的给定 path_to_extension 加载扩展.url 应该是 selenium 节点运行的路径.最后返回实例ID

To open browser loaded with an third party extension on remote server I have used below function. It loads the extension from the given path_to_extension on the remote server where the selenium node is running. url should be the path where selenium node is running. Finally it returns the instance ID

openBrowserWithExtension
        options = webdriver.ChromeOptions()
        options.add_argument('--load-and-launch-app=path_to_extension')
        capabilities = webdriver.DesiredCapabilities()
        instance = BuiltIn().get_library_instance('Selenium2Library').create_webdriver('Remote', command_executor=url, desired_capabilities=options.to_capabilities())      
        return instance

这篇关于如何使用 Selenium2Library 在 Robot Framework 中向我的 chromedriver 添加扩展并远程启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆