-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Add helper functions to ElementHandle #1151
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @sheerun, Thanks for the PR!
This is three PRs in one:
- ElementHandle.$/ElementHandle.$$
- ElementHandle.content()
- JSHandle.evaluate() (i'm not comfortable with this method name, given its current semantics)
I'd like this PR to be scoped to the ElementHandle.$/ElementHandle.$$ since it seems to be the most important. If you have time, I'd be happy to review other PR's.
lib/ElementHandle.js
Outdated
| * @param {!Array<*>} args | ||
| * @return {!Promise<*>} | ||
| */ | ||
| async evaluate(pageFunction, ...args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the evaluate and evaluateHandle methods as they are in this PR: they are named similarly to page.evaluate but have a different semantics, passing in the element as a first argument. They also should belong to JSHandle rather then ElementHandle.
lib/ElementHandle.js
Outdated
| * @return {!Promise<String>} | ||
| */ | ||
| async content() { | ||
| return this.evaluate(e => e.outerHTML, this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nice, I'd love to see this in a separate PR with a test.
| * @param {string} selector | ||
| * @return {!Promise<?ElementHandle>} | ||
| */ | ||
| async $(selector) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a test for this and for $$?
|
Please guide me where and how to write tests for this feature |
@sheerun sure:
|
|
In what file tests for this feature should be? |
|
@sheerun all tests live in a |
|
@aslushnikov I've done what you asked for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Can you please run npm run doc to regenerate the table-of-contents and please the linter?
test/test.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just put describe('ElementHandle.$', ..) and describe('ElementHandle.$$', ..) test suites somewhere next to other ElementHandle test suites. This will save you work for setting up a browser, and also will make tests faster since you'll avoid re-launching the browser.
a138d30 to
5aadb15
Compare
|
ok the tests are passing |
|
the errors on travis are irrelevant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks!
…eer#1151) This patch adds `ElementHandle.$` and `ElementHandle.$$` methods to query nested elements. Fixes puppeteer#508
Fixes #508