Friday, April 13, 2012

Get complete exception trace as a String

In some cases we want to write the complete exception stackTrace to a file, in that case use below method which will take Throwable object as a input and returns complete stackTrace as a String.

By using below method you can get complete exception stack trace as a String.

public static String stackTraceToString(Throwable e) 
{
  String retValue = null;
  StringWriter sw = null;
  PrintWriter pw = null;
  try {
                  sw = new StringWriter();
                  pw = new PrintWriter(sw);
                  e.printStackTrace(pw);
                retValue = sw.toString();
  } 
               finally 
               {
           try {
                       if(pw != null) { pw.close();}
                       if(sw != null) { sw.close();}
               } 
                       catch (IOException ignore) {
    ignore.printStackTrace();
             }
      }
 return retValue+" \n ";
}

MouseOver method in WebDriver

Use below method for mouseover action in WebDriver

public void mouseOver(WebDriver driver,WebElement element) throws Exception
{
new Actions(driver).moveToElement(element).perform();
}




Thursday, April 12, 2012

How to switch control to pop-up window ?






Switching control to popup



If you want to do any operations in pop-up window you need to switch the control to pop-up window then do all your operations in that and finally close the pop-up window and again select the default (main ) window.


here is WebDriver logic to select Pop-up window


1 . Pop-up window has name/id


     driver.switchTo().window("<window name>");



2. Pop-up window doesn't have name / you don't want to hard code the window name then go for below logic.

Method-1


  • before opening pop-up get the main window handle.
             String mainWindowHandle=driver.getWindowHandle();
  • open the pop-up (click on element which causes open a new window)
             webElement.click();
  • try to get all available open window handles with below command. (the below command returns all window handles as Set)
            Set s = driver.getWindowHandles();
  • from that above set try get newly opened window and switch the control to that (pop-up window handle), as we already know the mainWindowHandle.
          Set s = driver.getWindowHandles();
Iterator ite = s.iterator();
while(ite.hasNext())
            {
String popupHandle=ite.next().toString();
if(!popupHandle.contains(mainWindowHandle))
{
driver.switchTo().window(popupHandle);
}
}
  • Now control is in pop-up window, do all your operations in pop-up and close the pop-up window.
  • Select the default window again.
                 driver.switchTo().window( mainWindowHandle );









Method-2

// get all the window handles before the popup window appears
 Set beforePopup = driver.getWindowHandles();
     
// click the link which creates the popup window
driver.findElement(by).click();
  
// get all the window handles after the popup window appears
Set afterPopup = driver.getWindowHandles();
     
// remove all the handles from before the popup window appears
afterPopup.removeAll(beforePopup);

// there should be only one window handle left
if(afterPopup.size() == 1) {
          driver.switchTo().window((String)afterPopup.toArray()[0]);
 }



Thursday, February 9, 2012

Using Selenium 1.0 features in WebDriver

You can use your favorite features in Selenium RC in WEbDriver as well by using WebDriverBackedSelenium.


WebDriver driver= new FirefoxDriver();
Selenium selenium = new WebDriverBackedSelenium(driver, baseURL);
driver.get(baseURL); 
selenium.windowMaximize(); //selenium-rc method




 Happy coding guys

Sunday, October 16, 2011

Which tests should be automated?


We should perform a careful analysis of the application when deciding which tests warrant automation and which should executed manually.





Here some examples of tests that could be automated.
  • Tests that are executed more than once. By contrast, a test that is executed only once is often not worth automating.

  • Tests that evaluate high-risk conditions. Low-risk factors may not be worth testing by automated means.

  • Tests that are run on a regular basis. Example includes smoke (build verification) tests, regression tests, and test that include many simple and repetitive steps and must be conducted repeatedly.

  • Tests that would be impossible, or prohibitively expensive, to perform manually. For example, during stress and performance testing, during memory leak detection, or path-coverage testing.

  • Tests that have multiple data values for the same actions (data-driven tests).

  • Baseline tests to be run on different configurations.

  • Tests with predictable results.

  • Tests on a system that is some what stable, with functionality, implementation that are not constantly changing.





Divide and Conquer in Software Testing


This is all about testing.

To break down the testing tasks, the following “what,” “when,” “how,” and “who” questions should be answered.

What Should be tested? During the test-planning phase, what to test and what not to test will have been determined as part of the scope of testing.

When should test procedure be developed? Test procedure be developed as soon as requirements are available. (unfortunately we don't have that Test Procedures). Once it has been determined what to test, the sequence of tests must be established. What needs to be tested first? The test planner should get to know the testing priorities, and should become familiar with the build and release schedule. Procedures for testing the high-priority items should be developed first.

How should test procedures be designed? No single testing solution can effectively cover all parts of a system. Test procedures for the different parts of the system must be designed in the manner most appropriate for effectively testing each of those specific parts.
In order to design the appropriate and most effective tests, it is necessary to consider the parts that make up the system and how they are integrated.

Who should develop the tests? Once it has been determined what must be tested, when it is to be tested, and how the test is to be accomplished, it will be easier to decide to whom the various testing tasks should be assigned.

Since user-interface, or black-box, testing does not exhibit all defects, gray-box testing must also be applied.

Keep in mind that black-box and gray-box testing combined are still not sufficient to procedure a quality product. Testing processes, procedures, inspections, and walk-through s, along with unit and integration testing, are all important parts of effective testing. Black-box and gray-box testing alone cannot identify all of the defects in a software program.





Tuesday, October 11, 2011

First post in my personal blog


I'm decided to write personal blog content from today.