I have some documents to upload it. For that, I wrote a scenario. I need to run the same feature file multiple times. How can I run the feature file Multiple times?
Instead of using multiple feature file use scenario outline which will execute the same scenario multiple time as per the example table you will provide to it
Example:
Scenario Outline: Create ABC
Given I open the application
When I enter username as <username>
And I enter password as <password>
Then I enter title as <title>
And press submit
Examples:
| username | password | title |
| Rob | xyz1 | title1 |
| Bob | xyz1 | title2 |
So here the same scenario will run 2 times as example table have 2 data, you can add as many data table and cucumber will execute that number of times
Related
I need to verify bunch of sites that are using our templates. After login in I need to verify many info which I will put in the second table. How to write the gherkin code so that For each item in table "userinfo" it goes through All the items in table "siteinfo". I am seeing error calling them by userinfo.url or siteMenu.menuiitem. I am using python-bdd.
Scenario Outline: Login to SAP
Given User is on login page url <url>
When User enters username <username> and passwrod <password>
Then user should see <menuitem> <title> and <description>
Example: usefinfo
| url | username| password |
| siteA | Userx | pass1 |
| siteB | UserY | pass1 |
Example: siiteInfo
|menuitem | title | description |
|Community Managment | T1 | Text1 |
|User Managment | T2 | Text2 |
|Environment Management | T3 | Text3 |
|Loggin | T4 | Text4 |
|Miscellaneous | T5 | Text5 |
Use a different approach. Instead of trying to write one hugely complex low quality Cuke, write several simple high quality cukes.
Once you have a set of cukes that verify correctly that one particular site works correctly with your templates, then run that set of cukes against your other sites. You can do this by externalising site, perhaps as an environment variable, or by modifying cuke config, or by running the same set of cukes in different places.
This will be a much more sustainable solution in the medium term particularly when
you get asked to add new tests for each site
you get asked to add a site specific test.
I'm starting with Cucumber and Selenium.
I've created a test case where selenium runs a form and inputs default values, and clicks on default buttons, let's call this test case 1, but now I need test case 2, where I should run same steps, but with different inputs, imagine this:
I have a form where I have a selection, if the user is a Male or Female, depending on the button clicked, my form changes, so if I choose Male, I get for example an input asking if I'm "tall" (just an example), but if I choose Female, I get an input asking if "I have a boyfriend". Depending on my journey on the form the final result is different, taking this into account:
How could I create multiple test cases, without repeating code, that would test each option?
Example:
Test case A: Male Input
Test case B: Female Input
I need Test case A to finish the form, and next execute Test Case B, remember that my form has inputs that are the same in both scenarios, so I will have to use multiple times the same:
Scenario A:
Given I have to choose Male or Female
When I click ('one of them')
Then I will click other stuff
Is this even possible?
Welcome to Stackoverflow!
Scenario Outline is something best suits your scenario.
Scenario Outline: Validate Selection
Given I am in the required page
When I selection <choice> from the option
Then I will click other stuff
Examples:
|choice|
|Male |
|Female|
Best example from the docs here. Link
Scenario Outline: eating
Given there are <start> cucumbers
When I eat <eat> cucumbers
Then I should have <left> cucumbers
Examples:
| start | eat | left |
| 12 | 5 | 7 |
| 20 | 5 | 15 |
Feature: showing off behave style
Scenario Outline: wow
Given I put "<brand_one/brand_two>" in a blender
When we implement a test
Examples: Brand
| brand_one|brand_two|
| first Frog | second Frog|
I want to select brand_one or brand_two at run time.
On executing feature file i just want to execute method taking value of brand_one (i.e first Frog) or brand_two (i.e seconf Frog) at run time. But only execute one desired brand and not the other one. Please help me out to select this on run time. Thanks
You could use tags for this:
Feature: showing off behave style
Scenario Outline: wow
Given I put "<brand>" in a blender
When we implement a test
#FrogOne
Examples: Brand
| brand|
| first Frog |
#FrogTwo
Examples: Brand
| brand|
| second Frog|
Then choose it at run time like so
behave -t FrogOne
or
behave --tags FrogOne
Below is the list of steps that should be performed as part of my scenario.
Verify the file generated at S3 location with Redshift DB
Verify the duplicate between the original script with latest script
Verify the newly added column in latest script
Verify that old column data is intact in original script and latest script
And I have the below feature to cover the same.
Feature:Add # of times PDP browsed to search and sort output files User Story CDH-3311
#regression
Scenario Outline: :Validation of file being generated at S3 location after job run
Given user has the json file with <country> and <brand>
Then user execute the Generic-extract-Batch job
Then user verify the file is generated successfully at S3 location
Then user verify the data in Redshift db with generated file
Then user verify the duplicate data in latest sql script
And user verify the duplicate data in original sql script
And user verify PDP_VIEWS column in latest sql script
And user verify <old coulmn> data of original script
And user compare it with the latest sql script
Examples:
| country | brand | old column |
| US | test1 | test6 |
| US | test2 | STORE |
| US | test3 | test7 |
| US | test4 | SALESUNITSCORE |
| US | test5 | TOTALSCORE |
Kindly verify that the outline adhere to best practices and is the correct representation of the things that needs to be done for the above mentioned tests
Not sure about the business flow, but make sure there are not spaces in the examples table columns. so the last column should be old_column.
Is it possible to somehow construct a Scenario which uses two different Example tables in different steps? Something like this:
Given I log in
When I view a page
Then I should see <goodText>
Examples:
|goodText|
|abc|
And I should not see <badText>
Examples:
|badText|
|xyz|
The scenario above doesn't work, also in reality there would be more rows to each table.
It looks like you're confusing tables with scenario examples. You can mix them, but from your example I'm not sure what you're trying to achieve. Why not just write:
Given I log in
When I view a page
Then I should see "abc"
But I should not see "xyz"
or if you wanted to check for multiple strings:
Given I log in
When I view a page
Then I should see the following text:
| abc |
| def |
But I should not see the following text:
| xyz |
| uvw |
You say that in reality there would be many more rows to the table; but of course a table can also have many columns.
Would this not work for you?
Given I log in
When I view a page
Then I should see <goodText>
But I should not see <badText>
Examples:
|goodText| badText |
|abc | xyz |