Tuesday, September 21, 2010

Test Automation for ExtJS User Interface using Selenium

Test Automation of an application that has an ExtJS user interface can be tricky, because of randomly-generated default element IDs. The firm I am working for has ExtJS User Interface and Automation of UI Testing was about to drop because of randomly-generated element IDs. Unfortunately almost all the elements have the default random generated IDs and very few elements are overridden to get Custom set IDs. I managed to solve this issue.

Why is it difficult to Automate? 

To interact with DOM elements, Selenium Commands should specify the target elements using their xpaths.
click //input[@value='Google Search' and @type='button']
To determine the xpath we can use tools like xpath add-on for Firefox or record and get the xpath from Selenium IDE. But the biggest challenge here with ExtJS is this xpath changes every time page reloads as element IDs are randomly generated by default.

So the xpath generated using above mentioned ways will give some thing like
//div[@id='ext-gen77']/div[12]/table/tbody/tr/td[4]/div
This xpath will get changed every time you reload the page. So if you try to run the test it gives
[error] Element //div[@id='ext-gen77']/div[12]/table/tbody/tr/td[4]/div not found

How did I solve this?

To solve this Problem we need Firefox Browser with Firebug, Selenium IDE Add-On installed.

Record the Test Case using Selenium IDE


Open your Application UI which is developed in ExtJS. Right click on some element like Edit Button and say "Inspect Element"



Replace xpath which got recorded with xpath=//button[text()='edit'] because every time the screen gets reloaded, this xpath changes as Element ID is getting generated randomly. This xpath is determined by Tag name which is "button" and value of tag is "edit". 





Few times you may need to use class like xpath=//span[@class='x-menu-item']. This xpath is determined by Tag name which is "span" and value of class is "x-menu-itmt". 

Wednesday, September 1, 2010

First Generation - Need for Automation Testing

Before discussing any thing about Automation we should make sure that we are not having a wrong notion of
Automation is the replacement for Manual Testing   
Pain Points in Manual Testing
  1. Remember and Re-run:
    Regression Testing will be increasing difficult due to hard to duplicate circumstances, seemingly unrelated features that may have been inadvertently broken due to the modification. 
    Also remembering every unusual test case from the previous release's testing and executing with high precision for the new release is a daunting task.

  2. Spirit of Agile is lost:
    Developers waiting for QA for a day to know if there are any blockers in the given build. This happens if there is any issue in the last step of a work flow and as manual testing takes a day to complete Smoke.

  3. Repetitive means boring:
    Repeating test case execution in different environments induces human errors like overlooking details, etc. and losing sight on obvious defects.

  4. Out of time:
    Sequential execution of Test Cases on different environments is eating up the time.
Good Home work

Before automating, Test Cases should be documented, categorized and prioritized.

What should we automate?
  1. To run a set of tests repeatedly, automation is need of the hour 
  2. It gives you the ability to run automation against code that frequently changes to catch regressions in a timely manner
  3. To execute test cases on different OS platforms and on different browsers. 
  4. Parallel execution of automated tests can save a lot of time which can be used to test other critical features.
What should we test manually?
  1. Test Cases executed very few times or test cases which are difficult to automate should be tested manually.
  2. It allows the tester to perform more ad-hoc testing. 
  3. If the tools have any limitations, those tests are manual.
  4. If return on investment on automation is low as in some cases the cost of setting up and supporting the test cases, the automation framework, and the system that runs the test cases is very less.
Criteria for automating

Automating a Test Scenario yields better ROI practically in following conditions (8 out of 54 conditions)

ImportanceCost to AutomateTechnical FeasibilityRepeatabilityTest Mode
HighLowYesHighAutomation
HighLowYesMediumAutomation
HighMediumYesHighAutomation
HighMediumYesMediumAutomation
MediumLowYesHighAutomation
MediumLowYesMediumAutomation
MediumMediumYesHighAutomation
MediumMediumYesMediumAutomation