| 406 | } |
| 407 | |
| 408 | func (wd *remoteWD) NewSession() (string, error) { |
| 409 | // Detect whether the remote end complies with the W3C specification: |
| 410 | // non-compliant implementations use the top-level 'desiredCapabilities' JSON |
| 411 | // key, whereas the specification mandates the 'capabilities' key. |
| 412 | // |
| 413 | // However, Selenium 3 currently does not implement this part of the specification. |
| 414 | // https://github.com/SeleniumHQ/selenium/issues/2827 |
| 415 | // |
| 416 | // TODO(minusnine): audit which ones of these are still relevant. The W3C |
| 417 | // standard switched to the "alwaysMatch" version in February 2017. |
| 418 | attempts := []struct { |
| 419 | params map[string]interface{} |
| 420 | }{ |
| 421 | {map[string]interface{}{ |
| 422 | "capabilities": newW3CCapabilities(wd.capabilities), |
| 423 | "desiredCapabilities": wd.capabilities, |
| 424 | }}, |
| 425 | {map[string]interface{}{ |
| 426 | "capabilities": map[string]interface{}{ |
| 427 | "desiredCapabilities": wd.capabilities, |
| 428 | }, |
| 429 | }}, |
| 430 | {map[string]interface{}{ |
| 431 | "desiredCapabilities": wd.capabilities, |
| 432 | }}} |
| 433 | |
| 434 | for i, s := range attempts { |
| 435 | data, err := json.Marshal(s.params) |
| 436 | if err != nil { |
| 437 | return "", err |
| 438 | } |
| 439 | |
| 440 | response, err := wd.execute("POST", wd.requestURL("/session"), data) |
| 441 | if err != nil { |
| 442 | return "", err |
| 443 | } |
| 444 | |
| 445 | reply := new(serverReply) |
| 446 | if err := json.Unmarshal(response, reply); err != nil { |
| 447 | if i < len(attempts) { |
| 448 | continue |
| 449 | } |
| 450 | return "", err |
| 451 | } |
| 452 | if reply.Status != 0 && i < len(attempts) { |
| 453 | continue |
| 454 | } |
| 455 | if reply.SessionID != nil { |
| 456 | wd.id = *reply.SessionID |
| 457 | } |
| 458 | |
| 459 | if len(reply.Value) > 0 { |
| 460 | type returnedCapabilities struct { |
| 461 | // firefox via geckodriver: 55.0a1 |
| 462 | BrowserVersion string |
| 463 | // chrome via chromedriver: 61.0.3116.0 |
| 464 | // firefox via selenium 2: 45.9.0 |
| 465 | // htmlunit: 9.4.3.v20170317 |