Support querying numeric HTML properties from elements::Element::prop()
#289
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.
Preface
Hi, Jon! Longtime fan of yours. Your Crust of Rust series was HUGE for me going from a beginner Rust developer to more intermediate (I've got a long way to go before the rank of "master" 😄). Thank you for all the amazing work you do and how you give back to the community!
Problem
I'm building my own personal portfolio website. One of the features of the application is a terminal emulator, letting you run fake commands on the website.
One of the commands is
clear
, which clears the screen and the history of all previous commands. To write a functional test for this feature, I'd like to be able to tell that my<div id="previous-commands>
has no children which I check through thechildElementCount
property.However, when I try use
fantoccini::elements::Element::prop("childElementCount")
, I get the following error:...webdriver returned non-conforming response: Number(0)
Proposed Solution
It appears that the
fantoccini::elements::Element::prop
method currently only handlesString
s,Bool
s, andNull
values fromserde_json
and returns an error for everything else. This PR also supports matchingserde_json::Number
to support getting numeric properties likechildElementCount
.Tests
I've also added another
assert_eq!()
to theelement_test
function. Let me know if you'd like me to add more test coverage or to find another way to support numeric HTML properties.Functional Tests
I used this fork in the E2E tests for my website and now my functional tests pass: