Skip to content

Commit 6950080

Browse files
committed
refactor(js): move code samples to use mocha
1 parent d4adebb commit 6950080

16 files changed

+684
-694
lines changed
Lines changed: 53 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,69 @@
11
const Chrome = require('selenium-webdriver/chrome');
2-
const {suite} = require('selenium-webdriver/testing');
3-
const {Browser} = require("selenium-webdriver");
2+
const { Browser, Builder } = require("selenium-webdriver");
43
const options = new Chrome.Options();
54

6-
suite(function (env) {
7-
describe('Should be able to Test Command line arguments', function () {
8-
it('headless', async function () {
9-
let driver = await env
10-
.builder()
11-
.setChromeOptions(options.addArguments('--headless=new'))
12-
.build();
5+
describe('Should be able to Test Command line arguments', function () {
6+
it('headless', async function () {
7+
let driver = new Builder()
8+
.forBrowser(Browser.CHROME)
9+
.setChromeOptions(options.addArguments('--headless=new'))
10+
.build();
1311

14-
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
15-
await driver.quit();
16-
});
12+
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
13+
await driver.quit();
14+
});
1715

18-
it('exclude switches', async function () {
19-
let driver = await env
20-
.builder()
21-
.setChromeOptions(options.excludeSwitches('enable-automation'))
22-
.build();
16+
it('exclude switches', async function () {
17+
let driver = new Builder()
18+
.forBrowser(Browser.CHROME)
19+
.setChromeOptions(options.excludeSwitches('enable-automation'))
20+
.build();
2321

24-
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
25-
await driver.quit();
26-
});
22+
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
23+
await driver.quit();
24+
});
2725

28-
it('Keep browser open - set detach to true ', async function () {
29-
let driver = await env
30-
.builder()
31-
.setChromeOptions(options.detachDriver(true))
32-
.build();
26+
it('Keep browser open - set detach to true ', async function () {
27+
let driver = new Builder()
28+
.forBrowser(Browser.CHROME)
29+
.setChromeOptions(options.detachDriver(true))
30+
.build();
3331

34-
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
32+
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
3533

36-
// As tests runs in ci, quitting the driver instance to avoid any failures
37-
await driver.quit();
38-
});
34+
// As tests runs in ci, quitting the driver instance to avoid any failures
35+
await driver.quit();
36+
});
3937

40-
xit('Start browser from specified location ', async function () {
41-
let driver = await env
42-
.builder()
43-
.setChromeOptions(options.setChromeBinaryPath(`Path to chrome binary`))
44-
.build();
38+
xit('Start browser from specified location ', async function () {
39+
let driver = new Builder()
40+
.forBrowser(Browser.CHROME)
41+
.setChromeOptions(options.setChromeBinaryPath(`Path to chrome binary`))
42+
.build();
4543

46-
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
47-
await driver.quit();
48-
});
44+
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
45+
await driver.quit();
46+
});
4947

50-
it('Basic Chrome test', async function () {
51-
const Options = new Chrome.Options();
52-
let driver = await env
53-
.builder()
54-
.setChromeOptions(Options)
55-
.build();
48+
it('Basic Chrome test', async function () {
49+
const Options = new Chrome.Options();
50+
let driver = new Builder()
51+
.forBrowser(Browser.CHROME)
52+
.setChromeOptions(Options)
53+
.build();
5654

57-
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
58-
await driver.quit();
59-
});
55+
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
56+
await driver.quit();
57+
});
6058

61-
it('Add Extension', async function () {
62-
const options = new Chrome.Options();
63-
let driver = await env
64-
.builder()
65-
.setChromeOptions(options.addExtensions(['./test/resources/extensions/webextensions-selenium-example.crx']))
66-
.build();
59+
it('Add Extension', async function () {
60+
const options = new Chrome.Options();
61+
let driver = new Builder()
62+
.forBrowser(Browser.CHROME)
63+
.setChromeOptions(options.addExtensions(['./test/resources/extensions/webextensions-selenium-example.crx']))
64+
.build();
6765

68-
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
69-
await driver.quit();
70-
});
66+
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
67+
await driver.quit();
7168
});
72-
}, { browsers: [Browser.CHROME]});
69+
});
Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,62 @@
1-
const {Browser, By} = require('selenium-webdriver');
2-
const {suite} = require('selenium-webdriver/testing');
1+
const {Browser, By, Builder } = require('selenium-webdriver');
32
const edge = require('selenium-webdriver/edge');
43
const options = new edge.Options();
54
const assert = require("assert");
65

7-
suite(function (env) {
8-
describe('Should be able to Test Command line arguments', function () {
9-
it('headless', async function () {
10-
let driver = await env
11-
.builder()
12-
.setEdgeOptions(options.addArguments('--headless=new'))
13-
.build();
146

15-
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
16-
await driver.quit();
17-
});
7+
describe('Should be able to Test Command line arguments', function () {
8+
it('headless', async function () {
9+
let driver = new Builder()
10+
.forBrowser(Browser.EDGE)
11+
.setEdgeOptions(options.addArguments('--headless=new'))
12+
.build();
1813

19-
it('exclude switches', async function () {
20-
let driver = await env
21-
.builder()
22-
.setEdgeOptions(options.excludeSwitches('enable-automation'))
23-
.build();
14+
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
15+
await driver.quit();
16+
});
2417

25-
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
26-
await driver.quit();
27-
});
18+
it('exclude switches', async function () {
19+
let driver = new Builder()
20+
.forBrowser(Browser.EDGE)
21+
.setEdgeOptions(options.excludeSwitches('enable-automation'))
22+
.build();
2823

29-
it('Keep browser open - set detach to true ', async function () {
30-
let driver = await env
31-
.builder()
32-
.setEdgeOptions(options.detachDriver(true))
33-
.build();
24+
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
25+
await driver.quit();
26+
});
3427

35-
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
28+
it('Keep browser open - set detach to true ', async function () {
29+
let driver = new Builder()
30+
.forBrowser(Browser.EDGE)
31+
.setEdgeOptions(options.detachDriver(true))
32+
.build();
3633

37-
// As tests runs in ci, quitting the driver instance to avoid any failures
38-
await driver.quit();
39-
});
34+
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
4035

41-
it('Basic edge test', async function () {
42-
const Options = new edge.Options();
43-
let driver = await env
44-
.builder()
45-
.setEdgeOptions(Options)
46-
.build();
36+
// As tests runs in ci, quitting the driver instance to avoid any failures
37+
await driver.quit();
38+
});
4739

48-
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
49-
await driver.quit();
50-
});
40+
it('Basic edge test', async function () {
41+
const Options = new edge.Options();
42+
let driver = new Builder()
43+
.forBrowser(Browser.EDGE)
44+
.setEdgeOptions(Options)
45+
.build();
46+
47+
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
48+
await driver.quit();
49+
});
5150

52-
it('Add Extension', async function () {
53-
let driver = await env
54-
.builder()
55-
.setEdgeOptions(options.addExtensions(['./test/resources/extensions/webextensions-selenium-example.crx']))
56-
.build();
51+
it('Add Extension', async function () {
52+
let driver = new Builder()
53+
.forBrowser(Browser.EDGE)
54+
.setEdgeOptions(options.addExtensions(['./test/resources/extensions/webextensions-selenium-example.crx']))
55+
.build();
5756

58-
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
59-
let injected = await driver.findElement(By.id('webextensions-selenium-example'));
60-
assert.equal(await injected.getText(), `Content injected by webextensions-selenium-example`)
61-
await driver.quit();
62-
});
57+
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
58+
let injected = await driver.findElement(By.id('webextensions-selenium-example'));
59+
assert.equal(await injected.getText(), `Content injected by webextensions-selenium-example`)
60+
await driver.quit();
6361
});
64-
}, { browsers: [Browser.EDGE]});
62+
});
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
const {Browser, By} = require('selenium-webdriver');
1+
const {Browser, By, Builder} = require('selenium-webdriver');
22
const Firefox = require('selenium-webdriver/firefox');
33
const options = new Firefox.Options();
44
const path = require('path');
5-
const {suite} = require("selenium-webdriver/testing");
65
const assert = require("assert");
76

87

9-
suite(function (env) {
108
describe('Should be able to Test Command line arguments', function () {
119
it('headless', async function () {
12-
let driver = await env.builder()
10+
let driver = new Builder()
11+
.forBrowser(Browser.FIREFOX)
1312
.setFirefoxOptions(options.addArguments('--headless'))
1413
.build();
1514

@@ -20,7 +19,9 @@ describe('Should be able to Test Command line arguments', function () {
2019
it('Should be able to add extension', async function () {
2120

2221
const xpiPath = path.resolve('./test/resources/extensions/selenium-example.xpi')
23-
let driver = await env.builder().build();
22+
let driver = new Builder()
23+
.forBrowser(Browser.FIREFOX)
24+
.build()
2425
let id = await driver.installAddon(xpiPath);
2526
await driver.uninstallAddon(id);
2627

@@ -30,19 +31,20 @@ describe('Should be able to Test Command line arguments', function () {
3031
assert.equal(ele.length, 0);
3132
await driver.quit();
3233
});
33-
34+
3435
it('Should be able to install unsigned addon', async function () {
35-
36+
3637
const xpiPath = path.resolve('./test/resources/extensions/selenium-example')
37-
let driver = await env.builder().build();
38+
let driver = new Builder()
39+
.forBrowser(Browser.FIREFOX)
40+
.build()
3841
let id = await driver.installAddon(xpiPath, true);
3942
await driver.uninstallAddon(id);
40-
41-
43+
44+
4245
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
4346
const ele = await driver.findElements(By.id("webextensions-selenium-example"));
4447
assert.equal(ele.length, 0);
4548
await driver.quit();
4649
});
47-
});
48-
}, { browsers: [Browser.FIREFOX]});
50+
});
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
const safari = require('selenium-webdriver/safari');
2-
const {Browser} = require("selenium-webdriver");
3-
const { suite } = require('selenium-webdriver/testing')
2+
const {Browser, Builder} = require("selenium-webdriver");
43
const options = new safari.Options();
54
const process = require('node:process');
65

7-
suite(function(env) {
8-
describe('Should be able to Test Command line arguments', function () {
9-
(process.platform === 'darwin' ? it : it.skip)('headless', async function () {
10-
let driver = await env.builder()
6+
describe('Should be able to Test Command line arguments', function () {
7+
(process.platform === 'darwin' ? it : it.skip)('headless', async function () {
8+
let driver = new Builder()
9+
.forBrowser(Browser.SAFARI)
1110
.setSafariOptions(options)
1211
.build();
1312

1413
await driver.get('https://www.selenium.dev/selenium/web/blank.html');
1514
await driver.quit();
16-
});
1715
});
18-
}, { browsers: [Browser.SAFARI]});
16+
});

0 commit comments

Comments
 (0)