I have long test that call a lot of functions that test the all application. I looking for a way that in case of failure in the test, I can rollback the specific changes that the automation did on the test.
For example:
test "add user and login", session do
session
|> add_user()
# There can be more functions here...
end
def add_user(session, loops // 2) do
try do
session
|> visit("example.com")
|> fill_in(css("#user_name", with "John Doe")
|> click(css("#add_user_button"))
|> assert_has(css("#user_added_successfully_message")
rescue
msg -> if loops > 0, do: add_user(session, loops - 1), else: raise msg
end
end
In case of failure on the assert_has function (the user aded but the message don't show up), I want to rollback all the changes that happened on the database before the add_user function called again in the rescue.