2012-09-28

Recording in Selenium IDE and Generating WebDriver Code

In this article, we are going to learn how to record steps in selenium IDE. We are going to see some basic path as well as some basic command descriptions.
Step 1 : Please Install IDE & Firefox (for reference you may see one of my previous posts)
Step 2 : Start Firefox
Step 3 : From menu, click tools, and then select Selenium IDE
clip_image002
Step 4 : By default, when IDE opened, it is recording mode( like , it is recording). In the example I am using www.kaz.com.bd this site for practice.
clip_image004
Step 4 : now, From browser go to www.kaz.com.bd
Step 5 : You get a static HTML site with 4 tabs “Home”, “Talents”,” Culture”,” Contact”.
clip_image006
Step 6: click on “Home”, then “Talents”,” Culture”,” Contact” accordingly and from stat menu bar, open selenium IDE UI. You will get those 4 steps listed
clip_image008
Step 7: Press stop button from Selenium IDE (right Upper corner Red Round Button)
Now, you have finished recording where steps are simple clicking tabs.
From the IDE, you can work on those steps like re-run.
Now, We will see how to get web driver Unit test codes (Selenium IDE supported some experimental codes)
Step 1 : To get the code, go to Option –> Options… and check the “Enable experimental features” and press ok
 clip_image010
Step 2: Now, After recording from IDE, click Options -> Format and get the list below
 clip_image012
Step 3: Select c#/NUnit /webDriver ( later on we will also get the JUnit 4 code also) and press OK on warning message( as this is experimental code, so it may be not very accurate).
Now you get the code
clip_image014
In C# Code we have
   1: using System;

   2: using System.Text;

   3: using System.Text.RegularExpressions;

   4: using System.Threading;

   5: using NUnit.Framework;

   6: using OpenQA.Selenium;

   7: using OpenQA.Selenium.Firefox;

   8: using OpenQA.Selenium.Support.UI;

   9:  

  10: namespace SeleniumTests

  11: {

  12:     [TestFixture]

  13:     public class Untitled

  14:     {

  15:         private IWebDriver driver;

  16:         private StringBuilder verificationErrors;

  17:         private string baseURL;

  18:         

  19:         [SetUp]

  20:         public void SetupTest()

  21:         {

  22:             driver = new FirefoxDriver();

  23:             baseURL = "http://www.kaz.com.bd/";

  24:             verificationErrors = new StringBuilder();

  25:         }

  26:         

  27:         [TearDown]

  28:         public void TeardownTest()

  29:         {

  30:             try

  31:             {

  32:                 driver.Quit();

  33:             }

  34:             catch (Exception)

  35:             {

  36:                 // Ignore errors if unable to close the browser

  37:             }

  38:             Assert.AreEqual("", verificationErrors.ToString());

  39:         }

  40:         

  41:         [Test]

  42:         public void TheUntitledTest()

  43:         {

  44:             driver.Navigate().GoToUrl(baseURL + "/");

  45:             driver.FindElement(By.LinkText("Home")).Click();

  46:             driver.FindElement(By.LinkText("Talents")).Click();

  47:             driver.FindElement(By.LinkText("Culture")).Click();

  48:             driver.FindElement(By.LinkText("Contact")).Click();

  49:         }

  50:         private bool IsElementPresent(By by)

  51:         {

  52:             try

  53:             {

  54:                 driver.FindElement(by);

  55:                 return true;

  56:             }

  57:             catch (NoSuchElementException)

  58:             {

  59:                 return false;

  60:             }

  61:         }

  62:     }

  63: }
Step 4 : So, After recording we are getting NUnit code here.
If we make an empty class type project in vs2010(see my previous post on how to create webdriver environment setup) and copy to class to a new empty class, we can run the webDriver Unit test case using NUnit GUI(after building Project)

If we choose the JAVA/JUnit4 webDriver then , we will get the following code
image

In JAVA code we get
   1: package com.example.tests;

   2: 

   3: import com.thoughtworks.selenium.Selenium;

   4: import org.openqa.selenium.*;

   5: import org.openqa.selenium.htmlunit.*;

   6: import org.openqa.selenium.firefox.*;

   7: import org.openqa.selenium.chrome.*;

   8: import org.openqa.selenium.ie.*;

   9: import org.junit.*;

  10: import static org.junit.Assert.*;

  11: 

  12: public class Untitled {

  13:  

  14:     WebDriver driver;

  15:     Selenium selenium;

  16:  

  17:     @Before

  18:     public void startSelenium() {

  19:         driver = new FirefoxDriver();

  20:         selenium = new WebDriverBackedSelenium(driver, "http://www.kaz.com.bd/");

  21:     }

  22:  

  23:     @After

  24:     public void stopSelenium() {

  25:         driver.close();

  26:     }

  27:  

  28:     @Test

  29:     public void testUntitled() {

  30:         selenium.open("/");

  31:         selenium.click("link=Home");

  32:         selenium.waitForPageToLoad("30000");

  33:         selenium.click("link=Talents");

  34:         selenium.waitForPageToLoad("30000");

  35:         selenium.click("link=Culture");

  36:         selenium.waitForPageToLoad("30000");

  37:         selenium.click("link=Contact");

  38:         selenium.waitForPageToLoad("30000");

  39:     }

  40:  

  41: }
