Skip to content

Commit aae62d1

Browse files
devversionmmalerba
authored andcommitted
test: setup integration test for harnesses with selenium-webdriver
sets up an integration test for harnesses with selenium-webdriver. This test is valuable as it ensures that our harnesses can work with the Jasmine test runner + selenium-webdriver when running as ES module, compared to CommonJS which is no longer supported out of the box (as of v13).
1 parent fb6b50c commit aae62d1

File tree

6 files changed

+74
-1
lines changed

6 files changed

+74
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {Builder} from 'selenium-webdriver';
2+
import {
3+
ServiceBuilder,
4+
Options as ChromeOptions,
5+
setDefaultService,
6+
} from 'selenium-webdriver/chrome.js';
7+
8+
export function configureDriver() {
9+
const options = new ChromeOptions();
10+
const service = new ServiceBuilder(process.env['CHROMEDRIVER_BIN']!);
11+
12+
options.headless();
13+
options.addArguments('--no-sandbox');
14+
options.setChromeBinaryPath(process.env['CHROME_BIN']!);
15+
16+
setDefaultService(service.build());
17+
18+
return new Builder().forBrowser('chrome').setChromeOptions(options).build();
19+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"spec_dir": "e2e",
3+
"spec_files": [
4+
"**/*.spec.ts"
5+
],
6+
"env": {
7+
"random": true
8+
}
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "module"
3+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import {MatSelectHarness} from '@angular/material/select/testing';
2+
import {SeleniumWebDriverHarnessEnvironment} from '@angular/cdk/testing/selenium-webdriver';
3+
import {HarnessLoader} from '@angular/cdk/testing';
4+
import {configureDriver} from './driver.js';
5+
6+
describe('app test', () => {
7+
let loader: HarnessLoader;
8+
9+
beforeEach(async () => {
10+
const driver = await configureDriver();
11+
12+
await driver.get('http://localhost:4200');
13+
14+
loader = SeleniumWebDriverHarnessEnvironment.loader(driver);
15+
});
16+
17+
it('should work', async () => {
18+
const select = await loader.getHarness(MatSelectHarness);
19+
20+
expect(select).toBeDefined();
21+
expect(await select.getValueText()).toBe('');
22+
23+
await select.open();
24+
25+
const options = await select.getOptions();
26+
27+
await options[0].click();
28+
await select.close();
29+
30+
expect(await select.getValueText()).toBe('First');
31+
});
32+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"module": "es2020",
4+
"target": "es2020",
5+
"moduleResolution": "node",
6+
}
7+
}

integration/harness-e2e-cli/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"start": "ng serve",
77
"build": "ng build",
88
"watch": "ng build --watch --configuration development",
9-
"test": "ng test"
9+
"test": "ng test",
10+
"run-e2e-specs": "node --loader ts-node/esm node_modules/jasmine/bin/jasmine --config=e2e/jasmine.json",
11+
"wait-and-run-e2e": "wait-on http://localhost:4200 && yarn run-e2e-specs",
12+
"e2e": "concurrently -s first -k 'ng serve' 'yarn wait-and-run-e2e'"
1013
},
1114
"private": true,
1215
"dependencies": {

0 commit comments

Comments
 (0)