Skip to content

Commit af7d3d7

Browse files
authored
build: switch docs e2e tests away from protractor and run them (#33675)
Reworks the docs tests so they don't use Protractor anymore. Also fixes that they haven't been running on CI for a while.
1 parent 4fcb434 commit af7d3d7

20 files changed

Lines changed: 224 additions & 241 deletions

docs/BUILD.bazel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ load("@bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
33
load("@npm//:defs.bzl", "npm_link_all_packages")
44
load("@rules_angular//src/architect:ng_config.bzl", "ng_config")
55
load("//docs:defs.bzl", "ng_app")
6+
load("//tools:defaults.bzl", "http_server")
67

78
package(default_visibility = ["//visibility:public"])
89

@@ -47,6 +48,17 @@ alias(
4748
actual = ":build.serve",
4849
)
4950

51+
http_server(
52+
name = "server",
53+
testonly = True,
54+
additional_root_paths = [
55+
"_main/docs/dist/browser",
56+
],
57+
deps = [
58+
":build.production",
59+
],
60+
)
61+
5062
js_library(
5163
name = "audit_lib",
5264
srcs = [

docs/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ Run `pnpm bazel build //docs:build.production` to build the project.
4444

4545
1. Run `pnpm bazel test //docs/...` to execute the unit tests via [Karma](https://karma-runner.github.io).
4646

47+
## Running e2e tests
48+
49+
1. Run `pnpm bazel test //docs/e2e:e2e_tests` to execute the e2e tests via Selenium WebDriver.
50+
4751
## Scenes Development server
4852

4953
1. Run `pnpm bazel run //docs/scenes:build.serve` for a dev server. Navigate to `http://localhost:4200/`.
@@ -55,3 +59,8 @@ Run `pnpm bazel build //docs/scenes:build.production` to build the project.
5559
## Running unit tests
5660

5761
1. Run `pnpm bazel test //docs/scenes/...` to execute the unit tests via [Karma](https://karma-runner.github.io).
62+
63+
## Running Scenes e2e tests
64+
65+
1. Run `pnpm bazel test //docs/scenes/e2e:e2e_tests` to execute the scenes screenshot e2e tests.
66+

docs/angular.json

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,6 @@
173173
}
174174
]
175175
}
176-
},
177-
"e2e": {
178-
"builder": "@angular-devkit/build-angular:protractor",
179-
"options": {
180-
"protractorConfig": "e2e/protractor.conf.js",
181-
"devServerTarget": "material-angular-io:serve"
182-
},
183-
"configurations": {
184-
"production": {
185-
"devServerTarget": "material-angular-io:serve:production"
186-
}
187-
}
188176
}
189177
}
190178
},
@@ -274,18 +262,6 @@
274262
"includePaths": ["node_modules"]
275263
}
276264
}
277-
},
278-
"e2e": {
279-
"builder": "@angular-devkit/build-angular:protractor",
280-
"options": {
281-
"protractorConfig": "scenes/e2e/protractor.conf.js",
282-
"devServerTarget": "scenes:serve"
283-
},
284-
"configurations": {
285-
"production": {
286-
"devServerTarget": "scenes:serve:production"
287-
}
288-
}
289265
}
290266
}
291267
}

docs/defs.bzl

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,8 @@ TEST_CONFIG = COMMON_CONFIG + [
5353
":ng-test-config",
5454
]
5555

