Jim Holmes threw down the gauntlet on Twitter:
However, don’t is such a challenge to QA.
I use loops in my automated tests for the following things:
When running the same sort of test with different data.
When I want to test the same operation with different sets of data, I use a loop to jam the different set of strings into the same form.
incrementor=1
until(incrementor == number_of_rows)
item = util.get_hash_from_spreadsheet(spreadsheet,incrementor)
form.add(browser, item, log, filename)
incrementor = incrementor +1
end
When adding a large number of records for testing purposes.
I know, with just the right database management toolset, knowledge of the database, and proper tuned queries, I could go directly to the database to add a bunch of records if I want to see what happens when a user is working on a posting with a large number of comments attached to it. I want to see how it reacts when I add another comment or when I delete the posting or a comment.
So I just run a script with it:
incrementor = 0
while(incrementor < 100)
post.go_to_post(browser,post_id, log, filename)
countbefore = comment.get_comment_count(util,browser,post_id,urlstring)
comment_text= "Comment left at "+(Time.now.strftime("%m%d%y%H%M%S"))
comment.add_comment_on_want_detail(browser, post_id, comment_text, log, filename)
countafter = comment.get_comment_count(util,browser,post_id, urlstring)
incrementor = incrementor + 1
end
Sure, we can quibble about whether this is an automated test or just a script; however, the script is testing the site's ability to handle 100 comments in a row, ainna? So it's a test and not a set-up script.
When testing data loads.
I've got a client who runs different programs for banks, and individual programs are targeted to individual bank branches. This means the client runs a spreadsheet through a data load process, and I have to test to ensure that the bank branches are exposed.
So I take a spreadsheet from the data load and run it through the automated interface tester.
incrementor = 1
until(incrementor == number_of_rows)
branch = util.get_branch_from_spreadsheet(spreadsheet,incrementor)
form.search(browser, branch, log, filename)
incrementor = incrementor +1
end
So although you might have good reasons to not use loops in certain instances, loops do prove useful in automated tests.
Just remember, there's always an awful lot of sometimes in never.