Support querying numeric HTML properties from elements::Element::prop()#289
Support querying numeric HTML properties from elements::Element::prop()#289johnDeSilencio wants to merge 8 commits intojonhoo:mainfrom
elements::Element::prop()#289Conversation
jonhoo
left a comment
There was a problem hiding this comment.
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 |
jonhoo
left a comment
There was a problem hiding this comment.
That looks way better, thank you! One more question/change and then I think we're good!
src/elements.rs
Outdated
| pub async fn html(&self, inner: bool) -> Result<String, error::CmdError> { | ||
| let prop = if inner { "innerHTML" } else { "outerHTML" }; | ||
| Ok(self.prop(prop).await?.unwrap()) | ||
| Ok(self.prop(prop).await?.unwrap().to_string()) |
There was a problem hiding this comment.
I wonder if we should be a bit more principled here and instead of .unwrap().to_string() specifically match for Some(Json::String and error anything else?
|
Some of the tests in CI seem unhappy 🤔 |
|
Ah, some of the CI is just racy: fixed in #293. Merging in |
|
@johnDeSilencio Gentle nudge on this — it's very close to getting over the line! |
…rns Json::String, returns Err() otherwise
| // Requesting `innerHTML` or `outerHTML` should normally return a string | ||
| Some(Json::String(contents)) => Ok(contents), | ||
| Some(res) => Err(error::CmdError::NotW3C(res)), | ||
| _ => Err(error::CmdError::NotW3C(Json::Null)), |
There was a problem hiding this comment.
Not sure if this is the most appropriate error variant for the None case. Open to suggestions
|
The prodigal PR author returns 😅 I've merged up my branch with the most recent work on As a side note, I want to apologize for taking so long to get back to you and to this PR. My personal life got kinda hectic, and I let this PR fall through the cracks. Totally my fault that this change missed v0.22. Thank you for your patience and the gentle reminder last month 😃 Moving forward, I've gotten my schedule mapped out pretty well in self-hosted CalDav calendars (shout-out to Stalwart), so if I do submit future PRs, the turn-around time should be significantly less than 4 months! |
| // Requesting `innerHTML` or `outerHTML` should normally return a string | ||
| Some(Json::String(contents)) => Ok(contents), | ||
| Some(res) => Err(error::CmdError::NotW3C(res)), | ||
| _ => Err(error::CmdError::NotW3C(Json::Null)), |
Codecov Report❌ Patch coverage is
Additional details and impacted files
🚀 New features to boost your workflow:
|
Thanks for understanding! And yeah, no rush on the release either :) |
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 thechildElementCountproperty.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::propmethod currently only handlesStrings,Bools, andNullvalues fromserde_jsonand returns an error for everything else. This PR also supports matchingserde_json::Numberto support getting numeric properties likechildElementCount.Tests
I've also added another
assert_eq!()to theelement_testfunction. 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: