selenium-ide icon indicating copy to clipboard operation
selenium-ide copied to clipboard

appears Javascript date and time commands do not work

Open QA1MTG opened this issue 8 years ago • 8 comments

I have a number of javascript commands that i use to set date stamps for screenshots, and the commands appear to fail.
Attempting to use "storeEval" - is there an alternative to be used? Trying to execute storeEval on new Date().getFullYear() with value year... Failed: Unknown command: storeEval

QA1MTG avatar May 03 '18 13:05 QA1MTG

Not atm, it's not date and time commands rather than eval command. Duplicate of #138

corevo avatar May 03 '18 14:05 corevo

thanks . Is there an alternative for a work around?

QA1MTG avatar May 03 '18 14:05 QA1MTG

Depends on what you want to do.
Having a flexible tool like that is very important, but we need to introduce the right sandboxing mechanism to uphold user's protection.

corevo avatar May 03 '18 14:05 corevo

basically I need to be able to get the month, date, and year, so that I can use the variable as a part of time stamp for my screenshots, and also I can use these variables for data verification. My application picks dates, so I've built a mechanism to automatically update the date as I run the test daily. This also adds a date stamp to when I create Users IDs.

QA1MTG avatar May 03 '18 16:05 QA1MTG

This is now very similar to #162, which wants eval but for a safe use-case.
I'll post later today an issue about storeSafeEval and what safe means, and in what ways it's gonna be limited compared to storeEval.

corevo avatar May 04 '18 06:05 corevo

I use the store command for pretty much the same thing, but also use it to parse data in a variable.

<tr>
	<td>storeText</td>
	<td>//p/b[text()='Order#']/..</td>
	<td>t1</td>
</tr>
<tr>
	<td>echo</td>
	<td>${t1}</td>
	<td></td>
</tr>
<!-- parse data -->
<tr>
	<td>store</td>
	<td>javascript{storedVars["t1"].split(" ")["1"]}</td>
	<td>mloUID</td>
</tr>

Will the store command still allow js?

This is what I use to store the current time in a variable for use currently, haven't tried it in the new IDE yet: get todays date format mmddyyhhmmss

<tr>
	<td>store</td>
	<td>javascript{ var fd=new Date(); var date_month=fd.getMonth()+1; if (date_month < 10){ date_month = "0" + date_month; }; date_day = fd.getDate().toString(); var n=date_day.length; if (n < 2){ date_day = "0" + date_day; }; date_hour = fd.getHours().toString(); var n=date_hour.length; if (n < 2){ date_hour = "0" + date_hour; }; date_min = fd.getMinutes().toString(); var n=date_min.length; if (n < 2){ date_min = "0" + date_min; }; date_sec = fd.getSeconds().toString(); var n=date_sec.length; if (n < 2){ date_sec = "0" + date_sec; }; date_year=fd.getFullYear().toString(); date_year = date_year.toString().substr(2,2); date_month+""+date_day+""+date_year+""+date_hour+date_min+date_sec; }</td>
	<td>dateToday</td>
</tr>

98gmarquee avatar May 04 '18 14:05 98gmarquee

the store command as far as I see still works. It's just the storeEval command that appears to not be there.

QA1MTG avatar May 04 '18 14:05 QA1MTG

I will explain what I can do while being a good guy with Mozilla and Google,
For basic javascript evaluations it should be enough.
Mostly it will restrict what you can access in the application.
For example you wont be able to change a value of an input through it.

corevo avatar May 04 '18 15:05 corevo