How can I get the Iteration number of an example script

I have the following test using Specflow, Selenium WebDriver and C #:

Scenario Outline: Verify query result
    Given I'm logged in
    When I enter "<query>"
    Then I should see the correct result

    Examples: 
    | query  |
    | Query1 |
    | Query2 |
    | Query3 |

After each scenario, I save the screenshot in a file called based on ScenarioContext.Current.ScenarioInfo.Title. However, I cannot find a good way to distinguish between iterations, so the screenshots will be overwritten. I could add a column to the example table, but I need a more general solution ...

Is there any way to find out what iteration is doing?

+4
source share
3 answers

In your definition of Step-by-Step Definition, you can write the current request in ScenarioContext.Current, for example.

[When(@"I enter (.*)")]
public void WhenIEnter(string query)
{
 ScenarioContext.Current["query"] = query;
}

AfterScenario , , , .

[AfterScenario]
void SaveScreenShot()
{
 var queryJustRun = ScenarioContext.Current["query"];

 // You could subsequently append queryJustRun to the screenshot filename to 
 // differentiate between the iterations
 // 
 // e.g. var screenShotFileName = String.Format("{0}_{1}.jpg",
 //                                ScenarioContext.Current.ScenarioInfo.Title,
 //                                queryJustRun ); 
}
+2

, ; ;

Scenario Outline: Add two numbers
    Given I have entered <first> into the calculator
    And I have entered <last> into the calculator
    When I press add
    Then the result should be <result> on the screen
Examples: 
| name   | first | last | result |
| simple | 1     | 1    | 2      |
| zero   | 0     | 0    | 0      |

, <name> , Context, FeatureContext

TestExecutionResults , , Model.TestExecutionResults []. TestItemResult.TestNode.Description - , <name>; , .

0

the name will not appear if you have not defined in your script that I see that you did not. Your function can be written as follows

  Scenario Outline: Performing mathematical operation
    Given I am on <name> scenario
    And I have entered <first> into the calculator
    And I have entered <last> into the calculator
    When I do the <operation> 
    Then the result should be <result> on the screen
Examples: 
| name   | first | last | result | operation |
| simple | 1     | 1    | 2      | add       |
| subs   | 6     | 2    | 4      | substract |

The advantage of structuring the above is that you can use the same script to perform several operations, such as add, subtract, multiply, etc.

0
source

Source: https://habr.com/ru/post/1540808/


All Articles