How to use new geckodriver endpoints?

坚强是说给别人听的谎言 提交于 2020-01-14 15:18:28

问题


The new geckodriver v0.17.0 has a new way to install addons as mentioned here:

POST /session/{session id}/window/fullscreen to invoke the window manager-specific full screen operation
POST /session/{session id}/moz/addon/install to install an extension [Gecko only]
POST /session/{session id}/moz/addon/uninstall to uninstall an extension [Gecko only]

How can I use these endpoints to install my addon to firefox for my selenium tests?


回答1:


You have to know the ip and port in which geckodriver starts. And Once the geckodriver started you can get the Session Id from the driver Instance.

You can get the Ip Address and Port as mentioned here

For ex: if the ip and port is
localhost:15874

and session id is 1e53412a-05eb-40a9-8a7b-bb8dd6fd75ab

Then you can post a json message to

http://localhost:15874/session/1e53412a-05eb-40a9-8a7b-bb8dd6fd75ab/moz/addon/install

The body of post message should be

{
    "path":"xxyy.xpi",
    "temporary":true
}



回答2:


In case somebody need to use this from .NET client (as it is not yet implemented)

Public Class MyFirefoxDriver
Inherits OpenQA.Selenium.Firefox.FirefoxDriver

Public Sub New(fo As OpenQA.Selenium.Firefox.FirefoxOptions)
    MyBase.New(fo)
    MyBase.CommandExecutor.CommandInfoRepository.TryAddCommand("moz-install-web-ext", New CommandInfo(CommandInfo.PostCommand, "/session/{sessionId}/moz/addon/install"))
End Sub


Public Sub InstallWebExtension(path As String)
    Dim params As New Dictionary(Of String, Object)
    params.Add("path", path)
    params.Add("temporary", True)
    MyBase.Execute("moz-install-web-ext", params)
End Sub

End Class


来源:https://stackoverflow.com/questions/44935579/how-to-use-new-geckodriver-endpoints

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