Forum Discussion

TestQA1's avatar
TestQA1
Frequent Contributor
2 years ago

Duplicate gherkin statements

Hi All,

 

In my BDD tests, I need perform same actions in different place, the problem is that each scenario should only have Given before When and Then.

 

For example.

Given close the file

Now if I need to close the file after Then... I need to create a duplicate statement with Then close the file, which doesn't make sense and create duplicate code

 

Is there any way we can link 'close the file' to both Given and Then so it gets linked to the same code.

 

Thank you!

  • This is not a great example, but gives you a rough idea of what you can do without duplicating BDD statements

     

    • TestQA1's avatar
      TestQA1
      Frequent Contributor

      You mean in the Then statement? 

      Yes, the function to close the file can be called in Then.

       

      But, when using 'When', sometimes the When statements are common in most tests and not necessarily you will need to call the same function in the common 'When'. So I was thinking if there is a way to avoid duplicate lines in bdd.

       

      Also, calling function internally in Then means the reader won't know if the file was closed.

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Depending on what file you are using, there may be methods you can use to check if the file is opened.

     

    What are you BDD statements, and what is it suppoed to do?

    • TestQA1's avatar
      TestQA1
      Frequent Contributor

      rraghvani Because the same gherkin statement cannot be linked in When Given Then. I will have to call the same methods for each of them and the step definitions will duplicate.

       

      I think this is how the Gherkin binding is designed in test complete.

       

       

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    This is not a great example, but gives you a rough idea of what you can do without duplicating BDD statements