pytest-dev / pytest-bdd

BDD library for the pytest runner
https://pytest-bdd.readthedocs.io/en/latest/
MIT License
1.31k stars 221 forks source link

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

Open ajaygoutham1995 opened 2 years ago

ajaygoutham1995 commented 2 years ago

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 | |sample@gmail.com|newyear2022|

Scenario Outline: login with InCorrect credentials
  Given login with incorrect <username> and <password>
  Examples:
    |username  |password |
    |kasjfcjsnck@Gmail.coM|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)

elchupanebrej commented 2 years ago

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

ghost commented 2 years ago

@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      |
      |sample@gmail.com|newyear2022|123123|

   Scenario Outline: login with InCorrect credentials
      Given login with incorrect <username> , <password> 
      Examples:
      |username                       |password       | 
      |kasjfcjsnck@Gmail.coM|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 commented 2 years ago

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>:

Hari-G-S commented 2 years ago

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

elchupanebrej commented 2 years ago

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