-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.mjs
46 lines (34 loc) · 1.21 KB
/
index.test.mjs
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
import process from 'node:process';
import { findpath } from 'nw';
import selenium from 'selenium-webdriver';
import chrome from 'selenium-webdriver/chrome.js';
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { main } from './index.mjs';
describe('NW.js Selenium test suite example', async () => {
/**
* @type {chrome.Driver | undefined}
*/
let driver = undefined;
/**
* Setup Selenium driver.
*/
beforeAll(async function () {
await main();
const options = new chrome.Options();
const seleniumArguments = [
'nwapp=' + process.cwd(),
'headless=new'
];
options.addArguments(seleniumArguments);
const service = new chrome.ServiceBuilder(await findpath('chromedriver'), { sdk: 'flavor' }).build();
driver = chrome.Driver.createSession(options, service);
}, 30000);
it('text is displayed on page', async function () {
const textElement = await driver.findElement(selenium.By.id('test'));
const text = await textElement.getText();
expect(text).toEqual('world');
}, Infinity);
afterAll(async function () {
await driver.quit();
});
});