Как работать с массивами в Selenium IDE 3.7.4 - PullRequest
1 голос
/ 23 мая 2019

В Selenium IDE 3.7.4 Я хотел бы сделать цикл, чтобы кликать по нескольким ссылкам с похожим Xpath.Для этого я думаю, что в создании массива, но попытка с простым массивом с настройками (Command, Target, Value), как показано ниже, не работает.

+----------------+---------------------------------------+---------+
| Command        | Target                                | Value   |
+----------------+---------------------------------------+---------+
| execute script | var a = "A|B|C".split("|"); return a; | arr     |
+----------------+---------------------------------------+---------+
| execute script | return 0                              | counter |
+----------------+---------------------------------------+---------+
| while          | ${counter} < 3                        |         |
+----------------+---------------------------------------+---------+
| echo           | "Element = " + ${arr[${counter}]}     |         |
+----------------+---------------------------------------+---------+
| execute script | return ${counter} + 1                 | counter |
+----------------+---------------------------------------+---------+
| end            |                                       |         |
+----------------+---------------------------------------+---------+

Ожидаемый результат для этого теста будет:

Element = A
Element = B
Element = C

И я получаю этот вывод:

"Element = " + ${arr[${counter}]}
"Element = " + ${arr[${counter}]}
"Element = " + ${arr[${counter}]}

Как я могу обрабатывать массивы и печатать их элементы в Selenium IDE?Я нашел только вопрос здесь относительно этого, но с более старой версией Selenium IDE, в которой были другие команды, такие как getEval, которых нет в последней версии.

Заранее спасибо за любыесправка.

ОБНОВЛЕНИЕ

Благодаря ответу Джима я смог завершить пример рабочего массива в Selenium IDE.Код как ниже

{
  "version": "2.0",
  "name": "Array",
  "url": "https://www.seleniumhq.org",
  "tests": [{
    "name": "Untitled",
    "commands": [{
      "command": "open",
      "target": "https://www.seleniumhq.org",
      "targets": [],
      "value": ""
    }, {
      "command": "executeScript",
      "target": "var a = \"projects|download|documentation\".split(\"|\"); return a;",
      "targets": [],
      "value": "arr"
    }, {
      "command": "executeScript",
      "target": "return 0",
      "targets": [],
      "value": "counter"
    }, {
      "command": "pause",
      "target": "4000",
      "targets": [],
      "value": ""
    }, {
      "command": "while",
      "target": "${counter} < 3",
      "targets": [],
      "value": "counter"
    }, {
      "command": "executeScript",
      "target": "return \"css=#menu_\" + ${arr}[${counter}] + \" > a\";",
      "targets": [],
      "value": "output"
    }, {
      "command": "click",
      "target": "${output}",
      "targets": [],
      "value": ""
    }, {
      "command": "pause",
      "target": "3000",
      "targets": [],
      "value": ""
    }, {
      "command": "executeScript",
      "target": "return ${counter} + 1;",
      "targets": [],
      "value": "counter"
    }, {
      "command": "end",
      "target": "",
      "targets": [],
      "value": ""
    }]
  }],
  "suites": [{
    "name": "Default Suite",
    "persistSession": false,
    "parallel": false,
    "timeout": 300,
    "tests": ["78b402ba-8dfa-47d6-bee8-7a0d928db6f1"]
  }],
  "urls": ["https://www.seleniumhq.org/"],
  "plugins": []
}

1 Ответ

1 голос
/ 23 мая 2019

Это хороший тестовый массив. Я сделал всего два небольших изменения, и теперь это работает:

  • Изменить ${arr[${counter}]} на ${arr}[${counter}]
  • Вы должны сделать доступ к массиву внутри Выполнить сценарий , а не Эхо (эхо просто печатает все, что вы положили туда)

Мой тестовый макрос: (может быть вставлен в Kantu Selenium IDE вкладка исходного кода ).

{
  "Name": "array",
  "CreationDate": "2019-5-23",
  "Commands": [
    {
      "Command": "open",
      "Target": "/8889183/kak-rabotat-s-massivami-v-selenium-ide-3-7-4",
      "Value": ""
    },
    {
      "Command": "executeScript",
      "Target": "var a = \"A|B|C\".split(\"|\"); return a;",
      "Value": "arr"
    },
    {
      "Command": "executeScript",
      "Target": "return 0",
      "Value": "counter"
    },
    {
      "Command": "while_v2",
      "Target": "${counter} < 3   ",
      "Value": "counter"
    },
    {
      "Command": "executeScript",
      "Target": "return \"Element = \" + ${arr}[${counter}] ",
      "Value": "output"
    },
    {
      "Command": "echo",
      "Target": "${output}",
      "Value": ""
    },
    {
      "Command": "executeScript",
      "Target": " return ${counter} + 1  ",
      "Value": "counter"
    },
    {
      "Command": "end",
      "Target": "",
      "Value": ""
    }
  ]
}
...