Hi @konzy262 - long post, sorry!
Yes our visual and functional automated tests definitely cover the same ground as we donāt run visual every time depending on the changes made, we might choose to just run functional, the duplication weāre trying to avoid is the Cucumber step definitions and the methods we use, not the features.
I donāt know that this is the correct way to do it but this is what we currently have - and how Iām working on changing it
Previously a very simple visual testing feature we had looked like this:
(We use Cucumber/Gherkin/Ruby.)
Scenario: Take screenshot of homepage
Given a user visists the homepage
Then a screenshot is taken of the homepage
Given(/^a user visits the homepage$/) do
method_to_visit_homepage
end
Then(/^a screenshot is taken of the homepage$/) do
method_that_takes_screenshot_and_gives_it_a_label('homepage_label')
end
Iām aiming to remove a lot of code by replacing the āthenā to something more common like this:
Scenario: Take screenshot of homepage
Given a user visists the homepage
Then a screenshot is taken of the āhomepageā
So the āThenā will now be somewhere separate to the other steps and āhomepageā is the value of the label parameter in this case but could be a different value for another test. The āthenā may become an āandā, Iām not sure yet.
Then(/^a screenshot is taken of the "([^"]*)"$/) do | label |
method_that_takes_screenshot_and_gives_it_a_label(label)
end
We also have a LOT of step definitions that are only used in the visual tests but are the same as the functional ones. Using the example above, we might have a Given a user visits the homepage - visual test
and a Given the user visits the homepage
for the functional tests when they share the same code. Iām hoping to fix that too where I can because itās totally unecessary!
Using your example, we do repeat steps in tests. For instace, we have a test to check page C, and it needs to go through pages A and B first to get there. We will just have a single visual test feature to check C but within the steps it will go through A and B without doing a visual check. We will have separate tests that will do a visual check of A and another that will do a visual check of B.
Currently they donāt always use the shared steps but Iād like them to and they donāt take any screenshots for the visual check until the final step.
I donāt know which is better in this case and itās not something Iāve looked in to. Perhaps we should do A, B and C all in a single feature and do visual checks at each stage.
I hope all of that made sense!