1

I want to use the session id while creating a new WebDriver with Agouti to pass it to SauceLabs for status update.

Commands Used:

url := fmt.Sprintf("http://%s:%s@ondemand.saucelabs.com/wd/hub", username, accesskey)
page,err :=agouti.NewPage(url, options)
Expect(err).NotTo(HaveOccurred())
page.Navigate(`https://qiita.com/login`)

I tried to retrieve the session ID from page.Session() but the return type is a Bus Interface and result is Session with the *http.client variable.

Is there any other alternative to it?, to just retrieve the session id.

Anvesh
  • 149
  • 1
  • 8
  • Are you saying that you don't know how to parse Output to get Desired Output? – JeffC Jul 31 '17 at 18:08
  • Yes, I am unable to parse the output or any other alternative to just retrieve the Session ID. – Anvesh Jul 31 '17 at 18:18
  • Just convert the `sessionId` to a string, split it by space, and take the first part. – JeffC Jul 31 '17 at 18:25
  • I tried following that approach, but I was unable to convert the variable "sessionId" to string, as the return type of page.Session() is *api.Session – Anvesh Jul 31 '17 at 18:48
  • The fact that the logs contain the sessionId as a string, clearly it's possible. What have you tried to convert it to string? Please add that code to your question. – JeffC Jul 31 '17 at 19:29
  • I used : sessionId, _ = json.Marshal(sessionId) But i get the error message as "cannot assign [] byte to session id (type *api.Session in multiple assignment" – Anvesh Jul 31 '17 at 20:13

2 Answers2

1

The page.Session().Bus returns a type *apiSession to extract the session ID. Use of Indirect can help us return the value that *apiSession points to in this case page.Session().Bus from there we can extract the sessionID.

sessionBus := reflect.ValueOf(page.Session().Bus)
sessionURL := reflect.Indirect(sessionBus)
sessionField := sessionURL.FieldByName(`SessionURL`)
sessionString := sessionField.String()
sessionSplit := strings.SplitN(sessionString, "/", 7)
sessionID := sessionSplit[len(sessionSplit)-1]
Anvesh
  • 149
  • 1
  • 8
0

fmt.Println(fmt.Sprintf("%s", sessionId)[:32]) thanks to Gavin!

Good luck!

James
  • 1,928
  • 3
  • 13
  • 30