SeleniumHQ / selenium-ide

Open Source record and playback test automation for the web.
https://selenium.dev/selenium-ide/
Apache License 2.0
2.8k stars 764 forks source link

selenium-side-runner execute script return value not extracted correctly #1132

Open drumenbas opened 4 years ago

drumenbas commented 4 years ago

🐛 Bug Report

Recorded a test case that stores text into a variable called 'sms', running a regex script to extract a number to be used later in the test case. When running tests in side-runner execute script javascript regex returns d,d,d

To Reproduce

Steps to reproduce the behavior: As per project sms.side

Command Target Value
Store Your verification code is: 149599. Your code will expire in five minutes. Please do not reply. sms
Execute script return (${sms}.match(/\d+/g)); code
Echo ${code}

Execute in cli: selenium-side-runner -c "browserName=chrome" sms.side

Expected behavior

celenium-side-runner to be able to execute javascript regex value and store the value for reuse (example console log the echo 149599)

  console.log commons.js:5
    Your verification code is: 149599. Your code will expire in five minutes. Please do not reply.

  console.log commons.js:7
    code 149599

image

Actual behavior

  console.log commons.js:5
    Your verification code is: 149599. Your code will expire in five minutes. Please do not reply.

  console.log commons.js:7
    code d,d,d

image

Project file reproducing this issue

sms.zip

Environment

OS: Windows 10 Selenium IDE Version: v3.17.0 Selenium SIDE Runner Version: 3.17.0 Node version: v10.22.0 Browser Version: ChromeDriver 85.0.4183.38

drumenbas commented 4 years ago

So I could have sworn I tried with replace before I tried with match, seems that works fine

Command Target Value
store Your verification code is: 149599. Your code will expire in five minutes. Please do not reply. sms
echo SMS = ${sms}
execute script return (${sms}.replace(/[^0-9]+/g, "")); code
echo Code = ${code}
execute script return (${sms}.match(/\d+/g, "")); code
echo Code = ${code}

Actual behavior

match() fails, replace() works

image

Project file

sms.zip

So not sure if a bug, please feel free to close if not.

sabatale commented 4 years ago

@drumenbas Stupid question but I was actually looking for a way to get data out of the script with command runner. Do you know of any way to store the information (e.g. your verification code) in the log file? Or any external file for that matter.

drumenbas commented 4 years ago

@sabatale there is no such thing as stupid questions... Have not really played with the --output switch, but it logs the basic test statistics, so not much use there.

Now you could use some console output switch, eg. under windows your execution command would look like selenium-side-runner -c "browserName=chrome" sms.side 1> myoutput.txt 2>&1 && type myoutput.txt

The downside is you don't see the execution progress, only at the end it writes the text to file and console text.

Where normally you would see this image

You will get something like this image

But you get a txt file containing the output looking like this image

You totally hijacked my bug report 0_o

ghost commented 2 years ago

This is definitely still a problem with regex strings in general. I'm trying to do a .match on a string in the runner and it's returning null. I'm guessing it's an escaping problem (/\d+/g getting interpreted as /d+/g in this case).

E: Actually, just fixed it. I had to add an extra \\ before each \\ in the outputted .side file. Thankfully it still works in the IDE. This should really get fixed.