Introduction
Assume you use TDD, write test case first, and now you need to start to produce the minimum amount of code to pass that test.
This article describe how to make a test case as an assistant that can keep updating current issue when you are writing code, so you do not need to run test case by hand periodically to check current status.
Result
Please refer to the online demo:
ruby selenium auto retest
Pre-Request
Actually not really needed, just related for this article,
can work with local driver from terminal well.
Use Remote Webdriver in Selenium
Create Parameterized Test Service with Jenkins
Steps
1. Create an error filter
As an assistant, I wish it can report summarized error message in stead of full backtrace, so I write a filter method in test helper:
def self.displayError (error, file) puts "Error: " + error.message errArray = error.backtrace.map{ |x| x.match(/^(.+?):(\d+)(|:in `(.+)')$/); [$1,$2,$4] } errArray.each do |err| if err[0].end_with? File.basename(file) puts "Line: "+err[1]+", "+err[2]+", File: "+File.basename(file) puts "" end end end
2. Make it can retest automatically if failed.
So it will do test again and again until everything works fine, the code will as below:
reTest = true # ... while reTest do # clear reTest reTest = false # do some action and quit begin # ... rescue => error reTest = true # ... ensure driver.quit unless reTest end end
Done, now you can run the test case then start to write your code, you will keep receiving current status from the test case.
Added/Updated Files
Modified test_helper.rb
Added auto_retest_if_fail_test.rb
Added auto_redo_test.html
Added ubuntu_folder
So can use remote webdriver for 127.0.0.1
References
Ruby - get the file being executed
Catching line numbers in ruby exceptions
No comments:
Post a Comment