Is it possible to use for loop in the step function in Squish (python)
Solved
Squish
-
I tried to do a for loop in Squish step function to repeat several steps for different parameter, but it didn't work. This step function was called in the Background, so I also couldn't use the parameterization there with "Example". Any solution there?
-
@SquishHammer you can do something very simple.
Let's say you have 3 functions:
@Given("foo") def step(context): pass @When("bar") def step(context): pass @Then("baz '|any|'") def step(context, value): print(value)
First rename all the steps, so you don't have name collisions like so:
@Given("foo") def foo(context): pass @When("bar") def bar(context): pass @Then("baz '|any|'") def baz(context, value): print(value)
Then you can have another step that calls these functions:
@Given("my step '|any|'") def step(context, value): for i in range(10): foo(context) bar(context) baz(context, value)
-
@Nuno-Mendes, @SquishHammer, I advise against this, and instead suggest to create separate Python functions that do the needful, and calling those instead as desired.
-