selenium-side-runner 正则表达式返回 NULL

selenium-side-runner RegEx returning NULL

运行 从文本中提取验证码的测试,在 Selenium 中执行 IDE 它 return 是代码但是在 selenium-side-runner 中执行时我收到 d ,d,d 或 null,请查看下面的屏幕截图

来自cli

使用的字符串

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);

不确定我做错了什么,希望 cli return 提取代码就像 IDE

中一样

SIDE文件的完整代码

{
  "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://whosebug.com/", "https://google.com/"],
  "plugins": []
}

所以看起来 match() 失败了,但设法使用 replace() 获取了代码

有效的字符串:return (${sms}.replace(/[^0-9]+/g, ""));

界面

命令行界面

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)