taiko icon indicating copy to clipboard operation
taiko copied to clipboard

Ability of supporting xpath as a parameter to checkBox

Open Avinash9271 opened this issue 3 years ago • 4 comments

click($("/html/body/input[0]")) works, but checkBox($("/html/body/input[0]")).check() doesn't.

checkBox($("/html/body/input[0]")).check() throws an error 'Uncaught You are passing a ElementWrapper to a checkBox selector. Refer https://docs.taiko.dev/api/checkbox/ for the correct parameter'

Currently, checkBox extends elementWrapper. And, it's necessary that elementWrapper needs attrValuePairs (one of its fields) to not be an instance of elementWrapper. And, currently, when an xpath is passed as a selector for checkBox, attrValuePairs is a dollarWrapper, which makes attrValuePairs an instance of elementWrapper which is currently not acceptable as a field to elementWrapper.

A potential solution: Add another field to pass as a constructor to checkBoxWrapper, dollarSelector which gets conditionally populated when the parameter is an xpath, and attrValuePairs is conditionally set to null when the parameter is an xpath . Now, deal with the dollarSelector inside the checkBox constructor itself.

Alternatives considered: Having elementWrapper deal with this conditionally. Didn't do so, because it would be affecting a lot of other wrappers which extend elementWrapper. And, making changes only in checkBoxWrapper felt sufficient.

Avinash9271 avatar Nov 08 '21 08:11 Avinash9271

Just realised there's already an issue opened. https://github.com/getgauge/taiko/issues/1519 (my bad, I should have searched it before!)

Avinash9271 avatar Nov 08 '21 10:11 Avinash9271

A note that I'd like to work on this. I'm unable to assign this to myself.

Avinash9271 avatar Nov 08 '21 10:11 Avinash9271

Sure, I can assign it to you. Just to clarify this won't break existing behaviour right? (i.e it should accept attribute value pairs too)

zabil avatar Nov 08 '21 10:11 zabil

Just to clarify this won't break existing behaviour right? (i.e it should accept attribute value pairs too).

I doesn't seem to break. I tested it locally. And, it passes the already written tests (which considers attribute value pairs) too.

Avinash9271 avatar Nov 08 '21 10:11 Avinash9271