Skip to content
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

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

Merged
merged 1 commit into from
Jul 23, 2021

Conversation

crisbeto
Copy link
Member

We use Protractor's getText method to extract text, but the problem is that it's likely based on HTMLElement.innerText which excludes text from hidden elements.

These changes switch to using textContent to bring the behavior in-line with the UnitTestElement.

@google-cla google-cla bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jan 11, 2021
We use Protractor's `getText` method to extract text, but the problem is that it's likely based
on `HTMLElement.innerText` which excludes text from hidden elements.

These changes switch to using `textContent` to bring the behavior in-line with the `UnitTestElement`.
@crisbeto crisbeto force-pushed the protractor-hidden-text branch from 8739a98 to 9187032 Compare January 11, 2021 14:46
@crisbeto crisbeto marked this pull request as ready for review January 11, 2021 14:52
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release labels Jan 11, 2021
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jelbourn jelbourn added merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note action: merge The PR is ready for merge by the caretaker labels Jan 11, 2021
@jelbourn
Copy link
Member

Caretaker note: this has a chance of breaking some e2e tests, but I suspect it to be somewhat unlikely

@mmalerba
Copy link
Contributor

There were only a few failures as a result of this, but investigating one of them uncovered something that I guess is more of a problem with the stepper. The stepper leaves steps that are not visible in the DOM. There is a project using MatButtonHarness to get the "Next" button, but with this change it always gets the button for the first step, regardless of what step is shown. Any thoughts on what the right solution to this is?

@crisbeto
Copy link
Member Author

crisbeto commented Feb 17, 2021

I suppose to correct way to handle it would be to use a selector. They would've had this issue if they were running the test using TestBed as well.

@mmalerba
Copy link
Contributor

Isn't a selector just going to have the same problem? I didn't really see any classes that identify the currently visible step to select on

@crisbeto
Copy link
Member Author

Doesn't look like we have any classes that would identify it so the stepper harness uses aria-selected for it. Maybe something like MatButtonHarness.with({text: 'Next', ancestor: '[aria-selected="true"]'})?

@mmalerba
Copy link
Contributor

Ok that seems reasonable, or better yet maybe I can just change their test to use the stepper harness

@mmalerba mmalerba merged commit 26366e7 into angular:master Jul 23, 2021
mmalerba pushed a commit that referenced this pull request Jul 23, 2021
We use Protractor's `getText` method to extract text, but the problem is that it's likely based
on `HTMLElement.innerText` which excludes text from hidden elements.

These changes switch to using `textContent` to bring the behavior in-line with the `UnitTestElement`.

(cherry picked from commit 26366e7)
crisbeto added a commit to crisbeto/material2 that referenced this pull request Jul 24, 2021
In angular#21540 we added support for extracting text from hidden elements in Protractor, but before the PR could be merged, we introduced the WebDriver environment which didn't include the fix and is failing the e2e tests.

These changes port over the fix.
mmalerba pushed a commit that referenced this pull request Jul 26, 2021
In #21540 we added support for extracting text from hidden elements in Protractor, but before the PR could be merged, we introduced the WebDriver environment which didn't include the fix and is failing the e2e tests.

These changes port over the fix.
mmalerba pushed a commit that referenced this pull request Jul 26, 2021
In #21540 we added support for extracting text from hidden elements in Protractor, but before the PR could be merged, we introduced the WebDriver environment which didn't include the fix and is failing the e2e tests.

These changes port over the fix.

(cherry picked from commit 0742bab)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Aug 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants