在*agouti.webdriver for Golang中检索会话ID。

huangapple go评论87阅读模式
英文:

Retrieve the session ID in *agouti.webdriver for Golang

问题

我想在使用Agouti创建新的WebDriver时使用会话ID,并将其传递给SauceLabs以进行状态更新。

使用的命令:

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`)

我尝试从page.Session()中获取会话ID,但返回类型是总线接口(Bus Interface),结果是带有*http.client变量的会话(Session)。

是否有其他替代方法来仅获取会话ID?

英文:

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.

答案1

得分: 1

page.Session().Bus返回类型apiSession,用于提取会话ID。使用Indirect可以帮助我们返回apiSession指向的值,在这种情况下,我们可以从page.Session().Bus中提取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]
英文:

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]

答案2

得分: 0

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

祝你好运!

英文:

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

Good luck!

huangapple
  • 本文由 发表于 2017年8月1日 00:54:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/45421439.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定