Você está na página 1de 8

Selenium tutorial/overview

1. Selenium Introduction
2. Selenium Installation
3. Getting Started/Selenium RC steps
4. Selenium Tips and Quirks/FAQ
5. Extending Selenium
6. Selenium 2(pros/cons)
7. Load testing with selenium
8. Good Resources
9. Alternatives to Selenium

The Selenium-IDE (Integrated Development Environment) is the tool you use to develop your Selenium test
cases. It’s an easy-to-use Firefox plug-in and is generally the most efficient way to develop test cases. It also
contains a context menu that allows you to first select a UI element from the browser’s currently displayed page
and then select from a list of Selenium commands with parameters pre-defined according to the context of the
selected UI element. This is not only a time-saver, but also an excellent way of learning Selenium script syntax.

Selenium, the popular open-source automation test tool for Web-based software, comes in different flavors. This
tutorial series started by introducing Selenium Remote Control (Selenium RC). However using Selenium RC
requires knowledge of special commands, understanding the elements of an HTML page, and a fair amount of
programming. Wouldn't it be nice to be able to record your own actions and convert those to Selenium
commands, or, better yet, to record commands, insert some assertions, and just run the script back as a test,
without all that complex programming?

Selenium IDE is an integrated development environment for performing Selenium tests. Selenium tests can be
written as HTML tables or coded in various languages like C#, PHP, Perl, Python and can be run directly in most
modern browsers.The IDE can help you to record, edit and debug tests. Currently the IDE is only available for
Firefox (as if we developers will use any other) as a addon.

Here is a possible scenario for using Selenium. Imagine you have created a HTML form with about twenty fields
and you have to repeatedly test the form. Filling the form every time can quickly become tedious. With Selenium
you can automate the whole process and run the test as required. In this part we will see how to create a simple
test in Selenium. So let’s get started.

There is just such a tool. It's called Selenium IDE.

A simple script recorded with Selenium IDE


IDE is an acronym for Integrated Development Environment. Using Selenium IDE, instead of having a program
over here talking to a remote controller over here that drives a browser in a third place, the entire application runs
inside the web browser. To do that, Selenium IDE was built as a browser plug-in for FireFox. Let's take a look at
the software in-action, after I have recorded a simple script:

This will all be explained

To continue reading for free, register below or login

Requires Membership to View

To gain access to this and all member only content, please provide the following information:
Become a Member
Email Address:

By submitting your registration information to SearchSoftwareQuality.com you agree to receive email communications from the
TechTarget network of sites, and/or third party content providers that have relationships with TechTarget, based on your topic interests
and activity, including updates on new content, event notifications, new site launches and market research surveys. Please verify all
information and selections above. You may unsubscribe at any time from one or more of the services you have selected by editing your
profile, unsubscribing via email or by contacting us here

• Your use of SearchSoftwareQuality.com is governed by our Terms of Use


• We designed our Privacy Policy to provide you with important disclosures about how we collect and use
your registration and other information. We encourage you to read the Privacy Policy, and to use it to help
make informed decisions.

If you reside outside of the United States, by submitting this registration information you consent to having your
personal data transferred to and processed in the United States.

in more detail below, but I wanted to give you a quick look at what your Selenium RC screen will look like when
we're through. To record this, all I did was start Selenium IDE, type http://techtarget.searchsoftwarequality.com
(enter), and use the site to search for my tutorial on Selenium RC. With the test recorded, I can replay that test by
clicking the green go button. The 'Base URL' for the test is SearchSoftwareQuality.com so we don't see that
mentioned in the open method, but above in the Base URL field. With Web testing, often it can be tricky to obtain
an element's id. However, Selenium is able to capture the ids in the target field as the tool is recording actions
taking place in the Firefox browser.

One thing the test doesn't do (yet) is actually confirm any text on the screen -- it drives the browser, but doesn't
inspect it. We'll talk about that later.

Before we can do that, let's talk about how to install Selenium. Then I'll cover more on how to use it effectively,
and a little bit on how to save, re-use tests, and make test suites with the tool.

Installing Selenium IDE


We'll start by going to the openQA download page, which you can find at http://seleniumhq.org/download and
clicking on the link to download Selenium IDE. That will take us to the Selenium IDE Add-On Installer:

Now click the "Install Now" button to get started, followed by "Restart FireFox."

You should see a note that the new Add-on was installed, and that's it. You can start Selenium IDE by clicking
Tools->Selenium IDE from your Firefox browser.

It's that simple.

Now let's walk through creating that first test together in more detail; you may want to print this page out and
follow along.

Recording an Effective Test

1. Open the IDE through Tools->Selenium IDE.


2. When the window pops up, mouse over the red button on the top right. It should say "Now recording." If
not, click the button to start recording.
3. In your browser, go to www.searchsoftwarequality.com.
4. Look at the title of the web page; the words in the blue bar at the very top-left of the screen.
5. Let's assert that title comes up when we start testing. So click on the white box to add a command:

1.)Then click on the Command textbox and type in "assertTitle" into the command window and "Software
quality management, testing and QA resources - SearchSoftwareQuality.com" (which should be showing
in the Firefox Title Bar) into the Target textbox.
2.)Now go back to the browser, click on the search textbox. Type in "Heusser Selenium RC" and click
search.
3.)This brings us to a search results page. In steps 9 and 10, we'll add in checks for two recent Selenium
articles that I wrote.
4.)Click on the next blank command line in the Command Table. This is necessary in order to add a new
command. Add an assertElementPresent command for "link=Tutorial: Installing and running Selenium-
RC in Perl"
5.)Add a second assertElementPresent command for "link=Getting started with Selenium Remote Control
- Part 2."
6.)Go back to the main browser window and click that first link to go to "Tutorial: Installing and running
Selenium-RC in Perl." The action of clicking the link will both take us to that actual page, and "record"
the event in Selenium IDE, adding it automatically to the test case.

Now we're on a browser page for the first tutorial. Let's make sure at least some actual text from the article
appears. To do that:

7.)In the Selenium IDE window, click on the next blank command line. Then enter the command
"assertTextPresent" and add "Used in conjunction with Selenium's online tutorials" added to the Target
text box.
• If you followed these directions, click the red button to stop recording, and you should have something
like this:

The slash at the top is actually a command to open the 'Base URL,' which we can see at the very top is our
website. This is a sort of shorthand, so that we can skip the http colon slash slash domain-name dance for
every open command. Without the full path, Selenium assumes it is part of the Base URL. In our example,
we typed in SearchSoftwareQuality.com and hit enter, causing that Base URL to be set.

Now that the test is recorded, you can either click one of the green play buttons (we only have
one test right now; the test is the suite) or click at the top of the command list and click the step
in button to run one test at a time. If you get errors, it's likely that you called assertElementPresent when it
should have been assertTextPresent, or you made a typo in the check or command. You can compare your
test to this one to look for differences.

In addition to checking for text and links, Selenium has a host of commands. Most of them, such as clicks,
checks, and selects, can be recorded automatically with the IDE. One popular command is
waitForElementPresent (element_name) which can be especially important when waiting for Javascript
elements to populate. The commands are extensive; this list of common Selenium commands should get
you started.

Also, if you end at a different place than you start, make sure you begin with an "open" command with a
location of "/" and that the base URL is the place to start. If the test misses this for some reason, just add
the command at the bottom and drag it to the top.
Saving Tests, creating and re-suing suites
Sooner or later, you'll want to close your browser, and you'll likely want to get your file back next time
you open it. From Selenium IDE use the File Menu to Save Test Case As and specify a filename. This will
save to your hard drive for next time. Another option is to create a New Test Case and save that. Having
more than one test case open at once shows us the test suite interface. This is just like the test case
interface, except it shows the name of all the test cases loaded at left:

We can now run our tests collectively and save them as a suite. While for smaller apps you may be able to
test the entire application in one suite, you'll likely want to break them up for larger applications. In that
case, I suggest a test for each minor feature and a suite for each major feature, with each suite saved in a
directory. That way, you can test major pieces one at a time. With multiple testers, you can put the entire
system under version control, just like software code, and have multiple people working on tests at the
same time.

This is just a quick introduction, but you can find a great deal of detail in the Selenium IDE
documentation on-line. I've tried to hit the highlights and get you started quickly. Now I could end the
tutorial and ride off into the sunset, but if you'll allow me, I've got a little bit more advice to give.

Beyond Selenium IDE

Once the thrill runs off of working with the IDE, you're faced with a few realities. The tool generally takes
up your whole browser, and while it is faster, it really isn't that much faster than testing by hand. It always
does the same thing, over and over again, and it doesn't have any of the features we look for in a
programming language such as variables, looping and abstraction. So if you've got a technical team
interested in doing some serious automation testing, I generally suggest moving from Selenium IDE to
Selenium Remote Control, which can be programmed. If that tickles your fancy, read the two Selenium
RC tutorials that we searched for in our test case. You have the basics. Now it's time to move to the next
level.

Você também pode gostar