-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(cdk/testing): create a webdriver harness environment #22410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
818e87c
feat(cdk/testing): create a webdriver harness environment (#22321)
mmalerba 4d34726
test(cdk/testing): Get webdriver test suite running with dummy tests …
mmalerba b403d0e
test(cdk/testing): start the e2e-app and run webdriver tests in bazel…
mmalerba e0d8193
test(cdk/testing): port the protractor tests to the webdriver env (#2…
mmalerba 0860a32
test(cdk/testing): enable webdriver tests on CI (#22379)
mmalerba 57a3db8
fixup! test(cdk/testing): enable webdriver tests on CI (#22379)
mmalerba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
load("//tools:defaults.bzl", "jasmine_node_test") | ||
load("@io_bazel_rules_webtesting//web:web.bzl", "web_test") | ||
load("//tools/server-test:index.bzl", "server_test") | ||
|
||
def webdriver_test(name, data = [], tags = [], **kwargs): | ||
jasmine_node_test( | ||
name = "%s_jasmine_test" % name, | ||
data = data + [ | ||
"@npm//@bazel/typescript", | ||
], | ||
tags = tags + ["manual"], | ||
**kwargs | ||
) | ||
|
||
web_test( | ||
name = "%s_chromium_web_test" % name, | ||
browser = "@npm//@angular/dev-infra-private/browsers/chromium:chromium", | ||
tags = tags + ["manual"], | ||
test = ":%s_jasmine_test" % name, | ||
) | ||
|
||
server_test( | ||
name = "%s_chromium" % name, | ||
server = "//src/e2e-app:devserver", | ||
test = ":%s_chromium_web_test" % name, | ||
tags = tags + ["e2e"], | ||
) | ||
|
||
native.test_suite( | ||
name = name, | ||
tests = [ | ||
":%s_chromium" % name, | ||
], | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import {HarnessLoader, parallel} from '@angular/cdk/testing'; | ||
import {waitForAngularReady, WebDriverHarnessEnvironment} from '@angular/cdk/testing/webdriver'; | ||
import * as webdriver from 'selenium-webdriver'; | ||
import {crossEnvironmentSpecs} from './cross-environment.spec'; | ||
import {MainComponentHarness} from './harnesses/main-component-harness'; | ||
|
||
// Tests are flaky on CI unless we increase the timeout. | ||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10_000; // 10 seconds | ||
|
||
/** | ||
* Metadata file generated by `rules_webtesting` for browser tests. | ||
* The metadata provides configuration for launching the browser and | ||
* necessary capabilities. See source for details: | ||
* https://github.com/bazelbuild/rules_webtesting/blob/06023bb3/web/internal/metadata.bzl#L69-L82 | ||
*/ | ||
interface WebTestMetadata { | ||
capabilities: webdriver.Capabilities; | ||
} | ||
|
||
if (process.env['WEB_TEST_METADATA'] === undefined) { | ||
console.error(`Test running outside of a "web_test" target. No browser found.`); | ||
process.exit(1); | ||
} | ||
|
||
const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']!); | ||
const webTestMetadata: WebTestMetadata = | ||
require(runfiles.resolve(process.env['WEB_TEST_METADATA'])); | ||
const port = process.env['TEST_SERVER_PORT']; | ||
|
||
// Kagekiri is available globally in the browser. We declare it here so we can use it in the | ||
// browser-side script passed to `By.js`. | ||
declare const kagekiri: { | ||
querySelectorAll: (selector: string, root: Element) => NodeListOf<Element> | ||
}; | ||
|
||
describe('WebDriverHarnessEnvironment', () => { | ||
let wd: webdriver.WebDriver; | ||
|
||
async function getUrl(path: string) { | ||
await wd.get(`http://localhost:${port}${path}`); | ||
await waitForAngularReady(wd); | ||
} | ||
|
||
async function piercingQueryFn(selector: string, root: () => webdriver.WebElement) { | ||
return wd.findElements(webdriver.By.js( | ||
(s: string, r: Element) => kagekiri.querySelectorAll(s, r), selector, root())); | ||
} | ||
|
||
async function activeElement() { | ||
return wd.switchTo().activeElement(); | ||
} | ||
|
||
beforeAll(async () => { | ||
wd = await new webdriver.Builder() | ||
.usingServer(process.env.WEB_TEST_WEBDRIVER_SERVER!) | ||
.withCapabilities(webTestMetadata.capabilities) | ||
.build(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await wd.quit(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await getUrl('/component-harness'); | ||
}); | ||
|
||
describe('environment specific', () => { | ||
describe('HarnessLoader', () => { | ||
let loader: HarnessLoader; | ||
|
||
beforeEach(() => { | ||
loader = WebDriverHarnessEnvironment.loader(wd); | ||
}); | ||
|
||
it('should create HarnessLoader from WebDriverHarnessEnvironment', () => { | ||
expect(loader).not.toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('ComponentHarness', () => { | ||
let harness: MainComponentHarness; | ||
|
||
beforeEach(async () => { | ||
harness = await WebDriverHarnessEnvironment.loader(wd).getHarness(MainComponentHarness); | ||
}); | ||
|
||
it('can get elements outside of host', async () => { | ||
const globalEl = await harness.globalEl(); | ||
expect(await globalEl.text()).toBe('I am a sibling!'); | ||
}); | ||
|
||
it('should get correct text excluding certain selectors', async () => { | ||
const results = await harness.subcomponentAndSpecialHarnesses(); | ||
const subHarnessHost = await results[0].host(); | ||
|
||
expect(await subHarnessHost.text({exclude: 'h2'})).toBe('ProtractorTestBedOther'); | ||
expect(await subHarnessHost.text({exclude: 'li'})).toBe('List of test tools'); | ||
}); | ||
|
||
it('should be able to retrieve the WebElement from a WebDriverElement', async () => { | ||
const element = WebDriverHarnessEnvironment.getNativeElement(await harness.host()); | ||
expect(await element.getTagName()).toBe('test-main'); | ||
}); | ||
}); | ||
|
||
describe('shadow DOM interaction', () => { | ||
it('should not pierce shadow boundary by default', async () => { | ||
const harness = await WebDriverHarnessEnvironment.loader(wd) | ||
.getHarness(MainComponentHarness); | ||
expect(await harness.shadows()).toEqual([]); | ||
}); | ||
|
||
it('should pierce shadow boundary when using piercing query', async () => { | ||
const harness = await WebDriverHarnessEnvironment.loader(wd, {queryFn: piercingQueryFn}) | ||
.getHarness(MainComponentHarness); | ||
const shadows = await harness.shadows(); | ||
expect(await parallel(() => { | ||
return shadows.map(el => el.text()); | ||
})).toEqual(['Shadow 1', 'Shadow 2']); | ||
}); | ||
|
||
it('should allow querying across shadow boundary', async () => { | ||
const harness = await WebDriverHarnessEnvironment.loader(wd, {queryFn: piercingQueryFn}) | ||
.getHarness(MainComponentHarness); | ||
expect(await (await harness.deepShadow()).text()).toBe('Shadow 2'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('environment independent', () => crossEnvironmentSpecs( | ||
() => WebDriverHarnessEnvironment.loader(wd), | ||
() => WebDriverHarnessEnvironment.loader(wd).getHarness(MainComponentHarness), | ||
async () => (await activeElement()).getAttribute('id'), | ||
)); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
load("//tools:defaults.bzl", "ts_library") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
ts_library( | ||
name = "webdriver", | ||
srcs = glob( | ||
["**/*.ts"], | ||
exclude = ["**/*.spec.ts"], | ||
), | ||
module_name = "@angular/cdk/testing/webdriver", | ||
deps = [ | ||
"//src/cdk/testing", | ||
"@npm//@types/selenium-webdriver", | ||
"@npm//selenium-webdriver", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "source-files", | ||
srcs = glob(["**/*.ts"]), | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
export * from './public-api'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
export * from './webdriver-element'; | ||
export * from './webdriver-harness-environment'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.