Selenium is a web Automation tool which can be used to automate web browsers across many browsers and operating systems.
It has four components.
1.Selenium
Integrated Development Environment (IDE)
2.Selenium
Remote Control (RC)
3.WebDriver
4.Selenium
Grid
Here we
will discuss about Selenium Webdriver
which is the current version of Selenium.
Web driver
is basically that API which we can use programmatically to control a browser.Using
Webdriver we can make powerful tests because WebDriver allows us to use a programming
language of our choice in designing our tests.Following programming languages are supported by WebDriver.
# Java
# .Net
#PHP
#Python
#Ruby
Selenium WebDriver can process multilingual commands (sent
via Selenese or the Client API) and forwards them directly to the web browser.
Webdriver has a built-in implementation of the Firefox driver. For other
browsers, you need to plug-in their browser specific drivers to communicate and
run the tests.
So here’s a
picture of the architecture of Selenium Webdriver.
At the top
level there are some bindings and these are language level bindings. These
bindings are just implementations in the various languages that we can use to
do our automation. So we have a common API that we can use for Selenium that
has a common set of commands and we have various bindings for the different
languages. These bindings communicate across a common API,this WebDriver API
communicate with browsers eventually. This API allows us to have some drivers
that interpret commands that are sent across the API. Each one of these drivers
knows how to drive the browser that is corresponds to. So the IE driver knows
how to use low level details of Internet Explorer and drive it to do things
like clicking button, going into pages, getting data from the browser itself, the
same thing for Firefox, Chrome and so on.
Suppose we
write our test in C# language and we use common selenium API and that C#
binding is going to be sending command across this common WebDriver API.Now on
the other end is going to be listening a driver which interpret those commands
and execute them on the actual browser and then it returns the result backup
using the WebDriver API.
Finding
Elements
The first
thing we need to do is to find the elements on particular page so we can
reference them.Some different finders are listed below and we can use anyone of
this finders to find an element.
1.ClassName-ClassName
is just a CssClassName.If we have an element that has a unique ClassName,we can
use that.And if there were multiple
matches,we can index that so we can find the first one or the second one
2.ID-Id is
most useful and absolute one.If we have an Id for an element on the page we can
use that.This is one of the preferred methods.
3.Name-We
can use the name property of an HTML and it’s just like Id.
4.TagName-TagName
is pretty general case.This is the actual name of the tag.
5.CssSelector-We
can use a CssSelector and this is one of the more advance ways.We can basically
use any Css that we would use to identify an element when we created Css.
6.LinkText-LinkText
is useful one when we are trying to get a link,we can actually just use the
real text of that link
7.PartialLinkText-The
PartialLinkText is part of that LinkText,so we can do a partial match on there.
8.Xpath-XPath
is one of the most advanced one.This is often what we are going to turn to when
none of the other ways work.And we can almost always use some kind of XPath
expression to get to a particular element that you want on a page.
Definitely
when we are trying to find element on pages,we want to use the most clear one
as possible and Id is most absolute and also very clear.But in many cases we have
to resort to different ones especially if we don’t have control over that
page,if we are testing something that is existing and we can’t modify those
pages.
IWebElements
All of the
elements that exists on a page will basically be accessed by IWebElement.IWebElement
is designed in such a way that it will let us call the methods that we should
be able to call on those particular work elements.
Here are
some methods on IWebElements
1.Clear
2.Click
3.FindElement
4.FindElements
5.GetAttribute
6.GetCssValue
7.Sendkeys
8.Submit
Properties
on IWebElement
1.Displayed
2.Enabled
3.Location
4.Selected
5.Size
6.TagName
7.Text
Verification
In
Selenium we can verify some text or something on a page.There is two basic
things we can do.One is assert.An assert basically checks to make sure
something is true.If an assert fails,the test stops because an assert says ‘this
needs to be true in order for me to continue’. The verify actually checks some
statement and the test can still continue past that.We can put multiple
verification steps in and if it fails,it will log that failure but it will keep
going on so we might be able to check multiple things.So the easy way to
remember this is,if an assert fails that test has failed and its really an error
and if a verify fails,then probably its actually a failing test and then
probably it’s actually a failing test case and there might be multiple
verification that could fail.So only one assert value but multiple verify
failures are allowed.
Comments
Post a Comment