Wednesday 19 November 2014

To use FitNesse for testing .NET code with selenium RC and open http://www.gmail.com

Pre-requirements:
1. Java VM 6 to support FitNesse. Download and install from http://java.sun.com
2. Selenium Server (formerly the Selenium RC Server)
http://www.seleniumhq.org/download/ , version 2.43.1
3. Microsoft .NET 3.5 (at least) Framework to support FitSharp, the .NET test runner for FitNesse.
Fitnesse will work on .NET 3.5 or lower versions. Download and install from
http://msdn.microsoft.com/netframework.
4. thoughtworks.selenium.core.dll which you can find in the dotnet folder of Remote Control
installation.
5. FitSharp binaries for .NET 3.5 Download the latest release from
http://github.com/jediwhale/fitsharp/tree/master/binary/.
Unpacking FitSharp will give:
- fit.dll - the Framework for Integrated Test, with runners for Finesse and batch.
- Runner.exe - In a .NET environment, FitNesse starts an external Runner.exe .Runner process then
connects to FitNesse, downloads the page and executes tests. The results are passed back to
FitNesse, which displays them to the user
Framework for Integrated Test (FIT).
- fitSharp.dll - fitSharp is a set of open-source  functional testing tools for .NET, inspired by the
6. FitNesse server (fitnesse-standalone.jar) download the latest release from Goto
http://www.fitnesse.org/FitNesseDownload
Start Server:
Selenium:
Fitnesse
Create Fixture:
Open a new .NET project, and copy this below class into it.
Ad references reference to fit.dll,  thoughtworks.selenium.core.dll and fitsharp.dll to your project
using System;                           //.Net library
using System.Collections.Generic;       //.Net library
using System.Text;       //.Net library
using Selenium;                         //Selenium library
using fit;                              //fit library
using fitlibrary;       //fit library
namespace webfixture
{
public class WebTest : fitlibrary.DoFixture
{
private ISelenium instance;
public void StartBrowserWithSeleniumConsoleOnAtPortAndScriptsAt(String browser,String rcServer,int rcPort,
{
instance = new DefaultSelenium(rcServer,rcPort,browser,seleniumURL);
instance.Start();
instance.Open(seleniumURL);
}
  }
}
Save and compile the will generate webfixture.dll in <project path>bin\debug
Create Fitnesse Test:
Open fitnesse localhost:8080 in browser and click “Edit”
#path of fil library
!define COMMAND_PATTERN {%m -r fitnesse.fitserver.FitServer,D:\Automation\fit.dll %p}
*path of runner
!define TEST_RUNNER {D:\Automation\Runner.exe}
#path of fixture dll
!path D:\Automation\project\Fitnesse\webfixture\webfixture\bin\Debug\webfixture.dll
#Class to include
!|webfixture.WebTest|
!|Start Browser|*firefox|With Selenium Console On|localhost| At Port|4444|And Scripts
At|http://www.google.com|
webfixture code
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Selenium;
using fit;
using fitlibrary;
namespace webfixture
{
    public class WebTest : fitlibrary.DoFixture
    {
        private ISelenium instance;
        private String title;
        public void StartBrowserWithSeleniumConsoleOnAtPortAndScriptsAt(
        String browser, String rcServer, int rcPort, String seleniumURL)
        {
           instance = new DefaultSelenium(rcServer,
           rcPort, browser, seleniumURL);
           instance.Start();
           instance.Open(seleniumURL);
           instance.WindowMaximize();
        }
       public void TypeUsername(String typeusername)
        {
           instance.Type("//*[@id='Email']", typeusername);
         
        }
       public void TypePassword(String typepassword)
       {
           instance.Type("//*[@id='Passwd']", typepassword);
       }
        public void ClickBrowser()
       {
           instance.Click("//*[@id='signIn']");
           instance.WaitForPageToLoad( "10000");
           title= instance.GetTitle();
       }
        public bool PageContainsText(String s)
        {
            return instance.IsTextPresent(s);
        }
      }
}

!define COMMAND_PATTERN {%m -r fitnesse.fitserver.FitServer,D:\Automation\fit.dll %p}
!define TEST_RUNNER {D:\Automation\Runner.exe}
!path D:\Automation\project\Fitnesse\webfixture\webfixture\bin\Debug\webfixture.dll
!|webfixture.WebTest|
!|Start Browser|*firefox|With Selenium Console On|localhost| At Port|4444|And Scripts At|http://www.gmail.com|
|TypeUsername|tovaibhav1|
|TypePassword|pass|
|ClickBrowser|
|Page contains text|sign|



Donate:

Please Donate the some money (anything do you want) for my
blog if you beneficial for this, I will provide more real example for the
latest technique for whom who wants to make a carrier in IT field or solved
some problem, My Name is – RITESH KUMAR SINGH A/C number- 913010044116345 AXIS
Bank LTD :- Vaishali NCR, India-001
 

Tuesday 11 November 2014

Example of Web driver Listiners

package main.test.org.seleniummonster.com.demo.eventlistenerdemo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.events.AbstractWebDriverEventListener;
public class EventListenerType2 extends AbstractWebDriverEventListener {
/**

* @author ritesh

*/

@Override

public void onException(Throwable arg0, WebDriver arg1)
{

System.out.println("There is an exception in the script, please find the below error description" );

arg0.printStackTrace();

}

}
===============================================
package main.test.org.seleniummonster.com.demo.eventlistenerdemo;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.events.EventFiringWebDriver;

public class EventFiringWebdriverExample
{    /**

    * @author Selenium ritesh

    */
    public static void main(String[] args) {

    // Creating webdriver  instance

    WebDriver driver = new FirefoxDriver();

    // Creating  EventFiringWebDriver instance

    EventFiringWebDriver eventFiringWD= new EventFiringWebDriver(driver);

    // Creating instance of eventListener, that we just defined

    EventListenerType2 eventListener1=new EventListenerType2();

    // Register the Listener with the event firing driver

    eventFiringWD.register(eventListener1);

    eventFiringWD.get("https://www.google.co.in/");

    eventFiringWD.findElement(By.className("nosuchclassName"));

    }

    }


Donate:

Please Donate the some money (anything do you want) for my
blog if you beneficial for this, I will provide more real example for the
latest technique for whom who wants to make a carrier in IT field or solved
some problem, My Name is – RITESH KUMAR SINGH A/C number- 913010044116345 AXIS
Bank LTD :- Vaishali NCR, India-001