TestWise: “Run selected steps against the current browser”
An essential test-developing/debugging feature for wise test automation engineers.
In my First Day Setup series, I mentioned that my favourite feature of TestWise (a functional testing IDE) is running selected steps against the current browser. It enables you to run any test steps on a currently open browser and is extremely helpful for writing and debugging tests.
This article is dedicated to when and how to use this helpful feature.
Table of Contents:
· Before Using this Feature
· Using “Run Selected Scripts Against Current Browser”
∘ When to Use this Feature?
Before Using this Feature
To use this feature, first, run a test in TestWise (it could even be a blank test!) and make sure the browser window stays open. If the window closes, you won’t be able to reuse that browser for this function. Check out my dad’s article, Keep the Browser Open after Executing an Individual Test.
In TestWise, keep your window open by not running driver.quit
in the after(:all)
hook function.
One way to do this is to comment this line out. However, remember to uncomment it later!
after(:all) do
# driver.quit
end
Another (recommended) approach is to set the browser to quit only when debugging. This is the default setting in a new TestWise spec file.
after(:all) do
driver.quit unless debugging?
end
Debugging mode is when you run a single test case (not the whole file). This is the icon with the run arrow and boxes (as shown below). The shortcut for this on Mac is Shift + Command + F10.
Using “Run Selected Scripts Against Current Browser”
Now that you have a browser session open, we can continue using this browser to run specific lines of your choice.
Select the lines you want to run and select “Run Selected Scripts Against Current Browser” (or Option + F11).
You should see the lines execute in the browser.
Please note that the execution is from a special test script file, debugging_spec.rb
(auto-created by TestWise). The use_current_browser
step will ‘attach’ to the current existing browser.
Then, you can execute the test steps (in this particular test file) and see the result immediately in the browser. You are free to edit (change/add/remove) the test steps.
Keep in mind that:
- Only uses the most recent open browser for execution.
If you run two or more tests (2+ browsers open), this mode will only use the last executed test’s browser. If it gets closed, you will need to rerun a test case to open another browser before activating this mode. - You can manually use the browser as freely as you want.
There is no ‘lock’ on the browser; it’s not only for TestWise. You can manually click buttons/links and even change websites. And the attached script execution will pick up where you left off.
When to Use this Feature
This feature is most useful when developing and debugging an individual test case.
When writing one automated test (consisting of multiple test steps), you should be running the steps frequently as you go. This way, you can check if the element you selected was correct and if the steps worked as you thought. However, running them every time can be slow. You will be waiting for the browser to start up and wait. That’s a big waste of time and will break the rhythm.
It is more logical to start the browser only once, then run & rerun the steps that need refinement, not starting from the beginning every time. This feature enables just that. This is efficient, and I use this feature immensely when writing tests.
It is also helpful when debugging — sometimes, your script may fail at an action (e.g. clicking a button). And it’s not always clear why. Is it a problem with your script or the webpage? It also can help clarify whether what you’re seeing is a timing error or something is wrong with a particular step.
I highly recommend trying out this TestWise feature. It can easily save hours every day for a real test automation engineer.