@@ -513,6 +513,59 @@ Example:
513
513
def should_have_left_cucumbers (cucumbers , left ):
514
514
assert cucumbers[" start" ] - cucumbers[" eat" ] == left
515
515
516
+
517
+ Example parameters from example tables can not only be used in step names with angular brackets (e.g., <start>),
518
+ but also embedded directly within docstrings and datatables, allowing for dynamic substitution.
519
+ This provides added flexibility for scenarios that require complex setups or validations.
520
+
521
+ Example:
522
+
523
+ .. code-block :: gherkin
524
+
525
+ # content of docstring_and_datatable_with_params.feature
526
+
527
+ Feature: Docstring and Datatable with example parameters
528
+ Scenario Outline: Using parameters in docstrings and datatables
529
+ Given the following configuration:
530
+ """
531
+ username: <username>
532
+ password: <password>
533
+ """
534
+ When the user logs in
535
+ Then the response should contain:
536
+ | field | value |
537
+ | username | <username> |
538
+ | logged_in | true |
539
+
540
+ Examples:
541
+ | username | password |
542
+ | user1 | pass123 |
543
+ | user2 | 123secure |
544
+
545
+ .. code-block :: python
546
+
547
+ from pytest_bdd import scenarios, given, when, then
548
+ import json
549
+
550
+ # Load scenarios from the feature file
551
+ scenarios(" docstring_and_datatable_with_params.feature" )
552
+
553
+
554
+ @given (" the following configuration:" )
555
+ def given_user_config (docstring ):
556
+ print (docstring)
557
+
558
+
559
+ @when (" the user logs in" )
560
+ def user_logs_in (logged_in ):
561
+ logged_in = True
562
+
563
+
564
+ @then (" the response should contain:" )
565
+ def response_should_contain (datatable ):
566
+ assert datatable[1 ][1 ] in [" user1" , " user2" ]
567
+
568
+
516
569
Rules
517
570
-----
518
571
0 commit comments