问题
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