56-
# Common dependencies of Angular CLI e2e tests
57-
E2E_CONFIG = COMMON_CONFIG + [
58-
"@rules_browsers//browsers/chromium",
59-
"@rules_browsers//browsers/firefox",
60-
"//docs:ng-base-test-config",
61-
":ng-e2e-config",
62-
"//docs:node_modules/jasmine-spec-reporter",
63-
]
64-
E2E_DEPS = [
65-
"//docs:node_modules/@types/jasmine",
66-
"//docs:node_modules/@types/node",
67-
"//docs:node_modules/protractor",
68-
"//docs:node_modules/webdriver-manager",
69-
]
70-
7156
# buildifier: disable=unused-variable
72-
def ng_app(name, project_name = None, deps = [], test_deps = [], e2e_deps = [], **kwargs):
57+
def ng_app(name, project_name = None, deps = [], test_deps = [], **kwargs):
7358
"""
7459
Macro for Angular applications, creating various targets aligning with the Angular CLI.
7560
@@ -82,7 +67,6 @@ def ng_app(name, project_name = None, deps = [], test_deps = [], e2e_deps = [],
8267
project_name: the Angular CLI project name, to the rule name
8368
deps: dependencies of the library
8469
test_deps: additional dependencies for tests
85-
e2e_deps: additional dependencies for e2e tests
8670
**kwargs: extra args passed to main Angular CLI rules
8771
"""
8872
srcs = native.glob(
@@ -95,8 +79,6 @@ def ng_app(name, project_name = None, deps = [], test_deps = [], e2e_deps = [],
9579

9680
test_srcs = native.glob(["src/test.ts", "src/**/*.spec.ts"])
9781

98-
e2e_srcs = native.glob(["e2e/src/**/*.ts"])
99-
10082
tags = kwargs.pop("tags", [])
10183

10284
# config files
@@ -115,14 +97,6 @@ def ng_app(name, project_name = None, deps = [], test_deps = [], e2e_deps = [],
11597
],
11698
visibility = ["//visibility:private"],
11799
)
118-
copy_to_bin(
119-
name = "ng-e2e-config",
120-
srcs = [
121-
"e2e/tsconfig.json",
122-
"e2e/protractor.conf.js",
123-
],
124-
visibility = ["//visibility:private"],
125-
)
126100

127101
project_name = project_name if project_name else name
128102

@@ -154,20 +128,6 @@ def ng_app(name, project_name = None, deps = [], test_deps = [], e2e_deps = [],
154128
**kwargs
155129
)
156130

157-
# FUTURE:
158-
# _architect_test(
159-
# project_name,
160-
# "e2e",
161-
# size = "large",
162-
# srcs = srcs + e2e_srcs + deps + e2e_deps + DEPS + E2E_DEPS + E2E_CONFIG,
163-
# args = [
164-
# "--no-webdriver-update",
165-
# "--port=0",
166-
# ],
167-
# tags = tags + ["e2e"],
168-
# **kwargs
169-
# )
170-
171131
def _architect_build(project_name, configuration = None, args = [], srcs = [], **kwargs):
172132
args = []
173133

docs/e2e/BUILD.bazel

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
2+
load("//src/cdk/testing/tests:webdriver-test.bzl", "webdriver_test")
3+
load("//tools:defaults.bzl", "ts_project")
4+
5+
package(default_visibility = ["//visibility:public"])
6+
7+
ts_config(
8+
name = "tsconfig",
9+
src = "tsconfig.json",
10+
deps = [
11+
"//:node_modules/@types/jasmine",
12+
"//:node_modules/@types/node",
13+
"//:node_modules/@types/selenium-webdriver",
14+
"//src:test-tsconfig",
15+
],
16+
)
17+
18+
ts_project(
19+
name = "e2e_test_sources",
20+
testonly = True,
21+
srcs = glob(["src/**/*.ts"]),
22+
tsconfig = ":tsconfig",
23+
deps = [
24+
"//:node_modules/@bazel/runfiles",
25+
"//:node_modules/@types/jasmine",
26+
"//:node_modules/@types/node",
27+
"//:node_modules/@types/selenium-webdriver",
28+
"//:node_modules/selenium-webdriver",
29+
"//src/e2e-app:e2e_setup",
30+
],
31+
)
32+
33+
webdriver_test(
34+
name = "e2e_tests",
35+
server = "//docs:server",
36+
tags = ["e2e"],
37+
deps = [":e2e_test_sources"],
38+
)

docs/e2e/protractor.conf.js

Lines changed: 0 additions & 69 deletions
This file was deleted.

docs/e2e/src/app.e2e-spec.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,26 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9+
import * as webdriver from 'selenium-webdriver';
10+
import {createE2eWebDriver} from '../../../src/e2e-app/e2e-setup';
911
import {MaterialDocsAppPage} from './app.po';
10-
import {browser, logging} from 'protractor';
12+
13+
const {builder, port} = createE2eWebDriver();
1114

1215
describe('Material Docs App', () => {
16+
let wd: webdriver.WebDriver;
1317
let page: MaterialDocsAppPage;
1418

19+
beforeAll(async () => {
20+
wd = await builder.build();
21+
});
22+
23+
afterAll(async () => {
24+
await wd.quit();
25+
});
26+
1527
beforeEach(() => {
16-
page = new MaterialDocsAppPage();
28+
page = new MaterialDocsAppPage(wd, `http://localhost:${port}/`);
1729
});
1830

1931
it('should display welcome message', async () => {
@@ -22,12 +34,14 @@ describe('Material Docs App', () => {
2234
});
2335

2436
afterEach(async () => {
25-
// Assert that there are no errors emitted from the browser
26-
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
27-
expect(logs).not.toContain(
28-
jasmine.objectContaining({
29-
level: logging.Level.SEVERE,
30-
} as logging.Entry),
37+
// Assert that there are no application errors emitted from the browser
38+
const logs = await wd.manage().logs().get(webdriver.logging.Type.BROWSER);
39+
const errors = logs.filter(
40+
log =>
41+
log.level.name === 'SEVERE' &&
42+
!log.message.includes('ERR_ACCESS_DENIED') &&
43+
!log.message.includes('ERR_INTERNET_DISCONNECTED'),
3144
);
45+
expect(errors).toEqual([]);
3246
});
3347
});

docs/e2e/src/app.po.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,28 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {browser, by, element} from 'protractor';
9+
import * as webdriver from 'selenium-webdriver';
1010

1111
export class MaterialDocsAppPage {
12-
navigateTo() {
13-
return browser.get(browser.baseUrl) as Promise<any>;
12+
constructor(
13+
private _wd: webdriver.WebDriver,
14+
private _baseUrl: string,
15+
) {}
16+
17+
async navigateTo() {
18+
await this._wd.get(this._baseUrl);
19+
await this._wd.wait(
20+
webdriver.until.elementLocated(
21+
webdriver.By.css('app-homepage header .docs-header-headline .mat-h1'),
22+
),
23+
10000,
24+
);
1425
}
1526

16-
getTitleText() {
17-
return element(
18-
by.css('app-homepage header .docs-header-headline .mat-h1'),
19-
).getText() as Promise<string>;
27+
async getTitleText() {
28+
const el = await this._wd.findElement(
29+
webdriver.By.css('app-homepage header .docs-header-headline .mat-h1'),
30+
);
31+
return el.getText();
2032
}
2133
}

docs/e2e/tsconfig.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
2-
"extends": "../tsconfig.json",
2+
"extends": "../../src/bazel-tsconfig-test.json",
33
"compilerOptions": {
4-
"outDir": "../out-tsc/e2e",
5-
"module": "commonjs",
6-
"target": "es5",
7-
"types": ["jasmine", "jasminewd2", "node"]
4+
"declaration": true,
5+
"types": ["jasmine", "selenium-webdriver", "node"]
86
}
97
}

0 commit comments

Comments
 (0)