How can I add an extension to my chromedriver at the Robot Framework with Selenium2Library and launch remotely

醉酒当歌 提交于 2021-02-08 08:26:48

问题


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.

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.

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}

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

Secondly i have tried the below

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())

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


回答1:


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


来源:https://stackoverflow.com/questions/33693822/how-can-i-add-an-extension-to-my-chromedriver-at-the-robot-framework-with-seleni

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