Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c503089

Browse files
committed
refactor[js]: update code samples to use mocha
1 parent c452fff commit c503089

File tree

12 files changed

+198
-217
lines changed

12 files changed

+198
-217
lines changed
Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,37 @@
11
const {By, Button, Browser, Builder} = require('selenium-webdriver');
2-
32
const assert = require('assert');
43

4+
describe('Should be able to perform BACK click and FORWARD click', function () {
5+
let driver;
56

6-
describe('Should be able to perform BACK click and FORWARD click', function () {
7-
let driver;
8-
9-
before(async function () {
10-
driver = new Builder().forBrowser('chrome').build();
11-
});
7+
before(async function () {
8+
driver = new Builder().forBrowser('chrome').build();
9+
});
1210

13-
after(async () => await driver.quit());
11+
after(async () => await driver.quit());
1412

15-
it('Back click', async function () {
16-
await driver.get('https://selenium.dev/selenium/web/mouse_interaction.html');
17-
await driver.findElement(By.id("click")).click();
13+
it('Back click', async function () {
14+
await driver.get('https://selenium.dev/selenium/web/mouse_interaction.html');
15+
await driver.findElement(By.id("click")).click();
1816

19-
assert.deepStrictEqual(await driver.getTitle(), `We Arrive Here`)
17+
assert.deepStrictEqual(await driver.getTitle(), `We Arrive Here`)
2018

21-
const actions = driver.actions({async: true});
22-
await actions.press(Button.BACK).release(Button.BACK).perform()
19+
const actions = driver.actions({async: true});
20+
await actions.press(Button.BACK).release(Button.BACK).perform()
2321

24-
assert.deepStrictEqual(await driver.getTitle(), `BasicMouseInterfaceTest`)
25-
});
22+
assert.deepStrictEqual(await driver.getTitle(), `BasicMouseInterfaceTest`)
23+
});
2624

27-
it('Forward click', async function () {
28-
await driver.get('https://selenium.dev/selenium/web/mouse_interaction.html');
29-
await driver.findElement(By.id("click")).click();
30-
await driver.navigate().back();
25+
it('Forward click', async function () {
26+
await driver.get('https://selenium.dev/selenium/web/mouse_interaction.html');
27+
await driver.findElement(By.id("click")).click();
28+
await driver.navigate().back();
3129

32-
assert.deepStrictEqual(await driver.getTitle(), `BasicMouseInterfaceTest`)
30+
assert.deepStrictEqual(await driver.getTitle(), `BasicMouseInterfaceTest`)
3331

34-
const actions = driver.actions({async: true});
35-
await actions.press(Button.FORWARD).release(Button.FORWARD).perform()
32+
const actions = driver.actions({async: true});
33+
await actions.press(Button.FORWARD).release(Button.FORWARD).perform()
3634

37-
assert.deepStrictEqual(await driver.getTitle(), `We Arrive Here`)
38-
});
35+
assert.deepStrictEqual(await driver.getTitle(), `We Arrive Here`)
3936
});
37+
});
Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
const {By, Builder} = require('selenium-webdriver');
22

3+
describe('Click and hold', function () {
4+
let driver;
35

6+
before(async function () {
7+
driver = new Builder().forBrowser('chrome').build();
8+
});
49

5-
describe('Click and hold', function () {
6-
let driver;
7-
8-
before(async function () {
9-
driver = new Builder().forBrowser('chrome').build();
10-
});
11-
12-
after(() => driver.quit());
13-
14-
it('Mouse move and mouseDown on an element', async function () {
15-
await driver.get('https://www.selenium.dev/selenium/web/mouse_interaction.html');
16-
let clickable = driver.findElement(By.id("clickable"));
17-
const actions = driver.actions({async: true});
18-
await actions.move({origin: clickable}).press().perform();
19-
});
10+
after(() => driver.quit());
2011

12+
it('Mouse move and mouseDown on an element', async function () {
13+
await driver.get('https://www.selenium.dev/selenium/web/mouse_interaction.html');
14+
let clickable = driver.findElement(By.id("clickable"));
15+
const actions = driver.actions({async: true});
16+
await actions.move({origin: clickable}).press().perform();
2117
});
18+
});
Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
const {By,Builder} = require('selenium-webdriver');
22

3+
describe('Click and release', function () {
4+
let driver;
35

6+
before(async function () {
7+
driver = new Builder().forBrowser('chrome').build();
8+
});
49

5-
describe('Click and release', function () {
6-
let driver;
7-
8-
before(async function () {
9-
driver = new Builder().forBrowser('chrome').build();
10-
});
11-
12-
after(() => driver.quit());
13-
14-
it('Mouse move and click on an element', async function () {
15-
await driver.get('https://www.selenium.dev/selenium/web/mouse_interaction.html');
16-
let click = driver.findElement(By.id("click"));
17-
const actions = driver.actions({async: true});
18-
await actions.move({origin: click}).click().perform();
19-
});
10+
after(() => driver.quit());
2011

12+
it('Mouse move and click on an element', async function () {
13+
await driver.get('https://www.selenium.dev/selenium/web/mouse_interaction.html');
14+
let click = driver.findElement(By.id("click"));
15+
const actions = driver.actions({async: true});
16+
await actions.move({origin: click}).click().perform();
2117
});
18+
});
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
const {By, Builder} = require('selenium-webdriver');
2-
32
const assert = require("assert");
43

4+
describe('Double click', function () {
5+
let driver;
56

6-
describe('Double click', function () {
7-
let driver;
8-
9-
before(async function () {
10-
driver = new Builder().forBrowser('chrome').build();
11-
});
7+
before(async function () {
8+
driver = new Builder().forBrowser('chrome').build();
9+
});
1210

13-
after(async () => await driver.quit());
11+
after(async () => await driver.quit());
1412

15-
it('Double-click on an element', async function () {
16-
await driver.get('https://www.selenium.dev/selenium/web/mouse_interaction.html');
17-
const clickable = driver.findElement(By.id("clickable"));
18-
const actions = driver.actions({async: true});
19-
await actions.doubleClick(clickable).perform();
13+
it('Double-click on an element', async function () {
14+
await driver.get('https://www.selenium.dev/selenium/web/mouse_interaction.html');
15+
const clickable = driver.findElement(By.id("clickable"));
16+
const actions = driver.actions({async: true});
17+
await actions.doubleClick(clickable).perform();
2018

21-
await driver.sleep(500);
22-
const status = await driver.findElement(By.id('click-status')).getText();
23-
assert.deepStrictEqual(status, `double-clicked`)
24-
});
19+
await driver.sleep(500);
20+
const status = await driver.findElement(By.id('click-status')).getText();
21+
assert.deepStrictEqual(status, `double-clicked`)
2522
});
23+
});
Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
11
const {By, Builder} = require('selenium-webdriver');
2-
32
const assert = require('assert');
43

4+
describe('Drag and Drop', function () {
5+
let driver;
56

6-
describe('Drag and Drop', function () {
7-
let driver;
8-
9-
before(async function () {
10-
driver = new Builder().forBrowser('chrome').build();
11-
});
7+
before(async function () {
8+
driver = new Builder().forBrowser('chrome').build();
9+
});
1210

13-
after(async () => await driver.quit());
11+
after(async () => await driver.quit());
1412

15-
it('By Offset', async function () {
16-
await driver.get('https://www.selenium.dev/selenium/web/mouse_interaction.html');
17-
const draggable = driver.findElement(By.id("draggable"));
18-
let start = await draggable.getRect();
19-
let finish = await driver.findElement(By.id("droppable")).getRect();
20-
const actions = driver.actions({async: true});
21-
await actions.dragAndDrop(draggable, {x: finish.x - start.x, y: finish.y - start.y}).perform();
13+
it('By Offset', async function () {
14+
await driver.get('https://www.selenium.dev/selenium/web/mouse_interaction.html');
15+
const draggable = driver.findElement(By.id("draggable"));
16+
let start = await draggable.getRect();
17+
let finish = await driver.findElement(By.id("droppable")).getRect();
18+
const actions = driver.actions({async: true});
19+
await actions.dragAndDrop(draggable, {x: finish.x - start.x, y: finish.y - start.y}).perform();
2220

23-
let result = await driver.findElement(By.id("drop-status")).getText();
24-
assert.deepStrictEqual('dropped', result)
25-
});
21+
let result = await driver.findElement(By.id("drop-status")).getText();
22+
assert.deepStrictEqual('dropped', result)
23+
});
2624

27-
it('Onto Element', async function () {
28-
await driver.get('https://www.selenium.dev/selenium/web/mouse_interaction.html');
29-
const draggable = driver.findElement(By.id("draggable"));
30-
const droppable = await driver.findElement(By.id("droppable"));
31-
const actions = driver.actions({async: true});
32-
await actions.dragAndDrop(draggable, droppable).perform();
25+
it('Onto Element', async function () {
26+
await driver.get('https://www.selenium.dev/selenium/web/mouse_interaction.html');
27+
const draggable = driver.findElement(By.id("draggable"));
28+
const droppable = await driver.findElement(By.id("droppable"));
29+
const actions = driver.actions({async: true});
30+
await actions.dragAndDrop(draggable, droppable).perform();
3331

34-
let result = await driver.findElement(By.id("drop-status")).getText();
35-
assert.deepStrictEqual('dropped', result)
36-
});
32+
let result = await driver.findElement(By.id("drop-status")).getText();
33+
assert.deepStrictEqual('dropped', result)
3734
});
35+
});
Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,47 @@
11
const {By, Origin, Builder} = require('selenium-webdriver');
2-
32
const assert = require('assert');
43

4+
describe('Mouse move by offset', function () {
5+
let driver;
56

6-
describe('Mouse move by offset', function () {
7-
let driver;
8-
9-
before(async function () {
10-
driver = new Builder().forBrowser('chrome').build();
11-
});
7+
before(async function () {
8+
driver = new Builder().forBrowser('chrome').build();
9+
});
1210

13-
after(async () => await driver.quit());
11+
after(async () => await driver.quit());
1412

15-
it('From element', async function () {
16-
await driver.get('https://www.selenium.dev/selenium/web/mouse_interaction.html');
17-
const mouseTracker = driver.findElement(By.id("mouse-tracker"));
18-
const actions = driver.actions({async: true});
19-
await actions.move({x: 8, y: 0, origin: mouseTracker}).perform();
13+
it('From element', async function () {
14+
await driver.get('https://www.selenium.dev/selenium/web/mouse_interaction.html');
15+
const mouseTracker = driver.findElement(By.id("mouse-tracker"));
16+
const actions = driver.actions({async: true});
17+
await actions.move({x: 8, y: 0, origin: mouseTracker}).perform();
2018

21-
await driver.sleep(500);
22-
let result = await driver.findElement(By.id('relative-location')).getText();
23-
result = result.split(', ');
24-
assert.deepStrictEqual((Math.abs(parseInt(result[0]) - 100 - 8) < 2), true)
25-
});
19+
await driver.sleep(500);
20+
let result = await driver.findElement(By.id('relative-location')).getText();
21+
result = result.split(', ');
22+
assert.deepStrictEqual((Math.abs(parseInt(result[0]) - 100 - 8) < 2), true)
23+
});
2624

27-
it('From viewport origin', async function () {
28-
await driver.get('https://www.selenium.dev/selenium/web/mouse_interaction.html');
29-
const actions = driver.actions({async: true});
30-
await actions.move({x: 8, y: 0}).perform();
25+
it('From viewport origin', async function () {
26+
await driver.get('https://www.selenium.dev/selenium/web/mouse_interaction.html');
27+
const actions = driver.actions({async: true});
28+
await actions.move({x: 8, y: 0}).perform();
3129

32-
let result = await driver.findElement(By.id('absolute-location')).getText();
33-
result = result.split(', ');
34-
assert.deepStrictEqual((Math.abs(parseInt(result[0]) - 8) < 2), true)
35-
});
30+
let result = await driver.findElement(By.id('absolute-location')).getText();
31+
result = result.split(', ');
32+
assert.deepStrictEqual((Math.abs(parseInt(result[0]) - 8) < 2), true)
33+
});
3634

37-
it('From current pointer location', async function () {
38-
await driver.get('https://selenium.dev/selenium/web/mouse_interaction.html');
39-
const actions = driver.actions({async: true});
40-
await actions.move({x: 6, y: 3}).perform()
35+
it('From current pointer location', async function () {
36+
await driver.get('https://selenium.dev/selenium/web/mouse_interaction.html');
37+
const actions = driver.actions({async: true});
38+
await actions.move({x: 6, y: 3}).perform()
4139

42-
await actions.move({x: 13, y: 15, origin: Origin.POINTER}).perform()
40+
await actions.move({x: 13, y: 15, origin: Origin.POINTER}).perform()
4341

44-
let result = await driver.findElement(By.id('absolute-location')).getText();
45-
result = result.split(', ');
46-
assert.deepStrictEqual(Math.abs(parseInt(result[0]) - 6 - 13) < 2, true)
47-
assert.deepStrictEqual(Math.abs(parseInt(result[1]) - 3 - 15) < 2, true)
48-
});
42+
let result = await driver.findElement(By.id('absolute-location')).getText();
43+
result = result.split(', ');
44+
assert.deepStrictEqual(Math.abs(parseInt(result[0]) - 6 - 13) < 2, true)
45+
assert.deepStrictEqual(Math.abs(parseInt(result[1]) - 3 - 15) < 2, true)
4946
});
47+
});
Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
const {By, Builder} = require('selenium-webdriver');
2-
32
const assert = require("assert");
43

4+
describe('Move to element', function () {
5+
let driver;
56

6-
describe('Move to element', function () {
7-
let driver;
8-
9-
before(async function () {
10-
driver = new Builder().forBrowser('chrome').build();
11-
});
7+
before(async function () {
8+
driver = new Builder().forBrowser('chrome').build();
9+
});
1210

13-
after(async () => await driver.quit());
11+
after(async () => await driver.quit());
1412

15-
it('Mouse move into an element', async function () {
16-
await driver.get('https://www.selenium.dev/selenium/web/mouse_interaction.html');
17-
const hoverable = driver.findElement(By.id("hover"));
18-
const actions = driver.actions({async: true});
19-
await actions.move({origin: hoverable}).perform();
13+
it('Mouse move into an element', async function () {
14+
await driver.get('https://www.selenium.dev/selenium/web/mouse_interaction.html');
15+
const hoverable = driver.findElement(By.id("hover"));
16+
const actions = driver.actions({async: true});
17+
await actions.move({origin: hoverable}).perform();
2018

21-
const status = await driver.findElement(By.id('move-status')).getText();
22-
assert.deepStrictEqual(status, `hovered`)
23-
});
19+
const status = await driver.findElement(By.id('move-status')).getText();
20+
assert.deepStrictEqual(status, `hovered`)
2421
});
22+
});
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
const {By, Builder} = require('selenium-webdriver');
2-
32
const assert = require('assert');
43

4+
describe('Right click', function () {
5+
let driver;
56

6-
describe('Right click', function () {
7-
let driver;
8-
9-
before(async function () {
10-
driver = new Builder().forBrowser('chrome').build();
11-
});
7+
before(async function () {
8+
driver = new Builder().forBrowser('chrome').build();
9+
});
1210

13-
after(async () => await driver.quit());
11+
after(async () => await driver.quit());
1412

15-
it('Mouse move and right click on an element', async function () {
16-
await driver.get('https://www.selenium.dev/selenium/web/mouse_interaction.html');
17-
const clickable = driver.findElement(By.id("clickable"));
18-
const actions = driver.actions({async: true});
19-
await actions.contextClick(clickable).perform();
13+
it('Mouse move and right click on an element', async function () {
14+
await driver.get('https://www.selenium.dev/selenium/web/mouse_interaction.html');
15+
const clickable = driver.findElement(By.id("clickable"));
16+
const actions = driver.actions({async: true});
17+
await actions.contextClick(clickable).perform();
2018

21-
await driver.sleep(500);
22-
const clicked = await driver.findElement(By.id('click-status')).getText();
23-
assert.deepStrictEqual(clicked, `context-clicked`)
24-
});
19+
await driver.sleep(500);
20+
const clicked = await driver.findElement(By.id('click-status')).getText();
21+
assert.deepStrictEqual(clicked, `context-clicked`)
2522
});
23+
});

0 commit comments

Comments
 (0)