Reputation: 643
I am using se-Builder (not selenium ide) http://sebuilder.github.io/se-builder/
and I am trying to use an assertEval and reference a previously stored variable in the javascript line.
In the selenium IDE, you reference it using a storedVars object, however the following doesn't seem to work. (I get a script error). I have also tried returning just hw and ${hw} but nothing seems to work. Here is the documentation, which doesn't seem to mention this. https://github.com/sebuilder/se-builder/wiki
store
"HelloWorld"
hw
assertEval
return storedVars['hw'] // this is the problem line
"HelloWorld"
Upvotes: 1
Views: 540
Reputation: 643
I figured it out myself.
The eval command does insert variables into eval with this:
${var}
notation.
What was screwing me up is that it inserts everything as is. So if you have a string stored as myText with the value: "some text" and try to insert it into your javascript.
var myText = ${myText};
It does not insert as
var myText = "some text";
as I incorrectly assumed (this is pretty obvious looking back that it was a terrible assumption). It is inserted directly:
var myText = some text;
what you need to do is
var myText = "${myText}";
so the result ends up like this:
var myText = "some text";
which was giving me lots of errors, but nothing helpful. I know this answer seems obvious, but I am posting the answer in case someone is making the same mistake I was.
Another thing to be aware of is the new lines will automatically be inserted into the js, which while cause another error. Which was also happening to me. I ended up needing to store an eval which removed all new lines from the element I was looking for and then storing that text.
Upvotes: 2