Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97750

Replace strings in scenario before scenario execution

$
0
0

Say I have the following scenario:

Scenario Outline: <testCase> <expectedResult>
  Given I open the site "#"
  When I add the following data to shipment
    | field_name | field_value   |
    | id_1       | <timestamp>   |    # 1570689270595
    | id_2       | <timestamp>   |    # 1570689270595
    | id_3       | <timestamp>   |    # 1570689270595
    | id_a       | <timestamp_2> |    # 1570689272523
    | id_b       | <timestamp_2> |    # 1570689272523
    | id_c       | <timestamp_2> |    # 1570689272523


  Examples:
    | testCase          | expectedResult | timestamp     | timestamp_2   |
    | CORRECT USER INFO | PASSES         | id_$timestamp | id_$timestamp |

What I tried doing is to dynamically set the timestamp& uuid fields to create different ids for each test, as it has to be unique. And I did that by setting the beforeScenario hook and manipulating the scenario before its execution, this is the hook's code:

beforeScenario: function (uri, feature, scenario) {
    scenario.steps.forEach((step) => {
      if (step.arguments) {
        step.arguments.map((argument) => {
          if (typeof argument === 'string' || argument instanceof String)
            return uniquify(argument);
          if (argument.rows) {
            argument.rows = argument.rows.map((row) => {
              row.cells = row.cells.map((cell) => {
                cell.value = uniquify(cell.value);
                return cell;
              });
              return row;
            });
          }
          return argument;
        });
      }
    });
  }

In short, this maps every argument supplied to every step, and replaces (through uniquify function) in the argument certain predefined texts like $timestamp.

But the problem is that this isn't the correct flow I should be doing, I don't want to replace every argument supplied to each step but to replace the Example's distributed argument to steps in a way that makes ids 1 to 3 identical, and ids a to c identical.


Viewing all articles
Browse latest Browse all 97750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>