2012-11-30

How to manage browsers in Selenium WebDriver



In this article we are going to see the functions for controlling a web browser
I am using C# code(JAVA will given later on) with dot net web driver.

-Maximizing Browser :
driver.Manage().Window.Maximize();

-Keep browser to specific position of the screen :
driver.Manage().Window.Position = new System.Drawing.Point(10,5);

In here (x,y)=(10,5)(distance from left upper corner)

-Keep browser in fixed size resolution :  
driver.Manage().Window.Size = new System.Drawing.Size(640,480);

In here 640 is width and 480 is height.

-Open an URL in browser’s current tab:
driver.Navigate().GoToUrl("Site URL");

-Open Previous URL in browser’s current tab from the history (like as back button of the browser) :

driver.Navigate().Back();

-Open Next URL in browser’s current tab from the history (like as Next button of the browser):

driver.Navigate().Forward();
- Refresh current page
driver.Navigate().Refresh();
  
-To start Firefox browser with specific profile( i.e.- Tester creates new profile or use default profile to test for default settings and initiations.) 
private static FirefoxProfile myprofile = new FirefoxProfile("path of the profile directory");
private IWebDriver driver = new FirefoxDriver(myprofile);
In my case the path was @"C:\Users\shantonu\AppData\Local\Mozilla\Firefox\Profiles"

-To get  the source of the page last loaded by the browser
driver.PageSource
Note :  This will give page source string. We can compare with tested html.



These are some mostly use functions. I will add more incrementally

... To be continued...

2012-11-29

Thinking in Selenium WebDriver way for testing

In this following article we are going to learn the basic Test Strategy(the way) to test a web site element using selenium web driver.
First , we need to know what selenium web driver does. Selenium web driver fully controls the a browser , get the web elements, get data, get all the actions. Selenium web driver is used for functional test automation (mostly data validation). It also provides consistency among different browsers. Web Driver uses a different underlying framework from Selenium’s javascript Selenium-Core. It also provides an alternative API with functionality not supported in Selenium-RC. WebDriver does not depend on a javascript core embedded within the browser, therefore it is able to avoid some long-running Selenium limitations.
Before starting, we have to determine what to test, what to automate.
A web site may have different type of elements(details in my previous post).
For a UI web element when we will attempt to test we need to think about the scopes by which we can see the element is full functional.
For that if we check
-An element is present in a proper place on the page
-A text is present on the page(with proper style).
OR both -A text is at a specific place on the page

-The element is rendered properly in popular browsers.
-The element is Image(if it has) is proper size as well as position
-The HTML is ok
-The backed functionality is ok.
If a text or an image is present on a page to any location, we can easily check that by verification (when contents are frequently changing). If contents ate fixed, we can use assert for specificity.
For Image specificity, we will use Xpath for all example, as it is most useful and commonly used. In Xpath, we don’t have to have a suitable id or name attribute for the element you wish to locate. We can use XPath to either locate the element in absolute terms (not advised), or relative to an element that does have an id or name attribute. XPath locators can also be used to specify elements via attributes other than id and name.
(Note : XPath is the language used for locating nodes in an XML document, we will post a different post on describing XPath)
For better understanding, lets say, we need to check for a combo UI element. We may think in following way,
-Is the combo is ok to see( people can click & see the items).
-Is all elements are listed properly( element data and order)
-Is any position element is selectable
-After selection, can user gets the data to work with
-Is the CSS is ok for the particular styled combo.
-Is the combo Name is proper
-Is the combo position is correct.
-If the combo items are coming from database, is that the data collection ok.
-if Ajax/JavaScript loads items, are they are ok
-If items comes from external source, the time that needed for loading the items is ok
-If there is any service associated with the elements, are they are coming in proper way.
This is just an example to way of thinking in web driver way. Incrementally I will provide that way for all popular web elements.

What are the major web elements?

2012-11-28

Basic Functions in Selenium IDE

In this following article, we are going to learn some basic commands for working with web elements.From my previous posts, we know how to have setup and have a basic recording technique in selenium IDE.
In here we will discuss about popular functions of Selenium IDE and Selenium Web driver.
Popular functions are :
open : It is used for opening a URL.
Click : It performs a click operation
clickAndWait : It performs a click operation and waits to load
verifyTitle : verifies an expected page title. We use it for checking that the browser is displaying the expected page
assertTitle : It will check the title by compare.
Note: We may be confusion, why assert is differ from verify. Mainly verify used for running the test cases though they might fail, but assert used mainly for stopping the test case on failed condition.(we will see in the example)
verifyTextPresent : verifies expected text is somewhere on the full page.
verifyElementPresent : verifies an expected UI element(elements are described below), as defined by its HTML tag, is present on the page.
verifyText : verifies expected text and its corresponding HTML tag are present on the page.
verifyTable : verifies a table’s expected contents(with html).
waitForPageToLoad (clickAndWait) :This is not actually using for test purpose. Mostly it is used to keep wait for execution (wait for new page loading).
waitForElementPresent : wait for execution until an expected UI element, (HTML tag), is present on the page.

When we start selenium IDE in Firefox, we get those while right clicking mouse or, In the command selection combo in Selenium IDE.

2012-11-13

Testing Web Service(SOAP/XML-RPC) using JMete

 
In this article, we are going to see a very simple web service testing procedure using JMeter.
Scenario : We are going to test a web service where the service provide us data . To be specific, the service link is http://www.webservicex.net/periodictable.asmx, the Data action link http://www.webservicex.net/periodictable.asmx?op=GetAtoms. The functionality of the service is to provide atom names in tabular format. As we are testing the data service, we can not see the HTML table, but if we can get the data, that will solve the purpose of Testing data service. 
So, if we follow those steps, we can see a very simple test for web services.

Step 1. Run JMeter(jmeter.bat) from stored location “apache-jmeter-2.8\bin”

Step 2. Create a Thread Group( right click test plan –>Add –> Thread Group) and rename as SOAPThread(I am using this name).

Step 3 : Put Number of Threads(User) as 20( I am using ) and Ramp-Up Period as 2( I am using)

Step 4. Save the Thread Group. 

Step 5 . Add a Sampler “SOAP/XML-RPC Request” under your thread group
 

Step 6. Add "http://www.webservicex.net/periodictable.asmx" as the URL and "http://www.webserviceX.NET/GetAtoms" as the Send SoapAction
 

Step 7 . Add This following request as “SOAP/XML-RPC Data”(link or Drive)
 

So, there might be a question , where I get the this XML code. It’s simple, from the service link (http://www.webservicex.net/periodictable.asmx) , you will get the GetAtoms function. 
 
If you click GetAtoms , then you will get the function definition of different  XML format(http://www.webservicex.net/periodictable.asmx?op=GetAtoms). I use SOAP 1.1 format
 

Step 8. Add Listener to your thread group(I have added view result tree, view result in table)
 

Step 9 . Now, Run the Thread Group from Menu. 
Its done. We have make and run the service test using jmeter, lets observe the results.
Here is the Request of a sample under tree listener.
 

This is the response data( the tabular format atom names) [Note : we don’t need to check the format as we are not checking the font end. If the data is present, that is ok.
 
Here is table results.
 
I am inspired by this post.….. Thanks …. :)

We can do the same test using WebService(SOAP) Request which is another type of sampler. I am adding the screenshot in Google drive. This is more smarter than SOAP/XML-RPC Request. But, a little bit slower.