pytest-bdd icon indicating copy to clipboard operation
pytest-bdd copied to clipboard

how to achieve multiple scenario-outlines in single feature file in pytest-bb ?

Open ajaygoutham1995 opened this issue 3 years ago • 5 comments
trafficstars

I have given the code like this but it's not working, your response would be more helpful.

Feature: login feature Scenario Outline: login with valid credentials Given login with valid and Examples: |username |password | |[email protected]|newyear2022|

Scenario Outline: login with InCorrect credentials
  Given login with incorrect <username> and <password>
  Examples:
    |username  |password |
    |[email protected]|sjbcjsbakjsans|

implementation

@scenario( "../features/login.feature", "login with valid credentials",

) def test_after(): pass

@given(parsers.parse("login with valid {username} and {password}")) def test_valid_login(username,password): print() print(username,password)

@given(parsers.parse("login with incorrect {user} and {psw}")) def test_invalid_login(user,psw): print() print(user,psw)

ajaygoutham1995 avatar Nov 23 '21 15:11 ajaygoutham1995

Hi! Please provide more clear info about your environment and pytest output. Also please check the markup of your message, seems github eat some info

elchupanebrej avatar Jan 01 '22 23:01 elchupanebrej

@elchupanebrej I also faced similar issue. Issue Description : If we are trying to add two different scenario outline in single feature file as below :

#login.feature 

Feature: login feature
   Scenario Outline: login with valid credentials
      Given login with valid <username> , <password>and <otp> 
      Examples:
      |username                |password      | otp      |
      |[email protected]|newyear2022|123123|

   Scenario Outline: login with InCorrect credentials
      Given login with incorrect <username> , <password> 
      Examples:
      |username                       |password       | 
      |[email protected]|sjbcjsbakjsans|  

As per my understanding this is not working. As a work around, for now one Scenario Outline in one file is working. Please review and let me know if there is a way to achieve the same.

Exception :

../../../.local/lib/python3.8/site-packages/pytest_bdd/scenario.py:327: in scenarios
    @scenario(feature.filename, scenario_name, **kwargs)
../../../.local/lib/python3.8/site-packages/pytest_bdd/scenario.py:244: in scenario
    scenario.validate()
../../../.local/lib/python3.8/site-packages/pytest_bdd/parser.py:269: in validate
    raise exceptions.ScenarioExamplesNotValidError(

 pytest_bdd.exceptions.ScenarioExamplesNotValidError: Scenario " Scenario description "    in the feature
 "Feature File Details " has not valid examples. Set of step parameters  

I believe it is clubbing all the examples together somehow.

Any help will be appreciated . Please let me know in case I'm doing anything wrong here .

ghost avatar Jan 17 '22 05:01 ghost

I think I found the root cause. It is happening only when there is space here Scenario Outline : if I'm writing is without space i.e. Scenario Outline: its working as expected. It could look like minor issue , but it took lot of my time. Please be careful while using this. As a summary Scenario Outline<avoid_space_here>:

ghost avatar Jan 17 '22 06:01 ghost

I am trying without space. I have two scenario outlines. Still its executing only one scenario outline( And it is picking only second scenario)

Hari-G-S avatar May 06 '22 19:05 Hari-G-S

Could you please try https://pypi.org/project/pytest-bdd-ng/ as a replacement for pytest-bdd? There official parser is used

elchupanebrej avatar May 30 '22 08:05 elchupanebrej