1

Running a test to extract a verification code from text, executing in Selenium IDE it returns the code but when executing in selenium-side-runner I receive either d,d,d or null, have a look at the screen shots below

enter image description here

and from cli enter image description here

strings used

return (${sms}.match(/\d+/g));
var regex = (/\d+/g); var sms = ${sms}; var code = sms.match(regex);return (code);
var regex = (/\d+/g); var sms = ${sms}; var code = sms.match(regex);return Number(code);
var regex = (/\d+/g); var sms = ${sms}; var code = sms.match(regex);var integer = parseInt(code, 10); return (integer);

Not sure what I am doing wrong, expected cli to return extracted code just like in IDE

full code of SIDE file

{
  "id": "0b994070-c80e-4d08-a47c-80acfa2cfabe",
  "version": "2.0",
  "name": "sms",
  "url": "https://google.com/",
  "tests": [{
    "id": "fcd3a0c3-318a-413c-93a9-67d2a6d16afd",
    "name": "sms",
    "commands": [{
      "id": "b5660f01-72af-4406-825b-318d87309f4e",
      "comment": "",
      "command": "store",
      "target": "Your verification code is: 149599. Your code will expire in five minutes. Please do not reply.",
      "targets": [],
      "value": "sms"
    }, {
      "id": "f2273604-d068-4164-9341-5d0c317995cf",
      "comment": "",
      "command": "executeScript",
      "target": "return (${sms}.match(/\\d+/g));",
      "targets": [],
      "value": "verificationCode1"
    }, {
      "id": "ef17e1ef-69e1-400b-94db-6b1e42c5ed44",
      "comment": "",
      "command": "echo",
      "target": "verificationCode1 ${verificationCode1}",
      "targets": [],
      "value": ""
    }, {
      "id": "40fc2f41-ed06-4b53-9322-87425a90db18",
      "comment": "",
      "command": "executeScript",
      "target": "var regex = (/\\d+/g); var sms = ${sms}; var code = sms.match(regex);return (code);",
      "targets": [],
      "value": "verificationCode2"
    }, {
      "id": "34838fd8-ea17-48df-b271-6cb48c36add3",
      "comment": "",
      "command": "echo",
      "target": "verificationCode2 ${verificationCode2}",
      "targets": [],
      "value": ""
    }, {
      "id": "9ffdbf87-cf35-47fe-bd1b-c8d6c172aa20",
      "comment": "",
      "command": "executeScript",
      "target": "var regex = (/\\d+/g); var sms = ${sms}; var code = sms.match(regex);return Number(code);",
      "targets": [],
      "value": "verificationCode3"
    }, {
      "id": "fd668254-6c3d-4fed-8ccb-ee8d7d219314",
      "comment": "",
      "command": "echo",
      "target": "verificationCode3 ${verificationCode3}",
      "targets": [],
      "value": ""
    }, {
      "id": "df97f204-1836-4096-8832-63f96bb7d489",
      "comment": "",
      "command": "executeScript",
      "target": "var regex = (/\\d+/g); var sms = ${sms}; var code = sms.match(regex);var integer = parseInt(code, 10); return (integer);",
      "targets": [],
      "value": "verificationCode4"
    }, {
      "id": "299f2afc-c5a3-4740-b340-62bc60b4fdaa",
      "comment": "",
      "command": "echo",
      "target": "verificationCode4 ${verificationCode4}",
      "targets": [],
      "value": ""
    }]
  }],
  "suites": [{
    "id": "b84e7765-fa32-4bd2-bcb7-4ee89a5b0e10",
    "name": "sms",
    "persistSession": false,
    "parallel": false,
    "timeout": 300,
    "tests": ["fcd3a0c3-318a-413c-93a9-67d2a6d16afd"]
  }],
  "urls": ["https://stackoverflow.com/", "https://google.com/"],
  "plugins": []
}
J. Doe
  • 187
  • 2
  • 10

1 Answers1

1

So it looks like match() fails, but managed to get the code using replace()

string that worked: return (${sms}.replace(/[^0-9]+/g, ""));

GUI enter image description here

CLI enter image description here

var sms = "Your verification code is: 149599. Your code will expire in five minutes. Please do not reply."
console.log("SMS = " + sms)
var code = sms.replace(/[^0-9]+/g, "")
console.log("Code = " + code)
J. Doe
  • 187
  • 2
  • 10