No replacement for assertEval
I often need to write complex assertions which the other assert* commands don't allow. Like passing querySelector results to a filter that checks certain DOM element properties (not attributes), and asserting something about those elements.
I found https://github.com/SeleniumHQ/selenium-ide/issues/106#issuecomment-367670775 which says assertEval is a security risk, which I believe, but don't know the technical reasons for. Is the risk that it would literally run the code inside an eval in the context of the IDE?
Would it instead work to pass the code string to a Function constructor, and pass the window as an argument to that function? Since runScript still exists, I'm not sure how that would be any different, and it would cover all the cases I use it for - just running a small snippet of code that has access to the DOM and returns a value, and asserting what the value should be.
Let me explain the risk, there are two faces to the extension, the background, which is the popup; and the content which is what automates your browser.
Running evaluated code in the background is strictly forbidden, because that code can access elevated permissions of the extension, for example the extension is able to debug the webpage, meaning that unchecked evaluated code can do practically anything with your browsing data, as well as change the way the IDE works.
That being said, running code in the content is possible under certain conditions, which for most cases would suffice, including this one.
But! as of this moment we aren't available on AMO, and adding this feature is a gray area that might hinder us from getting there.
rusScript is a command that is available in SideeX the base of the new IDE, and we simply kept it, but Mozilla might as well tell us to remove it, for this exact risk, unless we have a green light on this, I don't want to introduce a command that may get scrapped.
Okay, thanks for the explanation. I'll collect the use cases I had and see if some safer assertion commands can be devised instead. For example, I see in many cases I was using assertEval to simply count the number of elements that match a selector, which the old IDE has a assertXpathCount for (didn't see it untill now).
Awesome, I'll gladly add more assertions, also its not the end, if we get that green light from the vendors I'll add assertEval.
It's really just because I don't want people to depend on something that I can't guarantee will stay available.
FYI, version 3.1.0 (released June 21, 2018) has added support for "execute script" command which is, more-or-less, a replacement of "storeEval". For example, you could use something like the below to return "year" variable (to be used later as ${year}): Command: execute script Target: z = new Date(); var x = z.getYear(); var y = x + 1900; return y Value: year I'm not sure if this "execute script" command also has some use like the old "assertEval" (which I never used myself), but probably?
Hello corevo, are there any news about adding assertEval?
Awesome, I'll gladly add more assertions, also its not the end, if we get that green light from the vendors I'll add
assertEval. It's really just because I don't want people to depend on something that I can't guarantee will stay available.
You can use the combination of execute script and then assert the result.
We will be adding assert script instead of assertEval, perhaps open a ticket for that.