Ask a Question

Duplicate gherkin statements

SOLVED
TestQA1
Frequent Contributor

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!

5 REPLIES 5
rraghvani
Champion Level 2

Can you not call the same function?

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
Champion Level 2

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
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
Champion Level 2

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

rraghvani_0-1681377597624.png

rraghvani_1-1681377782787.png

 

cancel
Showing results for 
Search instead for 
Did you mean: