0
Davor Building test automation frameworks with Ruby (Watir, FireWatir, Selenium RC)
Why… <ul><ul><li>Why test? </li></ul></ul><ul><ul><li>Why test automation? </li></ul></ul><ul><ul><li>Why test automation ...
Why is software testing necessary? <ul><ul><li>Software is likely to have defects </li></ul></ul><ul><ul><ul><li>People ma...
What are benefits of test automation? <ul><ul><li>Consistent and repeatable testing process  </li></ul></ul><ul><ul><li>Im...
Test automation limitations <ul><ul><li>Automated tests just complement and not replace manual tests. All test should not ...
Software Frameworks <ul><li>Definition (Wikipedia): </li></ul><ul><li>“ A software framework is a re-usable design for a s...
Why do we need test automation frameworks? <ul><ul><li>Separate routine calls from designed tests </li></ul></ul><ul><ul><...
Why should we use Ruby? <ul><ul><li>Totally free: use, copy, modify and distribute </li></ul></ul><ul><ul><li>Fully object...
Start with Ruby <ul><li>Install Ruby : </li></ul><ul><li>http://www.ruby-lang.org/en/downloads/ </li></ul><ul><li>http://r...
Ruby Editors / IDE <ul><ul><li>Free </li></ul></ul><ul><ul><li>Eclipse with RDT or DLTK </li></ul></ul><ul><ul><li>Aptana ...
WATiR <ul><ul><li>Watir – Web Application Testing in Ruby </li></ul></ul><ul><ul><li>open-source library for automating we...
FireWatir <ul><ul><li>Allows Watir scripts written for IE to work with the Firefox. </li></ul></ul><ul><ul><li>Some change...
Selenium RC <ul><ul><li>Selenium Remote Control provides a Selenium Server, which can automatically control any supported ...
Using The Ruby Interactive Shell (IRB)  <ul><ul><li>Type commands directly into the interpreter. You don’t need to </li></...
Building automated test framework approach
Simple test case <ul><li>Test scenario: </li></ul><ul><li>Start Internet Explorer and go to  www.google.se </li></ul><ul><...
<ul><li>The created code can be helpful but needs refactoring </li></ul>require 'watir' include Watir require 'test/unit' ...
Selenium IDE
Unit Test Framework (Watir & FireWatir) require  'test/unit'   class   TestSuiteSimple   <   Test :: Unit :: TestCase def ...
(Fire)Watir - setup & teardown def   df_setup   puts  &quot; 
  >>>>>  #{ to_s () }  <<<<<  
 &quot;   # output to console...
(Fire)Watir– start_browser def   start_browser (url)  browser  =   nil count  =   0 if   ENV [ 'browser' ]   ==   &quot;IE...
How does it look like in Selenium? <ul><li>require   &quot;selenium“ </li></ul><ul><li>require   &quot;test/unit&quot;   <...
(Fire)Watir - Help functions # Better readability with help functions def   test_01_simple_search @browser . text_field( :...
Selenium - Help functions # Help functions   Selenium  – some examples module   Selenium class   SeleniumDriver   def   sh...
(Fire)Watir – Win Map def   test_01_simple_search google  =   Google . new( @browser ) google . text_field_search . should...
Selenium – Win Map <ul><li>def   test_01_simple_search   </li></ul><ul><ul><li>@selenium . open  &quot;/“ </li></ul></ul><...
(Fire)Watir - encapsulating <ul><li>def   test_01_simple_search </li></ul><ul><ul><li>google  =   Google . new( @browser )...
(Fire)Watir – encapsulating 2 <ul><li>module   Actions </li></ul><ul><li>def   text_field_set (obj_ctrl, txt) </li></ul><u...
Selenium - encapsulating def   test_01_simple_search @selenium . open  &quot;/&quot; @selenium . text_field_set( Google ::...
Selenium – encapsulating 2 module   Selenium class   SeleniumDriver require   'test/unit/assertions'   include   Test :: U...
(Fire)Watir - domain functions # If you are using often the same set of actions, you could group them def   test_02_simple...
Data - driven testing def   test_03_data_driven   #################################################### # Local variables  ...
Test Reports <ul><li>Direct output to a text file </li></ul><ul><li>Download and unpack Test::Unit::Reporter from: </li></...
Test Reporter Usage require   'test/unit/testsuite' require   'test/unit/ui/reporter' require   'simple_test1_unit_ref' re...
Test Reporter
Something to think  about… <ul><li>Test automation is software development – treat it like that </li></ul><ul><li>Coding s...
Questions ? [email_address]
Upcoming SlideShare
Loading in...5
×

Download presentation

3,778

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
3,778
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
42
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Det är en Ruby bibliotek
  • Transcript of "Download presentation"

    1. 1. Davor Building test automation frameworks with Ruby (Watir, FireWatir, Selenium RC)
    2. 2. Why… <ul><ul><li>Why test? </li></ul></ul><ul><ul><li>Why test automation? </li></ul></ul><ul><ul><li>Why test automation framework? </li></ul></ul><ul><ul><li>Why ruby? </li></ul></ul>
    3. 3. Why is software testing necessary? <ul><ul><li>Software is likely to have defects </li></ul></ul><ul><ul><ul><li>People make errors (mistakes) </li></ul></ul></ul><ul><ul><ul><li>Errors can cause faults (bugs, defects) </li></ul></ul></ul><ul><ul><ul><li>Faults can cause failures. </li></ul></ul></ul><ul><ul><ul><li>Failures can cost a lot of money </li></ul></ul></ul><ul><ul><li>find defects </li></ul></ul><ul><ul><li>gain confidence about level of quality </li></ul></ul><ul><ul><li>prevent future defects </li></ul></ul><ul><ul><li>evaluate and mitigate risk </li></ul></ul><ul><ul><li>… </li></ul></ul>
    4. 4. What are benefits of test automation? <ul><ul><li>Consistent and repeatable testing process </li></ul></ul><ul><ul><li>Improved regression tests - decrease cost of change </li></ul></ul><ul><ul><li>Smoke testing </li></ul></ul><ul><ul><li>More tests can be run in less time </li></ul></ul><ul><ul><li>24/7 operation - better use of resources </li></ul></ul><ul><ul><li>Configuration testing </li></ul></ul><ul><ul><li>Data driven </li></ul></ul><ul><ul><li>Human resources are free to perform advanced manual tests </li></ul></ul><ul><ul><li>Execution of tests that can't be done manually </li></ul></ul><ul><ul><li>Tests can access system parameters that are not visible to tester </li></ul></ul><ul><ul><li>Simple reproduction of found defects </li></ul></ul><ul><ul><li>Testing costs decrease with reuse </li></ul></ul><ul><ul><li>… </li></ul></ul>
    5. 5. Test automation limitations <ul><ul><li>Automated tests just complement and not replace manual tests. All test should not be automated. </li></ul></ul><ul><ul><li>Automated tests cover only a part of possible defects </li></ul></ul><ul><ul><li>Probability to find defects is lower then for manual tests </li></ul></ul><ul><ul><li>Automation of test case decrease cost of execution but does not increase ability to find defects </li></ul></ul><ul><ul><li>Tools can be very complex and require significant training </li></ul></ul><ul><ul><li>Maintenance of the tests can be expensive </li></ul></ul><ul><ul><li>Automated test are sensitive to software changes </li></ul></ul><ul><ul><li>Handling of unexpected behaviour is not so good </li></ul></ul>
    6. 6. Software Frameworks <ul><li>Definition (Wikipedia): </li></ul><ul><li>“ A software framework is a re-usable design for a software system (or subsystem). A software framework may include support programs, code libraries, a scripting language, or other software to help develop and glue together the different components of a software project.” </li></ul>In test automation framework describes the collection of components that support your tests. Those components can also be described as frameworks.
    7. 7. Why do we need test automation frameworks? <ul><ul><li>Separate routine calls from designed tests </li></ul></ul><ul><ul><li>Modularity </li></ul></ul><ul><ul><li>Reuse of components (code) </li></ul></ul><ul><ul><li>Object oriented concepts </li></ul></ul><ul><ul><li>Encapsulation </li></ul></ul><ul><ul><li>Hide complexity </li></ul></ul><ul><ul><li>Test sripts can be written by testers with little or no programming skills </li></ul></ul><ul><ul><li>Less maintenance </li></ul></ul><ul><ul><li>Test script more reliable </li></ul></ul><ul><ul><li>Test script have longer life </li></ul></ul><ul><ul><li>etc. </li></ul></ul>
    8. 8. Why should we use Ruby? <ul><ul><li>Totally free: use, copy, modify and distribute </li></ul></ul><ul><ul><li>Fully object-oriented, dynamic scripting language </li></ul></ul><ul><ul><li>Interpreted language </li></ul></ul><ul><ul><li>Untyped language </li></ul></ul><ul><ul><li>Flexible language </li></ul></ul><ul><ul><li>Rich core library </li></ul></ul><ul><ul><li>Highly portable </li></ul></ul><ul><ul><li>Scalable (reuse modules) </li></ul></ul><ul><ul><li>Extensible (write extensions in C/C++) </li></ul></ul><ul><ul><li>Exception handling, garbage collector … </li></ul></ul><ul><ul><li>Clean and easy syntax, easy to use - high productivity </li></ul></ul><ul><ul><li>Ruby puts the fun back into programming. </li></ul></ul><ul><ul><li>… </li></ul></ul>
    9. 9. Start with Ruby <ul><li>Install Ruby : </li></ul><ul><li>http://www.ruby-lang.org/en/downloads/ </li></ul><ul><li>http://rubyforge.org/frs/?group_id=167 </li></ul><ul><li>Ruby Programming book: </li></ul><ul><li>http://phrogz.net/ProgrammingRuby/ </li></ul><ul><li>Ruby User Guides: </li></ul><ul><li>http://www.ruby-doc.org/docs/UsersGuide/rg/ </li></ul><ul><li>http://www.math.umd.edu/~dcarrera/ruby/0.3/ </li></ul><ul><li>http://www.ruby-doc.org/gettingstarted/ </li></ul><ul><li>http://rubylearning.com/ </li></ul><ul><li>http://www.zenspider.com/Languages/Ruby/QuickRef.html </li></ul>
    10. 10. Ruby Editors / IDE <ul><ul><li>Free </li></ul></ul><ul><ul><li>Eclipse with RDT or DLTK </li></ul></ul><ul><ul><li>Aptana IDE (Aptana RadRails) </li></ul></ul><ul><ul><li>RDE (Ruby IDE) </li></ul></ul><ul><ul><li>NetBeans IDE </li></ul></ul><ul><ul><li>SciTE </li></ul></ul><ul><ul><li>Komodo Editor </li></ul></ul><ul><ul><li>Crimson Editor and similar </li></ul></ul><ul><li>Comercial </li></ul><ul><ul><li>Arachno Ruby IDE </li></ul></ul><ul><ul><li>InteliJ IDEA </li></ul></ul><ul><ul><li>Komodo IDE </li></ul></ul>
    11. 11. WATiR <ul><ul><li>Watir – Web Application Testing in Ruby </li></ul></ul><ul><ul><li>open-source library for automating web browsers </li></ul></ul><ul><ul><li>works with Internet Explorer on Windows </li></ul></ul><ul><ul><li>Curently beeing ported to support Firefox (FireWatir) and Safari (SafariWatir) </li></ul></ul><ul><ul><li>Uses IE Component Object Model (COM) interface to directly access the objects on the page </li></ul></ul><ul><ul><li>Install Watir: </li></ul></ul><ul><ul><li>> gem install watir </li></ul></ul>
    12. 12. FireWatir <ul><ul><li>Allows Watir scripts written for IE to work with the Firefox. </li></ul></ul><ul><ul><li>Some changes are required </li></ul></ul><ul><ul><li>Uses JSSH (JavaScript Shell) to manipulate Firefox </li></ul></ul><ul><ul><li>Install FireWatir and JSSH </li></ul></ul><ul><ul><li>http://code.google.com/p/firewatir/downloads/list </li></ul></ul>
    13. 13. Selenium RC <ul><ul><li>Selenium Remote Control provides a Selenium Server, which can automatically control any supported browser. It works by using Selenium Core, a pure-HTML+JS library that performs automated tasks in JavaScript. </li></ul></ul><ul><ul><li>Several programming languages are supported except Ruby (Java, C#, Pyton, PHP, Perl) </li></ul></ul><ul><ul><li>Download Selenium </li></ul></ul><ul><ul><li>http://www.openqa.org/selenium-rc/download.action </li></ul></ul><ul><ul><li>You can also download gem by using command: </li></ul></ul><ul><ul><li>> gem install selenium </li></ul></ul>
    14. 14. Using The Ruby Interactive Shell (IRB) <ul><ul><li>Type commands directly into the interpreter. You don’t need to </li></ul></ul><ul><ul><li>save a file and run it. Start it from command line by typing ’ irb ’. </li></ul></ul><ul><ul><li>irb> require ’watir’ </li></ul></ul><ul><ul><li>=> true </li></ul></ul><ul><ul><li>irb> include Watir </li></ul></ul><ul><ul><li>=> Object </li></ul></ul><ul><ul><li>irb> br = IE.start(www.google.se) </li></ul></ul>> irb irb> 2 + 2 => 4 <ul><ul><li>irb> br = IE.attach(:title, ”Google”) </li></ul></ul><ul><ul><li>irb> br.button(:name, ”btnG”).flash </li></ul></ul>You can save a lot of time when attaching to page you want to test and investigating it.
    15. 15. Building automated test framework approach
    16. 16. Simple test case <ul><li>Test scenario: </li></ul><ul><li>Start Internet Explorer and go to www.google.se </li></ul><ul><li>Search for ”Testway” </li></ul><ul><ul><li>The Google result page should contain link www.testway.se </li></ul></ul><ul><li>Click the link </li></ul><ul><ul><li>Testway home page should open </li></ul></ul>
    17. 17. <ul><li>The created code can be helpful but needs refactoring </li></ul>require 'watir' include Watir require 'test/unit' class TC_recorded < Test::Unit::TestCase def test_recorded ie = IE.new ie.goto('http://www.google.se/') ie.text_field(:name, 'q').set('testway') ie.button(:name, 'btnG').click ie.link(:url, 'http://www.testway.se/').click end end Recorded by WatirRecorder++
    18. 18. Selenium IDE
    19. 19. Unit Test Framework (Watir & FireWatir) require 'test/unit'   class TestSuiteSimple < Test :: Unit :: TestCase def setup @browser = df_setup end def teardown df_teardown end   def test_01_simple_search @browser . text_field( :name , &quot;q&quot; ) . set( &quot;Testway&quot; ) @browser . button( :name , &quot;btnG&quot; ) . click assert( @browser . link( :href , /www.testway.se/ ) . exists?) @browser . link( :href , /www.testway.se/ ) . click assert_equal( &quot;Testway - Certified Test Specialists&quot; , @browser . title) end end
    20. 20. (Fire)Watir - setup & teardown def df_setup puts &quot; >>>>> #{ to_s () } <<<<< &quot; # output to console puts Time . now . strftime( &quot;%c&quot; ) browser = nil browser = start_browser(“www.google.se”) #(ENV['TEST_URL']) assert_match( /Google/ , browser . title, “The page does not exists&quot; ) return browser end def df_teardown # In case of the failure save a snapshot if (passed? == false) puts &quot; - Test case failed&quot; p = get_project_folder + &quot;/Test_logs/Screenshots/#{to_s()}.jpg&quot; take_screenshot(p) end @browser . close if @browser end
    21. 21. (Fire)Watir– start_browser def start_browser (url) browser = nil count = 0 if ENV [ 'browser' ] == &quot;IE“ require 'watir‘ begin Timeout . timeout 30 do browser = Watir :: IE . start_process(url) browser . wait end rescue Timeout :: Error kill_ie count += 1 puts &quot;Timeout error: #{ count } &quot; sleep 2 retry unless count == 3 end elsif ENV [ 'browser' ] == &quot;FF&quot; # require 'firewatir‘ # browser = FireWatir::Firefox.start(url) end return browser end
    22. 22. How does it look like in Selenium? <ul><li>require &quot;selenium“ </li></ul><ul><li>require &quot;test/unit&quot;   </li></ul><ul><li>class TestSuiteSimple < Test :: Unit :: TestCase </li></ul><ul><li>def setup </li></ul><ul><li>@ selenium = Selenium :: SeleniumDriver . new( &quot;localhost&quot; , 4444 , &quot;*iehta&quot; , &quot;http://www.google.se&quot; , 10000 ) # *iexplore (*iehta is experimental) </li></ul><ul><li>@ selenium . start </li></ul><ul><li>end </li></ul><ul><li>def teardown </li></ul><ul><li>@ selenium . stop </li></ul><ul><li>end </li></ul><ul><li>def test01_simple_search </li></ul><ul><ul><li>@ selenium . open &quot;/“ </li></ul></ul><ul><ul><li>@ selenium . type &quot;q&quot; , &quot;testway“ </li></ul></ul><ul><ul><li>@ selenium . click &quot;btnG“ </li></ul></ul><ul><ul><li>@ selenium . wait_for_page_to_load &quot;30000&quot; assert ( @selenium . is_element_present( &quot;link=Testway - Certified Test Specialists&quot; )) </li></ul></ul><ul><ul><li>@ selenium . click &quot;link=Testway - Certified Test Specialists&quot; </li></ul></ul><ul><ul><li>@ selenium . wait_for_page_to_load &quot;30000“ </li></ul></ul><ul><ul><li>assert_equal ( &quot;Testway - Certified Test Specialists&quot; , @ selenium . get_title ) </li></ul></ul><ul><li>end </li></ul><ul><li>end </li></ul>
    23. 23. (Fire)Watir - Help functions # Better readability with help functions def test_01_simple_search @browser . text_field( :name , &quot;q&quot; ) . should_exist @browser . text_field( :name , &quot;q&quot; ) . set( &quot;Testway&quot; ) @browser . button( :name , &quot;btnG&quot; ) . should_exist @browser . button( :name , &quot;btnG&quot; ) . click @browser . link( :text , &quot;Testway - Certified Test Specialists&quot; ) . should_exist @browser . link( :text , &quot;Testway - Certified Test Specialists&quot; ) . click @browser . should_have_title( &quot;Testway - Certified Test Specialists&quot; ) end module Watir class IE def should_have_title (value) assert(self.respond_to?( &quot;title&quot; ), &quot;This method can not be used&quot; ) assert_equal(value, self.title, &quot;The title is not correct. It is #{ self.title } - it should be #{ value } &quot; ) end def should_exist assert(self.respond_to?( &quot;exists?&quot; ), &quot;This method can not be used&quot; ) assert(self.exists?, &quot;The object does not exist&quot; ) end end end For FireWatir: module FireWatir class Firefox
    24. 24. Selenium - Help functions # Help functions Selenium – some examples module Selenium class SeleniumDriver def should_have_title (value , extra_info = &quot;-&quot; ) assert( self . respond_to?( &quot;get_title&quot; ), &quot;'This method can not be used #{ __FILE__ } : #{ __LINE__ } &quot; ) assert_equal(value, self . get_title, &quot;The title is not correct. It is: #{ self . get_title } - it should be: #{ value } #{ __FILE__ } : #{ __LINE__ } Extra info: #{ extra_info } &quot; ) end def should_not_have_title (value , extra_info = &quot;-&quot; ) assert( self . respond_to?( &quot;get_title&quot; ), &quot;This method can not be used #{ __FILE__ } : #{ __LINE__ } &quot; ) assert_not_equal(value, self . get_title, &quot;The title is not correct. It is: #{ self . get_title } - it should NOT be: #{ value } #{ __FILE__ } : #{ __LINE__ } Extra info: #{ extra_info } &quot; ) end def should_contain_text (value , extra_info = &quot;-&quot; ) assert( self . respond_to?( &quot;is_text_present&quot; ), &quot;This method can not be used #{ __FILE__ } : #{ __LINE__ } &quot; ) assert( self . is_text_present(value), &quot;The page does NOT contain text: - #{ value } #{ __FILE__ } : #{ __LINE__ } Extra info: #{ extra_info } &quot; ) end end end
    25. 25. (Fire)Watir – Win Map def test_01_simple_search google = Google . new( @browser ) google . text_field_search . should_exist google . text_field_search . set( &quot;Testway&quot; ) google . button_search . should_exist google . button_search . click @browser . link( :text , &quot;Testway - Certified Test Specialists&quot; ) . should_exist @browser . link( :text , &quot;Testway - Certified Test Specialists&quot; ) . click @browser . should_have_title( &quot;Testway - Certified Test Specialists&quot; ) end class Google def initialize (browser); @browser = browser ; end def text_field_search ; @browser . text_field( :name , &quot;q&quot; ) ; end def button_search ; @browser . button( :name , &quot;btnG&quot; ) ; end end
    26. 26. Selenium – Win Map <ul><li>def test_01_simple_search </li></ul><ul><ul><li>@selenium . open &quot;/“ </li></ul></ul><ul><ul><li>@selenium . type Google :: text_field_search, &quot;testway” </li></ul></ul><ul><ul><li>@selenium . click Google :: button_search </li></ul></ul><ul><ul><li>@selenium . wait_for_page_to_load &quot;30000“ </li></ul></ul><ul><ul><li>assert( @selenium . is_element_present( &quot;link=Testway - Certified Test Specialists&quot; )) </li></ul></ul><ul><ul><li>@selenium . click &quot;link=Testway - Certified Test Specialists&quot; </li></ul></ul><ul><ul><li>@selenium . wait_for_page_to_load &quot;30000&quot; </li></ul></ul><ul><ul><li>assert_equal( &quot;Testway - Certified Test Specialists&quot; , @selenium . get_title) </li></ul></ul><ul><li>end </li></ul>class Google def self . text_field_search ; &quot;//input[@name='q']“ ; end def self . button_search ; &quot;//input[@type='submit' and @name='btnG']“ ; end end
    27. 27. (Fire)Watir - encapsulating <ul><li>def test_01_simple_search </li></ul><ul><ul><li>google = Google . new( @browser ) </li></ul></ul><ul><ul><li>text_field_set(google . text_field_search, &quot;Testway&quot; ) </li></ul></ul><ul><ul><li>button_click(google . button_search) </li></ul></ul><ul><ul><li>link_click( @browser . link( :text , &quot;Testway - Certified Test Specialists&quot; )) </li></ul></ul><ul><ul><li>@browser . should_have_title( &quot;Testway - Certified Test Specialists&quot; ) </li></ul></ul><ul><li>end </li></ul>
    28. 28. (Fire)Watir – encapsulating 2 <ul><li>module Actions </li></ul><ul><li>def text_field_set (obj_ctrl, txt) </li></ul><ul><ul><li>assert(obj_ctrl . exists?, &quot;Object does not exist - #{ caller } &quot; ) </li></ul></ul><ul><ul><li>assert(obj_ctrl . enabled?, &quot;Object is not enabled - #{ caller </li></ul></ul><ul><ul><li>assert( ! obj_ctrl . readOnly?, &quot;Object is read only - #{ caller } &quot; ) assert(obj_ctrl . respond_to?( &quot;set&quot; ), &quot;Object does not respond to 'set' - #{ caller } &quot; ) </li></ul></ul><ul><ul><li>obj_ctrl . set( &quot; #{ txt } &quot; ) </li></ul></ul><ul><ul><li>assert_equal(obj_ctrl . value, &quot; #{ txt } &quot; , &quot; #{ obj_ctrl . value } is not equal #{ txt } - #{ caller } &quot; ) </li></ul></ul><ul><li>end </li></ul><ul><li>def button_click (obj_ctrl, w = true ) </li></ul><ul><ul><li>assert(obj_ctrl . exists?, &quot;Object does not exist - #{ caller } &quot; ) </li></ul></ul><ul><ul><li>assert(obj_ctrl . enabled?, &quot;Object is not enabled - #{ caller } &quot; ) </li></ul></ul><ul><ul><li>assert(obj_ctrl . respond_to?( &quot;click&quot; ), &quot;Object does not respond to 'click' - #{ caller } &quot; ) </li></ul></ul><ul><ul><li>begin </li></ul></ul><ul><li>if w == true obj_ctrl . click </li></ul><ul><li>else </li></ul><ul><li>obj_ctrl . click_no_wait </li></ul><ul><li>end </li></ul><ul><li>rescue => e </li></ul><ul><li>puts &quot;obj_ctrl.click failure: #{ to_s () } #{ __FILE__ } : #{ __LINE__ } &quot; </li></ul><ul><li>end </li></ul><ul><li>end </li></ul><ul><li>end </li></ul>
    29. 29. Selenium - encapsulating def test_01_simple_search @selenium . open &quot;/&quot; @selenium . text_field_set( Google :: text_field_search, &quot;testway&quot; ) @selenium . button_click( Google :: button_search) @selenium . should_contain_text( &quot;Testway - Certified Test Specialists&quot; ) @selenium . link_click( &quot;link=Testway - Certified Test Specialists&quot; ) @selenium . should_have_title( &quot;Testway - Certified Test Specialists&quot; ) end
    30. 30. Selenium – encapsulating 2 module Selenium class SeleniumDriver require 'test/unit/assertions' include Test :: Unit :: Assertions def text_field_set (locator, txt) assert( self . is_element_present(locator), &quot;Object does not exist&quot; ) assert( self . is_editable(locator), &quot;Object is not enabled &quot; ) assert( self . is_visible(locator), &quot;Object is not visible&quot; ) assert( self . respond_to?( &quot;type&quot; ), &quot;Object does not respond to 'type'&quot; ) assert( self . respond_to?( &quot;get_value&quot; ), &quot;Object does not respond to 'get_value'&quot; ) self . type(locator, txt) end def button_click (locator) assert( self . is_element_present(locator), &quot;Object does not exist&quot; ) assert( self . is_visible(locator), &quot;Object is not visible&quot; ) assert( self . respond_to?( &quot;click&quot; ), &quot;Object does not respond to 'click'&quot; ) self . click(locator) self . wait_for_page_to_load( 20000 ) end end end
    31. 31. (Fire)Watir - domain functions # If you are using often the same set of actions, you could group them def test_02_simple_search_refactored google_search_and_verify( &quot;Testway&quot; , &quot;Testway - Certified Test Specialists&quot; ) google_click_link_and_verify( &quot;Testway - Certified Test Specialists&quot; ) end def google_search_and_verify (srch_text, text_to_find = nil ) text_to_find = srch_text unless text_to_find google = GooglePage . new( @browser ) text_field_set(google . text_field_search, srch_text) button_click(google . button_search) @browser . should_contain_text(text_to_find) end def google_click_link_and_verify (lnk_text, page_title = nil ) page_title = lnk_text unless page_title link_click( @browser . link( :text , lnk_text)) @browser . should_have_title(page_title) end  
    32. 32. Data - driven testing def test_03_data_driven #################################################### # Local variables #################################################### data_array = Array . new path = &quot; #{ ENV [ 'my_project' ] } /test_data/google_search.xls&quot; #################################################### data_array = get_data_array(path) for i in 0. . . data_array . length @browser.goto( www.google.se ) google_search_and_verify(data_array [ i ]. search_text, data_array [ i ]. text_to_find) google_click_link_and_verify(data_array [ i ]. text_to_find, data_array [ i ]. page_title) end end
    33. 33. Test Reports <ul><li>Direct output to a text file </li></ul><ul><li>Download and unpack Test::Unit::Reporter from: </li></ul><ul><li>http ://files.rubyforge.vm.bytemark.co.uk/test-report/ </li></ul><ul><li>Issue the following commands: </li></ul>> ruby simple_test1.rb > simple_test_out.txt > ruby setup.rb config > ruby setup.rb install
    34. 34. Test Reporter Usage require 'test/unit/testsuite' require 'test/unit/ui/reporter' require 'simple_test1_unit_ref' require 'fileutils' # Create a new test suite Watir_Presentation suite = Test :: Unit :: TestSuite . new ( &quot;Watir_Presentation&quot; ) # Add TestSuite_Simple to Watir_Presentation test suite suite << TestSuiteSimple . suite # Create/Open the directory for test results dir = File . join( Dir . pwd, '/Reports/‘ + Time . now . strftime( &quot;%d-%b-%y&quot; )) FileUtils . mkdir_p dir # Run the test suite Test :: Unit :: UI :: Reporter . run(suite, dir, :html)
    35. 35. Test Reporter
    36. 36. Something to think about… <ul><li>Test automation is software development – treat it like that </li></ul><ul><li>Coding standards, naming conventions, source control, documentation, error handling, code review, etc. </li></ul><ul><li>Invest in maintainability from the beginning - it will save your time later on </li></ul><ul><li>Framework, error handling, win mapping, wrapper function etc. </li></ul><ul><li>The aim of the test automation is not to create code but good tests </li></ul><ul><li>The best written code can represent a lousy test – it is worthless then </li></ul><ul><li>Automated tests complement and not replace manual tests - all tests will not be automated </li></ul><ul><li>Automate only tests suitable for automation </li></ul>
    37. 37. Questions ? [email_address]
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×