Start with Python WebDriver - Procedure to create first test script for the beginners

Prerequisite:

   1. Python should be installed and set up path in your machine.Download Python from here “ClickHere
   2. Install easy_install using code from link "Click to download" .Just copy code from url and past in a new      created python file like “setup.py”
  3. Put “setup.py” file in where python installed and run “setup.py” file as below command
      >python setup.py
  4. After successfully execution a Scripts folder created under Pyhon installed directory. setup “Script”    folder path in your machine.
  5. Install selenium 2 in your system using command: > easy_install selenium

How to Set up and launching Selenium Grid?

Download selenium latest jar file from Webdriver

Launching Hub:

Open command prompt and got to your selenium server jar file and run command:

java -jar selenium-server-standalone-2.21.0.jar -host localhost -port 4444 -role hub
screen should be displayed like below.


How to search image (locator) using sikuli

Some time we are getting that image are not displayed on screen which is captured by sikuli at run time.

Such as we open a www.google.com on browser search a text like "testing" and click on searched button we observed that we need to scroll down to click on next button which is at footer. If I used direct sikuli click command to click on next button we will get exception because image not visible on page. I am using below approach to click on next button

Start with Java Webdriver - Procedure to create first test script for the beginners

Prerequisites:
  1. Download Selenium2 jar file from http://seleniumhq.org/download/.
  2. Download TestNG jar file from http://testng.org/doc/download.html
  3. Download and Install JDK and setup java path 
  4. Download Eclipse IDE from http://www.eclipse.org/downloads/
  5. Install TestNG plugin in downloaded eclipse
  6. Firefox should be install with selenium IDE plugin.

Road To - TestNG Installation in eclipse

1. Open eclipse.
2. Goto Help>>Install New Software and click, screen should be display as below:.

Junit Test Suite

Test Suite means combined multiple test cases . when I run test suite all test case associated with suite will execute. In Junit we will create test suite with two ways Test Runner class or using annotation  @RnWith and @Suite, here is a example for both type. I have created two Junit test case “JunitTest1.java” and “JunitTest2.java”

package com.test;

import org.junit.*;

public class JunitTest1 {

    @BeforeClass
    public static void beforeClassAnnotation() {        
      System.out.println("@BeforeClass - for junit class 1");
    }

    @AfterClass
    public static void afterClassAnnotation() {       
      System.out.println("@AfterClass - for junit class 1");
    }  

    @Test
    public void testAnnotation() {       
        System.out.println("@Test - first class test method");
    }    
}


JUnit Test Template

In this topic I will explain the basic Junit framework template

package com.test;

import org.junit.*;

public class JunitTemplate {

    @BeforeClass
    public static void beforeClassAnnotation() {        
        System.out.println("@BeforeClass - execute one time before any method");
    }

    @AfterClass
    public static void afterClassAnnotation() {       
        System.out.println("@AfterClass - execute one time after last method");
    }

    @Before
    public void beforeAnnotation() {       
        System.out.println("@Before - execute before every method");
    }

    @After
    public void afterAnnotation() {      
        System.out.println("@After - execute after every method");
    }

    @Test
    public void testAnnotation() {       
        System.out.println("@Test - first test method");
    }

    @Test
    public void testAnnotation1() {       
        System.out.println("@Test - second test method");
    }
}

After execution above test execution log generated as below:

@BeforeClass - execute one time before any method
@Before - execute before every method
@Test - second test method
@After - execute after every method
@Before - execute before every method
@Test - first test method
@After - execute after every method
@AfterClass - execute one time after last method     

Junit testing framework

Junit is a unit test framework for implementing testing in java. However it is suitable for unit testing but for integration testing you should use TestNG framework instead of it.

Why use a testing framework?

Using a testing framework is beneficial because it forces you to explicitly declare the expected results of specific program execution routes. When debugging it is possible to write a test which expresses the result you are trying to achieve and then debug until the test comes out positive. By having a set of tests that test all the core components of the project it is possible to modify specific areas of the project and immediately see the effect the modifications have on the other areas by the results of the test, hence, side-effects can be quickly realized.
JUnit promotes the idea of first testing then coding, in that it is possible to setup test data for a unit which defines what the expected output is and then code until the tests pass. It is believed by some that this practice of "test a little, code a little, test a little, code a little..." increases programmer productivity and stability of program code whilst reducing programmer stress and the time spent debugging

TestNG vs Junit 4

Junit 4  and TestNG are similar on surface where as Junit 4 is designed for unit test. TestNg is high label testing it specially use very large and complex test suite.TestNg has some feature which are not in Junit 4.
Below are compression of TestNG and Junit 4 feature