Writing BDD Function Files Shorter and Cleaner

I have many scripts that are identical, they differ only in the data that is transmitted to them. That's an example:

Function: Linking facts from a report in an Excel document
   To link facts to an Excel document
   As a user with access to a report I want to click a fact value in a report

Scenario: any uri element
   Given that I am logged in as admin with admin
   And I selected a sample project
   And I decided to view a report view containing data from factcollection1 and all periods and all clients
   When I click on cell excel C2
   And I click on the value in 2 columns of a row called any element uri
   Then cell Excel C2 should contain the value of some Internet address

Scenario: Base64 base element
   Given that I am logged in as admin with admin
   And I selected a sample project
   And I decided to view the report view containing data from factcollection1 and all periods and all clients
   When I click on cell Excel F3
   And I click on the value in 2 columns of a row called base64 binary element
   Then cell Excel F3 should contain the value asdf

:
   , admin admin
   
    , factcollection1 ,
    excel J3
    2 boolean item
    Excel J3 true

, :

:
, admin admin
   
    , factcollection1

:
excel XX
    YY ZZ
    Excel YY WW

, :

| XX | YY |          ZZ        |              WW              |
| C2 | 2  | any uri item       |    some internet address     |
| F3 | 2  | base64 binary item |               asdf           |
| J3 | 2  | boolean item       |        true                  |

.

.

Scenario Outline: display label in selected language
Given I am logged as <username> with <password>
  And I have clicked on <button> button
  Then result should be some result

Examples:
  | username | password | button |
  |  john    |  doe     | first  |
      |  foo     |  bar     | second |
+3
2

, , "Data Based Specifications". " " ​​ ", ", .

, "" "" , .

unit test, BDD . "Given X When Y Then Z". , "X" . , , Fixture, . , LoggedInUserFixture, .

, . , LoggedInUserFixture UserWithSampleProjectSelected. - , .

.

, , , ( ). . SubSpec.

+1
source

You can use Scenario Outlineinstead Scenario. Your example would look something like this:

Scenario Outline: 
  Given I am logged as admin with admin
  And I have selected Sample Project
  And I have chosen to view report presentation view containing data from factcollection1 and all periods and all clients
  When I click on excel cell '<Cell>'
  And I click on the value in '<Column>' column of the row entitled '<Row>'
  Then Excel cell '<Cell>' should contain value '<CellValue>'

Examples: 
  | Cell | Column | Row                | CellValue             |
  | C2   | 2      | any uri item       | some internet address |
  | F3   | 2      | base64 binary item | asdf                  |
  | J3   | 2      | boolean item       | true                  |
+3
source

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


All Articles