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

Prerequisite:
  1. Visual studio should be installed in machine..
  2. Download “Nunit: from link http://nunit.org/index.php?p=download and install in your machine.
  3. Download selenium-dotnet-2.31.0.zip file from link http://docs.seleniumhq.org/download/ and unzip in your machine.
Step To create new project.

    1. Open Visual studio in your machine.
    2. Go to and click on  File > New > Project.
    3. Select visual C# from left panel and select class library


     4. Enter project name  chose location and click on OK button.
     5. A default class created with named “Class1.cs” under your project         
     6. Rename this class or create new class for your test script.

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

Setup of Ruby and Selenium 2
  1. Download ruby setup file  from url http://rubyinstaller.org/downloads . Install the executable file into your system and set Ruby as Environmental variable into your system.
  2. Open command prompt and check “ruby  -v “ to verify ruby installation and path setup.
  3. After ruby installation run below command for selenium2 installation.
gem install selenium-webdriver

Create First Test Scripts:

Capture your test scenario using selenium Ide. import test script into Ruby/ Test::Unit /Webdriver and save as a .rb file in your machine. I have created below a sample Google search script.

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

Prerequisite:
  1. PHP should be installed and set up path in your machine. 
  2. PHPUnit Should be installed in machine.
  3. Java should be install and setup path in machine.
  4. Selenium2 jar(selenium-server-standalone-2.**.0.jar) file should in your machine.
Procedure & Setup of PHP and PHPUnit

If PHP and PHPunit are not installed in machine. We need to follow to installed them using below steps:
  1. Download PHP exe file from download and install in machine.
  2. Setup PHP path in environment variable if by default not path set. As if I installed in C:\\PHP drive the we need to setup path  “C:\\PHP”
  3. Now we need to install PEAR for this we open command prompt and go to PHP installation directory and run command
php.exe PEAR/go-pear.phar
     4.  After pear installed check version using command “pear  –V” . run below command to update pear.
  pear upgrade pear

TestNg Dependencies

Sometime we need to run test methods in certain order, As we need to run a test method always run after some test method. TestNg provide two ways to accomplish this either with annotation or XML suite.

Dependencies with annotations.

dependsOnMethods or dependsOnGroup attribute are used on @Test annotation to accomplish execution of dependent test.

There are two kinds of dependencies:

TestNG Parametrization: Part-2

If you need some complex parameter or parameter that need to created from java then using testng xml file parameter is not sufficient. For this need to use Data provider to pass values into test method. A data provider is a method of your class which return an array of array of objects. TestNg annotation of this method is @DataProvider.

TestNG Parametrization: Part-1

Parametrization means passing values in Unit test script using TestNG xml file, or using @DataProvider testing annotation

Parametrization using testing xml file:

For this type of parametrization need to declare “@Parameters” annotation in method which needs parameter testing, the value of parameter will be provided by using TestNG suite xml file. Using this we can Test a single unit test for multiple set of values.

How to create TestNG suite file.

TestNG suite means grouping two or more than two classes to execute with a single command.

How to create:
Create some test class as I created below two test class  “FirstTest.java” and “SecondTest.java” java files.

FirstTest.java:

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class FirstTest {
       
        @BeforeClass
        public void beforeClass() {           
           System.out.println("One time executed before first mathod");
        }
         
        @AfterClass
        public void afterClass() {
            System.out.println("One time executed after last method");
        }
                  
        @Test
        public void testFirstMethod() {       
           System.out.println("@Test - executed first test method");
        }
}


Some basic annotation of TestNG

Below are some basic annotation which we use in automation.
 
@BeforeSuite - Execute only one time before all testNg method..
@AfterSuite - Execute only one time after all testNg method.
@BeforeClass - Execute only one time before first test and after @BeforeSuite testNg method.
@AfterClass - Execute only one time after last test and before @AfterSuite testNg method.
@BeforeMethod - Execute before every @Test methods.
@AfterMethod - Execute after every @Test methods.
@Test – TestNG test method.

How to run java test scripts using Grid2

Prerequisites. 
  1. Java should be install and setup path in system.
  2. Eclipse should be configured TestNG plugin 
  3. Download the selenium-server-standalone-version.jar from the below location.
  4. TestNG jar file.
Steps to  create and execute test scripts:

1. Launch Grid 2 console(Hub ) and Nodes using below commands:

    Hub:
       java -jar selenium-server-standalone-2.29.0.jar -host localhost -port 4444 -role hub

    Nodes:
       java -jar selenium-server-standalone-2.29.0.jar -host localhost -port 5555 -role webdriver -hub http://localhost:4444/grid/register -browser browserName=iexplore,platform=XP,version=8

        java -jar selenium-server-standalone-2.29.0.jar -host localhost -port 5556 -role webdriver -hub http://localhost:4444/grid/register -browser browserName=firefox,platform=XP,version=13
       
2. Run test case parallel:  This “WebDriverGrid2Test “ example will be run test case on firefox and  internet explorer on version 8 and 13 respectively.

How to run python webdriver test scripts using Grid2

Prerequisite:
  1. Java and python should be installed and setup path in your machine..
  2. Download xmlrunner.py from below url: http://pypi.python.org/pypi/XmlTestRunner/0.16654
  3. Download and install “setuptools 0.6c11” from below link: http://pypi.python.org/pypi/setuptools
  4. Install selenium 2 in your system using command: > easy_install selenium
  5. Selenium server file should be in machine
Set up and launching Selenium Grid:

      1. Run below command in on your console to launch Grid hub console:
java -jar selenium-server-standalone-2.21.0.jar -host localhost -port 4444 -role hub
       2. Open two console and run below command to launch and register node with Grid hub.
java -jar selenium-server-standalone-2.21.0.jar -host localhost -port 5555 -role webdriver -hub http://localhost:4444/grid/register -browser browserName=firefox,platform=WINDOWS

java -jar selenium-server-standalone-2.21.0.jar -host localhost -port 5556 -role webdriver -hub http://192.168.1.22:4444/grid/register -browser browserName=iexplore,platform=WINDOWS
           Replace local host to system IP of Hob machine. If you want to launch node in different machine.