One thing you can do to make watir-console even more useful is to write a startup script. Here are the steps:
- Create a helper script and put it in one of the Ruby library directories (such as C:\ruby\lib\ruby\1.8). Let's call it helper.rb.
- Create a .irbrc file (just a text file) and store it in \ruby\bin. This is actually a Ruby file, and can have any Ruby commands you want to start up when Ruby starts. For our purposes, your script should 'require' the script you built in step 1.
That's it! Now, helper.rb (and its methods and constants) will be available in watir-console whenever you run it.
"What should I put in helper.rb", you ask? I'm a believer in examples, so here are a few examples of methods I created:
- A 'login()' method to start a browser, go to the login page for my web app and log in. It returns the IE object, so it can be called from watir-console as "instance = login()". This allows you to then access "instance" as the IE instance to be manipulated.
- Now you can run different methods to do different things. For example, my application does queries, so I have a 'new_query()' method that simply navigates to the page where I can create a query. It is accessed by calling 'new_query(instance)' from watir-console.
Thank you for the reminder about watir-console. Bret and Charley covered something like this at a tutorial at Agile 2007, and I promptly forgot about it. Thank you for the example, I am going to try it!
ReplyDeleteno problem lisa...i am sure all this stuff is in the docs somewhere too...but sometimes really cool features for testers can get lost in the great mass of words that is documentation :-).
ReplyDelete