Implements ability to press buttons.
This commit is contained in:
parent
c51d51fd72
commit
a2be578271
1 changed files with 54 additions and 3 deletions
|
|
@ -1,4 +1,6 @@
|
||||||
import httpclient, uri, json, tables, options
|
# For reference, this is brilliant: https://github.com/jlipps/simple-wd-spec
|
||||||
|
|
||||||
|
import httpclient, uri, json, tables, options, strutils, unicode
|
||||||
|
|
||||||
type
|
type
|
||||||
WebDriver* = ref object
|
WebDriver* = ref object
|
||||||
|
|
@ -134,6 +136,55 @@ proc sendKeys*(self: Element, text: string) =
|
||||||
|
|
||||||
discard checkResponse(resp.body)
|
discard checkResponse(resp.body)
|
||||||
|
|
||||||
|
type
|
||||||
|
# https://w3c.github.io/webdriver/#keyboard-actions
|
||||||
|
Key* = enum
|
||||||
|
Unidentified = 0,
|
||||||
|
Cancel,
|
||||||
|
Help,
|
||||||
|
Backspace,
|
||||||
|
Tab,
|
||||||
|
Clear,
|
||||||
|
Return,
|
||||||
|
Enter,
|
||||||
|
Shift,
|
||||||
|
Control,
|
||||||
|
Alt,
|
||||||
|
Pause,
|
||||||
|
Escape
|
||||||
|
|
||||||
|
proc toUnicode(key: Key): Rune =
|
||||||
|
Rune(0xE000 + ord(key))
|
||||||
|
|
||||||
|
proc press*(self: Session, keys: varargs[Key]) =
|
||||||
|
let reqUrl = $(self.driver.url / "session" / self.id / "actions")
|
||||||
|
let obj = %*{"actions": [
|
||||||
|
{
|
||||||
|
"type": "key",
|
||||||
|
"id": "keyboard",
|
||||||
|
"actions": []
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
for key in keys:
|
||||||
|
obj["actions"][0]["actions"].elems.add(
|
||||||
|
%*{
|
||||||
|
"type": "keyDown",
|
||||||
|
"value": $toUnicode(key)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
obj["actions"][0]["actions"].elems.add(
|
||||||
|
%*{
|
||||||
|
"type": "keyUp",
|
||||||
|
"value": $toUnicode(key)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
let resp = self.driver.client.post(reqUrl, $obj)
|
||||||
|
if resp.status != Http200:
|
||||||
|
raise newException(WebDriverException, resp.status)
|
||||||
|
|
||||||
|
discard checkResponse(resp.body)
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
let webDriver = newWebDriver()
|
let webDriver = newWebDriver()
|
||||||
let session = webDriver.createSession()
|
let session = webDriver.createSession()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue