【问题标题】:selenium-side-runner RegEx returning NULLselenium-side-runner RegEx 返回 NULL
【发布时间】:2020-12-16 20:46:57
【问题描述】:

运行测试以从文本中提取验证码,在 Selenium IDE 中执行它会返回代码,但在 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 会像在 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://stackoverflow.com/", "https://google.com/"],
  "plugins": []
}

【问题讨论】:

    标签: javascript regex selenium-ide browser-automation selenium-side-runner


    【解决方案1】:

    所以看起来 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)

    【讨论】:

      猜你喜欢
      • 2020-08-13
      • 2022-06-10
      • 2019-11-29
      • 1970-01-01
      • 2019-09-02
      • 2019-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多