-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathkeysTest.spec.js
89 lines (66 loc) · 2.57 KB
/
keysTest.spec.js
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
79
80
81
82
83
84
85
86
87
88
89
const { By, Key, Browser, Builder} = require('selenium-webdriver')
const assert = require('assert')
const { platform } = require('node:process')
describe('Keyboard Action - Keys test', function() {
let driver
before(async function() {
driver = await new Builder().forBrowser('chrome').build();
})
after(async () => await driver.quit())
it('KeyDown', async function() {
await driver.get('https://www.selenium.dev/selenium/web/single_text_input.html')
await driver.actions()
.keyDown(Key.SHIFT)
.sendKeys('a')
.perform()
const textField = driver.findElement(By.id('textInput'))
assert.deepStrictEqual(await textField.getAttribute('value'), 'A')
})
it('KeyUp', async function() {
await driver.get('https://www.selenium.dev/selenium/web/single_text_input.html')
const textField = driver.findElement(By.id('textInput'))
await textField.click()
await driver.actions()
.keyDown(Key.SHIFT)
.sendKeys('a')
.keyUp(Key.SHIFT)
.sendKeys('b')
.perform()
assert.deepStrictEqual(await textField.getAttribute('value'), 'Ab')
})
it('sendKeys', async function() {
await driver.get('https://www.selenium.dev/selenium/web/single_text_input.html')
const textField = driver.findElement(By.id('textInput'))
await textField.click()
await driver.actions()
.sendKeys('abc')
.perform()
assert.deepStrictEqual(await textField.getAttribute('value'), 'abc')
})
it('Designated Element', async function() {
await driver.get('https://www.selenium.dev/selenium/web/single_text_input.html')
await driver.findElement(By.css('body')).click()
const textField = await driver.findElement(By.id('textInput'))
await driver.actions()
.sendKeys(textField, 'abc')
.perform()
assert.deepStrictEqual(await textField.getAttribute('value'), 'abc')
})
it('Copy and Paste', async function() {
await driver.get('https://www.selenium.dev/selenium/web/single_text_input.html')
const textField = await driver.findElement(By.id('textInput'))
const cmdCtrl = platform.includes('darwin') ? Key.COMMAND : Key.CONTROL
await driver.actions()
.click(textField)
.sendKeys('Selenium!')
.sendKeys(Key.ARROW_LEFT)
.keyDown(Key.SHIFT)
.sendKeys(Key.ARROW_UP)
.keyUp(Key.SHIFT)
.keyDown(cmdCtrl)
.sendKeys('xvv')
.keyUp(cmdCtrl)
.perform()
assert.deepStrictEqual(await textField.getAttribute('value'), 'SeleniumSelenium!')
})
})