-
Notifications
You must be signed in to change notification settings - Fork 133
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
Support querying numeric HTML properties from elements::Element::prop()
#289
base: main
Are you sure you want to change the base?
Support querying numeric HTML properties from elements::Element::prop()
#289
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.
Thank you^2!
Arguably, prop
should just return a serde_json::Value
instead of coercing everything to a string. I'm honestly not quite sure why I made it be string only 🤔 I think it's because attribute can only return strings, and I guess I incorrectly assumed that the same would apply to prop
. But property values can be "any ECMAScript language type". Given we're going to have to cut a breaking change for #285 anyway, let's maybe just go ahead and change prop
to return serde_json::Value
right now?
… from prop() method
Hey, Jon! I've made the change you suggested so that |
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: