-
Notifications
You must be signed in to change notification settings - Fork 7
Getting Started
After following the steps in Installation and Setup, you can start writing tests with bewildr.
Probably the first thing you’ll want to do is to start your app and wait for it to be ready to interact with. Here’s how to do that with bewildr:
my_app, main_window = Bewildr::Application.start_app_and_wait_for_window("c:\myApp.exe", "My App 1.0")
You’ll notice that with one line you can start your app and wait for a window to be displayed – the first argument is the path to your exe, the second argument is the title of the window you want to wait for. You can make this more robust by substituting a regex for the string when specifying the window title… the following example does exactly the same thing as above but will allow the test to keep working when the app version number changes:
my_app, main_window = Bewildr::Application.start_app_and_wait_for_window("c:\myApp.exe", /My App [0-9.]+/)
Waiting for the window to appear may not be enough… you may also need to wait for an object to appear in the window before your app is ready for interaction. Eg: you may have username and password fields that only appear after a second or two. Bewildr allows you to wait for them to appear before doing anything else. Here’s an example:
main_window.wait_for_existence_of(:id => "username_field")
…or…
main_window.wait_for(:id => "username_field")
The above line will cause your script to wait (up to 30s) for an element whose automation id is “username_field” to appear (take a look at Using UI Spy to see where to get those values from). There is a matching method called wait_for_non_existence_of
which does the opposite! Note that you can call these methods on any object, not just windows.
After waiting for a second or so, your username field has appeared. You can now do stuff with it. Here’s how to get a reference to the object:
username_field = main_window.get(:id => "username_field")
The wait_for
method also returns the object once it has appeared, so you could do the same as the above with:
username_field = main_window.wait_for(:id => "username_field")
The following line will set the value of the username field:
username_field.text = "bob"
If you want to select the value of a combo box, do the following:
main_window.get(:id => "combo1").select("MasterCard")
The above line will find the combo box and select the “MasterCard” option. For more examples of methods available on different object types, see the API summary.
Now that you’ve interacted with your app and performed an action whose result you want to test, you can now do just that. If you’re using bewildr in a cucumber/rspec script, you can write some very idiomatic test code. Here are some example tests:
username_field.should exist
username_field.text.should match("bob")
main_window.get(:id=> "login_button").should be_enabled
main_window.should be_open
main_window.get(:id => "combo1").selected.name.should match("MasterCard")
main_window.get(:id => "welcome_message").should be_visible