Automating web-app testing for beginners

Automating the process of testing is, using a testing tool which will automatically perform tasks for the tester, tester only has to execute a set of tests using the tool and it tests those without the need of manual intervention. For a newbie this won’t make sense so some basic question & answers below will make things clear.
An obvious question that anyone would have when automation is discussed, is;

Why we need to automate an application?
The answer to it is “Automation is an assistant of a Manual tester to give extra time to think about new sequences rather than checking the routine of already developed sequences by them are working or not.”

So never an automation tool can replace a manual tester until the product is dead. Manual testing is tedious and monotonous in case of regression testing, to overcome this, using automation for regression is a good option.

Next comes,

What needs to be automated?

Before we start automation process we should prepare a list for things which has to be automated like below:
1. Links
2. Elements
3. Functions
All the above mentioned items will have some following sub divisions
Links:
a. Inner Link
b. Outer Link
Elements:
a. Visible Elements
b. Hidden Elements.
Functions:
a. Positive Case
b. Negative Case
c. Exceptional Case
Apart from all the above we can automate the bugs to check for not reproducing again.

There are many proprietary and open source tools available for automation, but we have to choose the right automation tool to implement.

How to select a tool?
Automation tool selection criteria:

  1. Do we need to automate standalone application or client/server application or both?
  2. Do we have the technical persons to train the resource or need any expert from out side.
  3. Is it feasible to invest in the tool.
  4. Is our existing testing resources capable of adopting the new technology?
  5. How is the technical support available for the tool
  6. Complexity of using the tool.

For Client/Server Application Selenium is a good choice for various reasons like
a. It is Free
b. It is Compatible for many languages so one doesn’t need a different language expert to implement, any language that it supports can be used.
c. It is compatible on different browsers and OS (Selenium RC and Webdriver)
d. Its easily maintainable during frequent integration.

Selenium is a UA or GUI testing tool that can be used to automate web applications without worrying about browser and OS compatibility since Selenium RC and Selenium Webdriver supports almost all the browsers along with the OS the browsers are compatible with. UA testing i.e. User Acceptance testing is a test conducted to determine if the requirements of a specification are met. UA tests only test the generated output, they cannot be a replacement for unit testing. Selenium has 4 components viz. Selenium IDE, Selenium RC(remote control) a.k.a Selenium 1, Selenium Web-driver a.k.a Selenium 2 and Selenium Grid.
Selenium IDE is a simple record and playback tool that comes in as an add-on in Mozilla Firefox, for a rookie this is a great tool to start off with automation.

To start off with Selenium, in this blog we will look into Selenium IDE and other components would be seen in next part of this blog.

Note:Selenium IDE can be used to build the test cases in Mozilla Firefox only.

You Can Download Selenium IDE from Link :- http://seleniumhq.org/download/

Install the downloaded file and restart the browser

selenium_1

Selenium IDE works only on Mozilla, you can use this for record, play-back and language conversion

How to create a test in selenium IDE:

  1. Open/browse the site for which you want to prepare a test case.
  2. Start Selenium IDE from Firefox Tools > Selenium IDE
  3. Perform your actions, by default recording is on
  4. Click red button to stop recording

To run your test click ‘Play Current test case’

Selenium IDE is good to use for test cases or scenarios which are not complex. Recorded actions are seen in a tabular form in the IDE window. Actions can be manipulated by many commands provided in the IDE which are simple to understand and use.

selenium_ide_1

Selenium IDE window after recording is performed

How does IDE make the process of automation easy for a beginner?

    1. IDE provides many commands which can be used for various operations.

selenium_ide_2

  1. Tester can insert commands for certain operations, for this obtaining the attribute or target is easy, just a click of button can do it for you.Click Select – go to the web page under test – click the element whose identifier is not known

selenium_ide_3

 

Knowing Selenium IDE basics are important in order to use Selenium RC or Selenium Webdriver, so we take an overview of the things that we would require in future.

Assertions and Validations:
There are two mechanism for validating elements that are on the application under test using Selenium IDE. In order to understand what actually the validation means,  go through the below examples:
Examples of Validations:

  • Example1: To check whether the UI element exists or not on the Application. If the automation tool finds that the element is found on the application it results PASS else it will result FAIL as output.
  • Example2: To check whether the hidden UI element is really hidden. If the automation tool finds that this element is not hidden it results FAIL else it will result PASS.

Two mechanism for validating elements in Selenium IDE:

  1. Assert – This allows the test to check whether the element is on the page. If it is not available then the test will stop execution at the step that failed.
  2. Verify – This allows the test to check whether the element is on the page. If it is not available then the test will fail the step and carry on execution of the remaining steps.

There are number of assert and verify commands available depending upon the property that is being tested for. Right click any element on web page to see all the available commands, assertions and verifications.

Locating elements on web pages:
Element Locators tell Selenium which HTML element a command refers to.
Following are the Object Identifiers or Element Locators that selenium allows:
Identifying an UI element on the application screen is an important feature for any automation tool. Locators allows the Selenium Automation tool to find UI elements on a page that can be used in automation tests.
i.e. The Selenium Tool uses Locators to find and match the elements on your page that it needs to interact with while running the automation scripts.

Selenium uses different types of locators to identify the UI elements on the page.

Following is the list of locators based on the priority and recommendations to use:

1. ID
2. Name
3. Link
4. CSS
5. XPath
6. DOM
7. UI-element

i.e. You have to follow the below steps while finding the Locator for the selected UI element:

  1. First we’ve to find out if there is any locator which can locate the UI element by ID else you have to go to the next step
  2. Find out if there is any locator which can locate the UI element by Name else you have to go to the next step
  3. Find out if there is any locator which can locate the UI element by Link else you have to go to the next step
  4. Find out if there is any locator which can locate the UI element by CSS else you have to go to the next step
  5. Find out if there is any locator which can locate the UI element by XPath else you have to go to the next step
  6. Find out if there is any locator which can locate the UI element by DOM else you have to go to the next step
  7. Find out if there is any locator which can locate the UI element by UI-element

 

Why there are different types of locators instead of having only one kind of locator to identify the UI elements ?

While building the application code, it is seen as a good practice to make sure that every element you need to interact with has an ID attribute and a Name attribute. Unfortunately, this best practice is difficult to implement for the UI elements which dynamically change. This is the reason for having different types of locators instead of having only the ID locator to identify the elements.

Also note, Selenium records script in HTML format but it can be converted in any other language that you are comfortable with like Ruby, java, C# etc. Follow these steps to change the format for viewing — click on Selenium IDE -> Options Menu  -> Format -> Java/Ruby anything desired.
Remember to switch back to HTML in order to continue recording. Recorded script can also be exported to desired language from — File > Export Test case as. This helps in understanding the commands in other languages that are equivalent to HTML in the recording.

We shall see more about Selenium components in coming blogs which would be continuation of this.

Until then….Stay tuned 🙂