Selenium IDE hints - Intro, recording, waiting
So far, Selenium IDE has saved my testing life
so many times that I have decided the following:
1. To dig
deep into this essential tool for testers, in order to understand properly what
it is, what I have been doing with Selenium IDE, how I can take more benefit
from it, etc.
2. To
spread the word about this (sometimes) underrated complement, defending its
honour and helping and encouraging others to dig deep, learn and get inspired
from it.
What is Selenium IDE?
According to the SeleniumHQ (its official
site), Selenium IDE is a Firefox add-on that will do simple record-and-playback of
interactions with the browser. From this definition,
let’s focus into some concepts:
§
IDE: IDE
stands for “Integrated Development Environment”, and this means that we are in
front of an application to help you develop software related utilities.
§
Firefox: Yes,
Selenium IDE is only available for Firefox browser, so it is not going to help
you in cross-browser testing, but it is an invaluable lightweight tool to
automate general browser functional testing.
§
Add-on: a
browser add-on (a.k.a. browser extension) is an
installable enhancement that allows the browser’s user to add or increase the
default browser features. That’s what Selenium IDE offers you, it adds
record-and-playback browser interactions capabilities to your Firefox.
§
Record-and-playback: this
would be better presented as record and/or playback. You
can record or not, but you are interested in playback, because that’s what
really provides you the automation abilities, the playback of...
§
Interactions with the
browser: this is the point, this is what Selenium IDE does
greatly. With this add-on you can record, generate, manage and execute
interactions with the browser, simulating a real user clicking, typing,
highlighting, advancing... in web pages and their content.
So, to sum up this section in plain words, Selenium IDE is a
small complement of your Firefox browser that allows you to simulate a real
browser user actions in web pages. With it, you’ll be able, amongst other
things, to perform some automated functional browser testing.When is Selenium IDE a good choice for automated testing?
With Selenium IDE you can store and organize test cases and test
suites, so it is possible to have an automated suite of suites executed with
it. Selenium IDE is strong (more than you can think of!), yet limited; it is a
great tool for simple test cases and not that suitable for complex ones (with
lots of branches, cases and so on). Also, as I’ve mentioned before, it only
works in Firefox, so if you need a tool to cover more complex cases and/or
working in different browsers, better have a look at Selenium
Webdriver or Watir. There are commercial tools as well that might
satisfy your needs.
Personally, I use it to do some lightweight automation testing,
to repeat some tedious yet simple tasks or tests during an iteration or
project, but without the goal of storing or maintaining this automation; doing
this, the tests can be developed faster and probably in a suboptimal way, but
they become highly cost-effective. Also, Selenium IDE is a terrific
“facilitator” tool for non-automated testing, as it may help you in executing
fastly and robotically some tedious steps that let your web app ready to be
tested, in a certain state or point that’s boring to reach. Automating the path
to reach this point you won’t be tired and upset and you’lll be able to execute
your best testing skills on it
Recording as an easy
start...
The easiest way to start a test case with Selenium IDE is to
perform it manually while having the record button set to “on”; unfortunately,
there are lots of things that will sneak this recording (background events,
implicit waits you perform as a human, things like that). For instance, let’s
record a simple search in a search engine for “Software Testing” and then see
if there appears a link to the Software Testing Wikipedia page in the
results. This is the code I get after recording this in Selenium IDE:
This test can be reproduced without none of the aforementioned
issues, as Selenium IDE recording mode is wise enough to turn my “click”
gesture of the search button into a “clickAndWait” command. The implicit
reference (search for this tab at the IDE console) of this command says...
clickAndWait(locator)
Generated from click(locator)
Arguments:
§
locator - an element
locator
Clicks on a link, button,
checkbox or radio button. If the click action causes a new page to load
(like a link usually does), call waitForPageToLoad.
So, virtually, the previous sample is equivalent to the
following one......where the 30000 is just an arbitrary number of milliseconds
to call a timeout once they’ve passed and the page is not loaded yet. The
“clickAndWait” command uses the default timeout value present at the Options
menu for the IDE, while in “click” + “waitForPageToLoad” we have to specify it
by hand, therefore it can be bigger or smaller than the default.
I can achieve something similar by using the “pause” command
like this:
Running this snippet you’ll see that the test execution ALWAYS
waits 30 seconds (30000 milliseconds), no matter if the page was loaded 29
seconds ago, which sounds really less efficient than the previous versions. The
thing is that we need something to be done just after clicking the button that
assures us that the page (resource, button...) is properly loaded before we
proceed in our checkings, because if we had the following test case......our
test will likely fail executing it at maximum speed, because we are telling
Selenium IDE to verify right after clicking, when it turns out that the
clicking is a trigger that loads a new page, so verifying immediately something
before waiting the page is fully loaded will easily make Selenium IDE verify
something it can’t find already, returning a...
[error] false...message
in the log tab of the IDE’s console while trying to execute the command
“verifyElementPresent”, as when Selenium IDE is executing this command there is
no link to Wikipedia in the page (because it is not loaded completely yet).
No comments:
Post a Comment