@@ -12,6 +12,8 @@ import (
1212 "io/ioutil"
1313 "mime"
1414 "net/http"
15+ "net/url"
16+ "path"
1517 "strings"
1618 "time"
1719
@@ -122,6 +124,10 @@ func (e *Error) Error() string {
122124// encoded by the remote end in a JSON structure. If no error is present, the
123125// entire, raw request payload is returned.
124126func (wd * remoteWD ) execute (method , url string , data []byte ) (json.RawMessage , error ) {
127+ return executeCommand (method , url , data )
128+ }
129+
130+ func executeCommand (method , url string , data []byte ) (json.RawMessage , error ) {
125131 debugLog ("-> %s %s\n %s" , method , filteredURL (url ), data )
126132 request , err := newRequest (method , url , data )
127133 if err != nil {
@@ -213,7 +219,7 @@ const DefaultURLPrefix = "http://127.0.0.1:4444/wd/hub"
213219// Providing an empty string for urlPrefix causes the DefaultURLPrefix to be
214220// used.
215221func NewRemote (capabilities Capabilities , urlPrefix string ) (WebDriver , error ) {
216- if len ( urlPrefix ) == 0 {
222+ if urlPrefix == "" {
217223 urlPrefix = DefaultURLPrefix
218224 }
219225
@@ -230,6 +236,17 @@ func NewRemote(capabilities Capabilities, urlPrefix string) (WebDriver, error) {
230236 return wd , nil
231237}
232238
239+ // DeleteSession deletes an existing session at the WebDriver instance
240+ // specified by the urlPrefix and the session ID.
241+ func DeleteSession (urlPrefix , id string ) error {
242+ u , err := url .Parse (urlPrefix )
243+ if err != nil {
244+ return err
245+ }
246+ u .Path = path .Join (u .Path , "session" , id )
247+ return voidCommand ("DELETE" , u .String (), nil )
248+ }
249+
233250func (wd * remoteWD ) stringCommand (urlTemplate string ) (string , error ) {
234251 url := wd .requestURL (urlTemplate , wd .id )
235252 response , err := wd .execute ("GET" , url , nil )
@@ -249,18 +266,22 @@ func (wd *remoteWD) stringCommand(urlTemplate string) (string, error) {
249266 return * reply .Value , nil
250267}
251268
252- func ( wd * remoteWD ) voidCommand (urlTemplate string , params interface {}) error {
269+ func voidCommand (method , url string , params interface {}) error {
253270 if params == nil {
254271 params = make (map [string ]interface {})
255272 }
256273 data , err := json .Marshal (params )
257274 if err != nil {
258275 return err
259276 }
260- _ , err = wd . execute ( "POST" , wd . requestURL ( urlTemplate , wd . id ) , data )
277+ _ , err = executeCommand ( method , url , data )
261278 return err
262279}
263280
281+ func (wd * remoteWD ) voidCommand (urlTemplate string , params interface {}) error {
282+ return voidCommand ("POST" , wd .requestURL (urlTemplate , wd .id ), params )
283+ }
284+
264285func (wd remoteWD ) stringsCommand (urlTemplate string ) ([]string , error ) {
265286 url := wd .requestURL (urlTemplate , wd .id )
266287 response , err := wd .execute ("GET" , url , nil )
0 commit comments