Skip to content

fix(cdk/testing): protractor element not extracting hidden text #21540

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 1 commit into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/cdk/testing/protractor/protractor-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ export class ProtractorElement implements TestElement {
if (options?.exclude) {
return browser.executeScript(_getTextWithExcludedElements, this.element, options.exclude);
}
return this.element.getText();
// We don't go through Protractor's `getText`, because it excludes text from hidden elements.
return browser.executeScript(`return (arguments[0].textContent || '').trim()`, this.element);
}

async getAttribute(name: string): Promise<string|null> {
Expand Down
6 changes: 6 additions & 0 deletions src/cdk/testing/tests/cross-environment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,12 @@ export function crossEnvironmentSpecs(
await button.blur();
expect(await button.isFocused()).toBe(false);
});

it('should be able to get the text of a hidden element', async () => {
const hiddenElement = await harness.hidden();
expect(await hiddenElement.text()).toBe('Hello');
});

});
}

Expand Down
1 change: 1 addition & 0 deletions src/cdk/testing/tests/harnesses/main-component-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export class MainComponentHarness extends ComponentHarness {
readonly hoverTest = this.locatorFor('#hover-box');
readonly customEventBasic = this.locatorFor('#custom-event-basic');
readonly customEventObject = this.locatorFor('#custom-event-object');
readonly hidden = this.locatorFor('.hidden-element');

private _testTools = this.locatorFor(SubComponentHarness);

Expand Down
1 change: 1 addition & 0 deletions src/cdk/testing/tests/test-main-component.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ <h1 style="height: 100px; width: 200px;">Main Component</h1>
(mouseenter)="isHovering = true"
(mouseleave)="isHovering = false"
style="width: 50px; height: 50px; background: hotpink;"></div>
<div class="hidden-element" style="display: none;">Hello</div>
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ describe('card harness', () => {

it('should get card text', async () => {
const card = await loader.getHarness(MatCardHarness);
expect(await card.getText()).toBe([
'Shiba Inu',
'Dog Breed',
'The Shiba Inu is the smallest of the six original and distinct spitz breeds of dog from' +
' Japan. A small, agile dog that copes very well with mountainous terrain, the Shiba Inu' +
' was originally bred for hunting.',
'LIKE',
'SHARE'
].join('\n'));
expect(await card.getText()).toBe('Shiba InuDog Breed The Shiba Inu is the smallest of ' +
'the six original and distinct spitz breeds of dog from ' +
'Japan. A small, agile dog that copes very well with ' +
'mountainous terrain, the Shiba Inu was originally bred ' +
'for hunting. LIKESHARE');
});

it('should get title text', async () => {
Expand Down
14 changes: 5 additions & 9 deletions src/material/card/testing/card-harness.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ describe('card harness', () => {

it('should get card text', async () => {
const card = await loader.getHarness(MatCardHarness);
expect(await card.getText()).toBe([
'Shiba Inu',
'Dog Breed',
'The Shiba Inu is the smallest of the six original and distinct spitz breeds of dog from' +
' Japan. A small, agile dog that copes very well with mountainous terrain, the Shiba Inu' +
' was originally bred for hunting.',
'LIKE',
'SHARE'
].join('\n'));
expect(await card.getText()).toBe('Shiba InuDog Breed The Shiba Inu is the smallest of ' +
'the six original and distinct spitz breeds of dog from ' +
'Japan. A small, agile dog that copes very well with ' +
'mountainous terrain, the Shiba Inu was originally bred ' +
'for hunting. LIKESHARE');
});

it('should get title text', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/material/toolbar/testing/toolbar-harness.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('toolbar harness', () => {
const toolbar = await loader.getHarness(MatToolbarHarness);

expect(await toolbar.getRowsAsText())
.toEqual(['Custom Toolbar', 'Second Line\nverified_user', 'Third Line\nfavorite\ndelete']);
.toEqual(['Custom Toolbar', 'Second Lineverified_user', 'Third Linefavoritedelete']);
});

it('should have multiple rows', async () => {
Expand Down