Merge pull request #3 from hlaaftana/patch-1

Traverse object once for nil checks
This commit is contained in:
Dominik Picheta 2017-12-07 10:38:36 +00:00 committed by GitHub
commit c51d51fd72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -43,12 +43,13 @@ proc createSession*(self: WebDriver): Session =
# Check the readiness of the Web Driver.
let resp = self.client.getContent($(self.url / "status"))
let obj = parseJson(resp)
let ready = obj{"value", "ready"}
if obj{"value", "ready"}.isNil():
if ready.isNil():
let msg = "Readiness message does not follow spec"
raise newException(ProtocolException, msg)
if not obj{"value", "ready"}.getBool():
if not ready.getBool():
raise newException(WebDriverException, "WebDriver is not ready")
# Create our session.
@ -56,10 +57,11 @@ proc createSession*(self: WebDriver): Session =
let sessionResp = self.client.postContent($(self.url / "session"),
$sessionReq)
let sessionObj = parseJson(sessionResp)
if sessionObj{"value", "sessionId"}.isNil():
let sessionId = sessionObj{"value", "sessionId"}
if sessionId.isNil():
raise newException(ProtocolException, "No sessionId in response to request")
return Session(id: sessionObj["value"]["sessionId"].getStr(), driver: self)
return Session(id: sessionId.getStr(), driver: self)
proc close*(self: Session) =
let reqUrl = $(self.driver.url / "session" / self.id)
@ -141,4 +143,4 @@ when isMainModule:
echo session.findElement("#priceblock_ourprice").get().getText()
session.close()
session.close()