mcdcorp / opentest

Open source test automation tool for web applications, mobile apps and APIs
https://getopentest.org
MIT License
447 stars 107 forks source link

$data no longer working #546

Closed olivrick closed 2 years ago

olivrick commented 2 years ago

Hello @adrianth

I'm currently using OpenTest version number: 1.2.4: image

Java version 8: image

and Node.js version 17.6.0: image

I've researched the GitHub page and since I couldn't find a similar topic I decided to post it. This is my very first time posting in GitHub, therefore I'd like to apologize in advance if there's anything wrong.

Unfortunately last week after updating my OpenTest, Node.js and Java I noticed that the "$data" is now presenting errors. I've attempted "downgrading" the versions of each application however, the error is still coming up. As a last resort, I decided to do a clean install on a different computer and for my surprise the same errors were presented there.

This is what the "Actor" command prompt looks like:

23.14.34 Evaluating action 2/2 (org.getopentest.selenium.Click) in segment 1 (Click Sign In or Register dropdown)... 23.14.35 ERROR: java.lang.Exception: Failed executing test /LoginTest, segment 1 at org.getopentest.base.TestActor.executeTestSegment(TestActor.java:2165) at org.getopentest.base.TestActor.runOneSession(TestActor.java:2981) at org.getopentest.base.TestActor.runOneSession(TestActor.java:3017) at org.getopentest.Main.main(Main.java:20) Caused by: java.lang.RuntimeException: There was an error while executing action no. 2 (org.getopentest.selenium.Click) in segment 1 of test /LoginTest. The action definition was: { "action": "org.getopentest.selenium.Click", "args": { "locator": "$data(\"locators\").accountDropDown" }, "description": "Click Sign In or Register dropdown" } at org.getopentest.base.TestActor.executeTestSegment(TestActor.java:2123) ... 3 more Caused by: java.lang.RuntimeException: Failed executing action org.getopentest.selenium.Click (no arguments were provided) at org.getopentest.base.TestActor.executeActionByDef(TestActor.java:1821) at org.getopentest.base.TestActor.executeTestSegment(TestActor.java:2073) ... 3 more Caused by: java.lang.RuntimeException: There was an error while evaluating property "locator" at org.getopentest.base.TestActor.evalObject(TestActor.java:1349) at org.getopentest.base.TestActor.executeActionByDef(TestActor.java:1655) ... 4 more Caused by: java.lang.RuntimeException: Failed to evaluate JavaScript code at line number 1. The script content was: $data("locators").accountDropDown at org.getopentest.base.TestActor.evalScript(TestActor.java:1441) at org.getopentest.base.TestActor.evalString(TestActor.java:1471) at org.getopentest.base.TestActor.evalObject(TestActor.java:1389) at org.getopentest.base.TestActor.evalObject(TestActor.java:1346) ... 5 more Caused by: java.lang.RuntimeException: Failed to parse data file "locators". at org.getopentest.base.TestActor$5.apply(TestActor.java:493) at org.getopentest.base.TestActor$5.apply(TestActor.java:474) at jdk.nashorn.internal.scripts.Script$6$\^eval_.:program(:1) at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:637) at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494) at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:449) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:406) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:402) at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155) at javax.script.AbstractScriptEngine.eval(Unknown Source) at org.getopentest.base.TestActor.evalScript(TestActor.java:1427) ... 8 more Caused by: while parsing a flow mapping in 'reader', line 5, column 16: signOutButton: { css: a[href='/customer/account ... ^ expected ',' or '}', but got FlowSequenceStart in 'reader', line 5, column 24: signOutButton: { css: a[href='/customer/account/logout/'] } ^ at org.yaml.snakeyaml.parser.ParserImpl$ParseFlowMappingKey.produce(ParserImpl.java:729) at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:157) at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:147) at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:224) at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:154) at org.yaml.snakeyaml.composer.Composer.composeValueNode(Composer.java:246) at org.yaml.snakeyaml.composer.Composer.composeMappingChildren(Composer.java:237) at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:225) at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:154) at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:122) at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105) at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:122) at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:505) at org.yaml.snakeyaml.Yaml.load(Yaml.java:436) at org.getopentest.base.TestActor$5.apply(TestActor.java:491) ... 19 more

And this is my Visual Studio Code screen (just in case): image

PS.: I've also tested the locators directly in the LoginTest.yaml instead of referencing them with "$data" and they worked fine then.

Thank you in advance for your assistance.

adrianth commented 2 years ago

You have a syntax error in your "locators.yaml" file. Here are the relevant pieces from the error information you sent:

Failed to parse data file "locators".
...
Caused by: while parsing a flow mapping
in 'reader', line 5, column 16:
signOutButton: { css: a[href='/customer/account ...
^

I think you'll have to put the value a[href='/customer/account ... in double quotes. This is because it contains square brackets, which in the YAML format are used to represent arrays (aka YAML flow sequences). You should change your data file to something like this:

signOutButton: { css: "a[href='/customer/account ..." }

Please close this issue once the problem has been resolved.

olivrick commented 2 years ago

My apologies for the syntax error and thank you for the explanation. I don't know coding yet and OpenTest has been an amazing help to get things done in an efficient and scalable way. Thank you very much for your help and fast response. That indeed resolved the problem. I'm closing this issue now.