I'm trying to refactor one set of Watir scripts into separate files so that it is more like the setup used in the UnitTests and I seem to be having some difficulty figuring out the right order of things. Maybe it's just the choice of my files that's hanging me up, but it's what I'm working with so I'd like to see if I can figure it out. Also, I imagine that there might be a better way of doing this, but this is my first complete set of Ruby/Watir scripts so bear with me if the setup seems inefficient or incorrect in some way. (All feedback appreciated.)
Background:
- I have 4 Performance scripts that walk through the site maps for 4 different apps.
- Each script is currently independent and does the following things:
(a) opens up two files for writing output: one for the performance measurements, and one for a separate progress/status report (used for troubleshooting in case something goes wrong).
(b) walks through each page in the site map and records the (i) page size and (ii) download time.
(c) closes the two files and the web browser.
-> These scripts all work as expected when run individually.
FIRST PROBLEM (with hack workaround):
- The last step above (c) was interesting, because it took me a while to figure out how to close the files as the *last* step in the test run.
- To do this, I put all of the setup and tests into the first class ( e.g. "class TC_BD01") and the 'close open files' step into a second class (e.g. "class TC_BD02"). I couldn't figure out any other way to ensure that this was performed in the correct order. On the downside, I have an extra unwanted Class with an unwanted TestCase that all it does is close some files and close the web browser.
- As an example, here is the output of the test file that helped me work out this line/class/test order problem (the general structure is the same as my real script, except all the code has just been replaced with a simple 'puts' line):
-----
>ruby BD_site_map_tests.rb
** TC_BD01_site_map_walkthru **
Loaded suite BD_site_map_tests
Started
] TC_BD1 > test_a_Public_Pages
]=> TC_BD1 *teardown*
.] TC_BD1 > test_b_First_Time_login
]=> TC_BD1 *teardown*
.] TC_BD1 > test_c_Main_Menu
]=> TC_BD1 *teardown*
.
] TC_BD2 > test_wrap_up
*-*-*-*-*-*-*-*-*-*
.
Finished in 0.0 seconds.
4 tests, 0 assertions, 0 failures, 0 errors
>Exit code: 0
-----
=> So it kind of bugs me that it reports "4 tests" when really there are 3 tests and 1 'wrap_up' routine, but I can live with that (for now) because it works. In the long term I'd like to figure out how to solve this problem with the extra empty test cases.
SECOND PROBLEM (working with the new integrated script suite):
- I stripped out all the constant declarations and custom methods into separate files. (Thanks for the help with this Bret and Sean G.)
- I created a master script file that has all the 'require' and 'include' statements and then calls the individual scripts one at a time.
=> What I've noticed is that Ruby (1) scans through *all* of the scripts, (2) groups all of the [non test case lines] and [test cases] and then (3) runs them in that group order. I think it's really whacked, but that's what I've seen.
- Here's my Script_Order_TestSuite.rb file:
-----
require 'common'
# The Tests:
puts '-= Wrapper A - BEFORE =-'
require 'BD_shell_tests'
puts '-= Wrapper A - AFTER =-'
puts ''
puts '-= Wrapper B - BEFORE =-'
require 'SD_shell_tests'
puts '-= Wrapper B - AFTER =-'
puts ''
# End
-----
And here's the output:
-----
>ruby Script_Order_TestSuite.rb
-= Wrapper A - BEFORE =-
** TC_BD01_site_map_walkthru **
-= Wrapper A - AFTER =-
-= Wrapper B - BEFORE =-
** TC_SD01_site_map_walkthru **
-= Wrapper B - AFTER =-
Loaded suite Script_Order_TestSuite
Started
] TC_BD1 > test_a_Public_Pages
]=> TC_BD1 *teardown*
.] TC_BD1 > test_b_First_Time_login
]=> TC_BD1 *teardown*
.] TC_BD1 > test_c_Main_Menu
]=> TC_BD1 *teardown*
.
] TC_BD2 > test_wrap_up
*-*-*-*-*-*-*-*-*-*
.] TC_SD1 > test_a_Public_Pages
]=> TC_SD1 *teardown*
.] TC_SD1 > test_b_First_Time_login
]=> TC_SD1 *teardown*
.] TC_SD1 > test_c_Main_Menu
]=> TC_SD1 *teardown*
.] TC_SD1 > test_d_Admin_Pages
]=> TC_SD1 *teardown*
.
] TC_SD2 > test_wrap_up
*-*-*-*-*-*-*-*-*-*
.
Finished in 0.0 seconds.
9 tests, 0 assertions, 0 failures, 0 errors
>Exit code: 0
-----
=> What I was *expecting* was that the master script would do the "Wrapper # - Before" stuff *prior* to running the test cases in the called script, and *then* perform the "Wrapper # - After" stuff when that called script was complete. But that's not what happens.
MY QUESTION(S):
- Given : Ruby will always pool *all* the TestCases together and run them as a set/suite in ascending order by class and then by TestCase. So I need to rethink how the output files are opened and closed, as well as how the browsers are opened and closed.
Does anyone have any suggestions as to how I can properly close open files after each test script/suite run? (The reason I did this in each script was so that I could record the script start and end times. I think I may need to replace this with variables now if I can't write the output at the actual script start and stop times.)
Or should I just open all the output files at the start and then close them at the very end of the master script completion? If so, what sort of module/class/whatever structure should I use in my scripts to ensure that certain steps are run *first* and *last* and hopefully without adding additional empty Classes and TestCases.
(Aside: I ordered the 2nd edition Pickaxe book and am still waiting for it to arrive, so I can't look that up for reference just yet. If applicable, feel free to reference certain sections within it and I will look it up when I get it.)
I just can't figure out how to run commands *after* the "suite" of test cases is complete. Everything I add always runs *prior* to the suite of test cases. I think that both problems above might share a common solution, but I just don't know what that could be. Thanks in advance for any useful suggestions and advice.
Cheers. Paul.
_______________________________________________ Wtr-general mailing list [email protected] http://rubyforge.org/mailman/listinfo/wtr-general