If we make a JAVA project in Eclipse(see my previous post on how to create webdriver environment setup) and copy to class to a new empty class, we can run the webDriver Unit test case code Running as JUnit 4.0 test project. 

For detail about Selenium IDE, you can visit the link
Thanks for reading this….:)

This is shantonu's personal blog.Mail[shantonu_oxford@yahoo.com] to contact.

2012-09-26

Setting up Selenium Webdriver

Setting up Selenium Web driver environment in Windows PC

In the following article, we will learn how to setup environment for selenium IDE & selenium Webdriver.

Step 1: Installing Firefox
We need selenium IDE supported Firefox. To know supported Firefox version visit selenium IDE release note . See suitable version number and Download Firefox 
Step 2: Installing Selenium IDE
Run the newly installed Firefox and go to the link 
Download suitable Selenium IDE (Firefox supported, that you have seen from step 1). The Firefox plug-in will be installed.
Or, from Firefox, go to Tools -> add on (Ctrl+Shift+A) search selenium and install selenium IDE. You may find many helping add on. We may need to install when we will start for deeper level coding.

Step3: Selenium Driver Download
Download “Selenium Client Drivers” from here   for JAVA or C# . We will download both as we will setup both environments.Extract the folders and see
For Dot Net: We will get 2 folders for net35& net40 (for different dot Net versions). We have to include DLLs located inside folder as reference of the selenium project in VS 2010.
For JAVA: We will get 2 jar files. selenium-JAVA-2.25.0.jar, selenium-JAVA-2.25.0-srcs.jar. We have to include the jar in the project.

Step 4: IDE and Unit Test Frame Work Installation.
For Dot Net:
1.    Visual studio 2010 should be installed.
2.    NUnit(Download and install latest one)

For JAVA:
1.    Download and install latest Eclipse  or Net Beans(My examples are on Eclipse of that version )
2.    JUnit 4.0 JARs (Already included in eclipse, if not present please install latest one from here )

Step 5 : Including Unit Test framework in the project
For Dot Net : After Crating a Project(class library)
->From solution explorer Right click Reference
-> add reference 
-> Browse
-> Locate to the installed path of NUnit (under program files)
-> bin\framework
->select all (nunit.framework.dll, nunit.mocks.dll, pnunit.framework.dll) and press ok.
For JAVA: After Crating a JAVA Project
-> Mouse right click from Package explorer and click properties
(It also can be found while creating a new JAVA project)
-> build path
 -> Libraries
-> Add Library
-> JUnit
-> JUnit 4.0(not 3.0) and Finish
(Usually it is included in the eclipse, if not, include as external JARs that we have downloaded in step 4

Step 6 : Including Selenium Client Drivers reference  in the project
For Dot Net :
->From solution explorer Right click Reference
-> add reference 
-> Browse
-> Locate to the downloaded & extracted folder path of step 3
-> Select net40
-> include all DLLs (Castle.Core.dll, Ionic.Zip.dll, Newtonsoft.Json.dll, Selenium.WebDriverBackedSelenium.dll, ThoughtWorks.Selenium.Core.dll,
WebDriver.dll, WebDriver.Support.dll)
And press OK.
For JAVA:
-> Mouse right click from Package explorer and click properties
(It also can be found while creating a new JAVA project)
-> build path
 -> Libraries
->Add External JARs
-> Locate to the downloaded & extracted folder path of step 3
->selenium-JAVA-2.25.0.jar 

Step 7 : Add Unit Test framework Header in the Code
In the Class header, we have to add those references that we add in Step 5. Add the header in the top of a Test class.
For Dot Net  :
using NUnit.Framework;
For JAVA :
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;

Step 8 : Add Selenium WebDriver Header in the Code
In the Class header, we have to add those references that we add in Step 6. Add the header in the top of a Test class.
For Dot Net  :
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.IE;

For JAVA :
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

Now, we are ready for selenium web driver test implementation.
Be noted that, In Dot Net, we are using class library project type as we will use NUnit GUI for observing test results. And for JAVA, we are using run as JUnit(project) for observing test results.

2009-05-25

Read Write Text File in c#, The old fashion storage system.

Class Diagram, The function container of a system

I am very new for class diagram. I tried to introduce class diagram as a initial point of view, I hope it will help. I follow UML 2.0.....(CLICK & DOWNLOAD)

Activity Diagram,The business and operational work flow representing tool

This is my thoughts on Activity Diagram diagram(Uml 2.0) for all.
It will give you some initial idea.....:)...(CLICK & DOWNLOAD)

E-R Diagram, At-A-Glance Data Base Represening tool

This is my thoughts(I don't have much experience in database) on Sequence Diagram diagram(Uml 2.0) for all.
I made it in 2008. Hope fully It will give us some idea.....:)...(CLICK & DOWNLOAD)

Sequence Diagram, The Time prospective workflow of a program

This is my thoughts(very small) on Sequence Diagram diagram(Uml 2.0) for all.
I made it in 2008. Hope fully It will help all.....:)...(CLICK & DOWNLOAD)

Use Case Diagram, The Initial Requirement Specification

This is my thoughts on Use Case diagram(Uml 2.0) for all. I made it for my company in 2008. Hope fully It will help all.....:)...(CLICK & DOWNLOAD)

Implementing Crystal Report using UDL

Introduction to software testing