selenium-ide
selenium-ide copied to clipboard
Accessing Object Values
🚀 Feature Proposal
To access a property value of a stored json object, I need to do a workaround using execute script command each time(ex. "execute script, return ${object}.someKey, someVariable"). This workaround causes my .side scripts to look very messy and longer than needed.
Instead of adding a new command just to access the property, I would like to do this: ${object.someKey}" any time I need to use that property value. The idea would be to modify the xlateArgument function so if the variable "object.someKey" is not found, parse it to see if "object" is found to be a variable and then access the object property value and return that as the argument. We would also have to evaluate the changes for supporting the code export of this feature.
Motivation
In Selenium IDE I need to access object properties previously stored using the storejson command, or provided as inputs to a Selianize test. Currently, accessing a property of an object requires a separate command step to execute JavaScript, which is not intuitive. I can currently access properties of objects directly when using Selianize using the proposed syntax ${objectVar.property}, and the extension and other runners should support this as well.
Example
if we want to implement the following script it would be very beneficial and it would save unnecessary commands to extract property values.
How it currently works:
command: store json target: { "People" : [{"name":"John", "age":30, "car":null }, {"name":"Paul", "age":27, "car":null }]} value: json
command: execute script target: return ${json}.People value:people
command: for each target: people value: i
command: execute script target: return ${i}.name value: name
command: type target: name=q value: ${name}
command: end target: value:
Proposal:
command: store json target: { "People" : [{"name":"John", "age":30, "car":null }, {"name":"Paul", "age":27, "car":null }]} value: json
command: for each target: json.People value: i
command: type target: name=q value: ${i.name}
command: end target: value:
@cdifino PR welcome :-)
Hi,
I was thinking on accessing properties doing ${a.b}. Is it ok if I raise a PR that works with that approach?
Thanks,
Camila
On Sat, Aug 3, 2019 at 11:38 PM Tomer Steinfeld [email protected] wrote:
He can't send that PR, we need to spec this behavior, how would we know in string interpolation if ${a}.b should be $$$.b or the b property on a?
That's why I was thinking we should move to ${a.b} but that's complex.
Cheers, Tomer On 4 Aug 2019, 8:23 +0300, Dave Haeffner [email protected], wrote:
@cdifino PR welcome :-) — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SeleniumHQ/selenium-ide/issues/765?email_source=notifications&email_token=AGLMIR6LB44RSPWM36JQIJLQCZ2M7A5CNFSM4IJBHO52YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3P3RRA#issuecomment-517978308, or mute the thread https://github.com/notifications/unsubscribe-auth/AGLMIRZDLEOUJZ7BXKM7MELQCZ2M7ANCNFSM4IJBHO5Q .
Thanks for the PR! We'll review it (#768) soon.
Will this PR be merged? I also want to use ${obj.prop} syntax.