|
1 | | -const { By, Key, Browser} = require('selenium-webdriver') |
2 | | -const { suite } = require('selenium-webdriver/testing') |
| 1 | +const { By, Key, Browser, Builder} = require('selenium-webdriver') |
3 | 2 | const assert = require('assert') |
4 | 3 | const { platform } = require('node:process') |
5 | 4 |
|
6 | | -suite(function(env) { |
7 | | - describe('Keyboard Action - Keys test', function() { |
8 | | - let driver |
| 5 | +describe('Keyboard Action - Keys test', function() { |
| 6 | + let driver |
9 | 7 |
|
10 | | - before(async function() { |
11 | | - driver = await env.builder().build() |
12 | | - }) |
| 8 | + before(async function() { |
| 9 | + driver = await new Builder().forBrowser('chrome').build(); |
| 10 | + }) |
13 | 11 |
|
14 | | - after(() => driver.quit()) |
| 12 | + after(() => driver.quit()) |
15 | 13 |
|
16 | | - it('KeyDown', async function() { |
17 | | - await driver.get('https://www.selenium.dev/selenium/web/single_text_input.html') |
| 14 | + it('KeyDown', async function() { |
| 15 | + await driver.get('https://www.selenium.dev/selenium/web/single_text_input.html') |
18 | 16 |
|
19 | | - await driver.actions() |
20 | | - .keyDown(Key.SHIFT) |
21 | | - .sendKeys('a') |
22 | | - .perform() |
| 17 | + await driver.actions() |
| 18 | + .keyDown(Key.SHIFT) |
| 19 | + .sendKeys('a') |
| 20 | + .perform() |
23 | 21 |
|
24 | | - const textField = driver.findElement(By.id('textInput')) |
25 | | - assert.deepStrictEqual(await textField.getAttribute('value'), 'A') |
26 | | - }) |
| 22 | + const textField = driver.findElement(By.id('textInput')) |
| 23 | + assert.deepStrictEqual(await textField.getAttribute('value'), 'A') |
| 24 | + }) |
27 | 25 |
|
28 | | - it('KeyUp', async function() { |
29 | | - await driver.get('https://www.selenium.dev/selenium/web/single_text_input.html') |
| 26 | + it('KeyUp', async function() { |
| 27 | + await driver.get('https://www.selenium.dev/selenium/web/single_text_input.html') |
30 | 28 |
|
31 | | - const textField = driver.findElement(By.id('textInput')) |
32 | | - await textField.click() |
| 29 | + const textField = driver.findElement(By.id('textInput')) |
| 30 | + await textField.click() |
33 | 31 |
|
34 | | - await driver.actions() |
35 | | - .keyDown(Key.SHIFT) |
36 | | - .sendKeys('a') |
37 | | - .keyUp(Key.SHIFT) |
38 | | - .sendKeys('b') |
39 | | - .perform() |
| 32 | + await driver.actions() |
| 33 | + .keyDown(Key.SHIFT) |
| 34 | + .sendKeys('a') |
| 35 | + .keyUp(Key.SHIFT) |
| 36 | + .sendKeys('b') |
| 37 | + .perform() |
40 | 38 |
|
41 | | - assert.deepStrictEqual(await textField.getAttribute('value'), 'Ab') |
42 | | - }) |
| 39 | + assert.deepStrictEqual(await textField.getAttribute('value'), 'Ab') |
| 40 | + }) |
43 | 41 |
|
44 | | - it('sendKeys', async function() { |
45 | | - await driver.get('https://www.selenium.dev/selenium/web/single_text_input.html') |
| 42 | + it('sendKeys', async function() { |
| 43 | + await driver.get('https://www.selenium.dev/selenium/web/single_text_input.html') |
46 | 44 |
|
47 | | - const textField = driver.findElement(By.id('textInput')) |
48 | | - await textField.click() |
| 45 | + const textField = driver.findElement(By.id('textInput')) |
| 46 | + await textField.click() |
49 | 47 |
|
50 | | - await driver.actions() |
51 | | - .sendKeys('abc') |
52 | | - .perform() |
| 48 | + await driver.actions() |
| 49 | + .sendKeys('abc') |
| 50 | + .perform() |
53 | 51 |
|
54 | | - assert.deepStrictEqual(await textField.getAttribute('value'), 'abc') |
55 | | - }) |
| 52 | + assert.deepStrictEqual(await textField.getAttribute('value'), 'abc') |
| 53 | + }) |
56 | 54 |
|
57 | | - it('Designated Element', async function() { |
58 | | - await driver.get('https://www.selenium.dev/selenium/web/single_text_input.html') |
| 55 | + it('Designated Element', async function() { |
| 56 | + await driver.get('https://www.selenium.dev/selenium/web/single_text_input.html') |
59 | 57 |
|
60 | | - await driver.findElement(By.css('body')).click() |
61 | | - const textField = await driver.findElement(By.id('textInput')) |
| 58 | + await driver.findElement(By.css('body')).click() |
| 59 | + const textField = await driver.findElement(By.id('textInput')) |
62 | 60 |
|
63 | | - await driver.actions() |
64 | | - .sendKeys(textField, 'abc') |
65 | | - .perform() |
| 61 | + await driver.actions() |
| 62 | + .sendKeys(textField, 'abc') |
| 63 | + .perform() |
66 | 64 |
|
67 | | - assert.deepStrictEqual(await textField.getAttribute('value'), 'abc') |
68 | | - }) |
| 65 | + assert.deepStrictEqual(await textField.getAttribute('value'), 'abc') |
| 66 | + }) |
69 | 67 |
|
70 | | - it('Copy and Paste', async function() { |
71 | | - await driver.get('https://www.selenium.dev/selenium/web/single_text_input.html') |
| 68 | + it('Copy and Paste', async function() { |
| 69 | + await driver.get('https://www.selenium.dev/selenium/web/single_text_input.html') |
72 | 70 |
|
73 | | - const textField = await driver.findElement(By.id('textInput')) |
| 71 | + const textField = await driver.findElement(By.id('textInput')) |
74 | 72 |
|
75 | | - const cmdCtrl = platform.includes('darwin') ? Key.COMMAND : Key.CONTROL |
| 73 | + const cmdCtrl = platform.includes('darwin') ? Key.COMMAND : Key.CONTROL |
76 | 74 |
|
77 | | - await driver.actions() |
78 | | - .click(textField) |
79 | | - .sendKeys('Selenium!') |
80 | | - .sendKeys(Key.ARROW_LEFT) |
81 | | - .keyDown(Key.SHIFT) |
82 | | - .sendKeys(Key.ARROW_UP) |
83 | | - .keyUp(Key.SHIFT) |
84 | | - .keyDown(cmdCtrl) |
85 | | - .sendKeys('xvv') |
86 | | - .keyUp(cmdCtrl) |
87 | | - .perform() |
| 75 | + await driver.actions() |
| 76 | + .click(textField) |
| 77 | + .sendKeys('Selenium!') |
| 78 | + .sendKeys(Key.ARROW_LEFT) |
| 79 | + .keyDown(Key.SHIFT) |
| 80 | + .sendKeys(Key.ARROW_UP) |
| 81 | + .keyUp(Key.SHIFT) |
| 82 | + .keyDown(cmdCtrl) |
| 83 | + .sendKeys('xvv') |
| 84 | + .keyUp(cmdCtrl) |
| 85 | + .perform() |
88 | 86 |
|
89 | | - assert.deepStrictEqual(await textField.getAttribute('value'), 'SeleniumSelenium!') |
90 | | - }) |
| 87 | + assert.deepStrictEqual(await textField.getAttribute('value'), 'SeleniumSelenium!') |
91 | 88 | }) |
92 | | -}, { browsers: [Browser.CHROME, Browser.FIREFOX]}) |
| 89 | +}) |
0 commit comments