-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathkeyboard_test.exs
78 lines (60 loc) · 2.14 KB
/
keyboard_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
defmodule Playwright.Page.KeyboardTest do
use Playwright.TestCase, async: true
alias Playwright.Page
alias Playwright.Page.Keyboard
describe "type" do
test "keyboard type into a textbox", %{page: page} do
Page.evaluate(page, """
const textarea = document.createElement('textarea');
document.body.appendChild(textarea);
textarea.focus();
""")
text = "Hello world. I am the text that was typed!"
Keyboard.type(page, text)
assert Page.evaluate(page, ~s[document.querySelector("textarea").value]) == text
end
end
describe "insert_text" do
test "should send characters inserted", %{page: page} do
Page.evaluate(page, """
const textarea = document.createElement('textarea');
document.body.appendChild(textarea);
textarea.focus();
""")
text = "Hello world. I am the text that was typed!"
Keyboard.insert_text(page, text)
assert Page.evaluate(page, ~s[document.querySelector("textarea").value]) == text
end
end
describe "up" do
test "sends proper code", %{page: page, assets: assets} do
Page.goto(page, assets.prefix <> "/input/keyboard.html")
Keyboard.up(page, ";")
assert Page.evaluate(page, "() => getResult()") ==
"Keyup: ; Semicolon 186 []"
end
end
describe "down" do
test "sends proper code", %{page: page, assets: assets} do
Page.goto(page, assets.prefix <> "/input/keyboard.html")
Keyboard.down(page, "Control")
assert Page.evaluate(page, "() => getResult()") ==
"Keydown: Control ControlLeft 17 [Control]"
end
end
describe "press" do
test "test should press plus", %{page: page, assets: assets} do
Page.goto(page, assets.prefix <> "/input/keyboard.html")
Keyboard.press(page, "+")
assert Page.evaluate(page, "() => getResult()") ==
[
# 192 is ` keyCode
"Keydown: + Equal 187 []",
# 126 is ~ charCode
"Keypress: + Equal 43 43 []",
"Keyup: + Equal 187 []"
]
|> Enum.join("\n")
end
end
end