Thursday 10 November 2011

Selenium with C# using MonoDevelop

Selenium


Selenium with C# using MonoDevelop


Since commercial tools being costlier to maintain in terms of licensing and various other factors, We (Our Team) have decided to go for another alternative which is some what similar to MSVS and we figured out MonoDevelop would be a good option and it is absolutely free!!!!


I have successfully installed it made it running for our selenium C# scripts and its really fantastic tool with build in unit test runner rather than having separate NUnit for MSVS.


If someone who wants to try Selenium and would like to execute their scripts in C# I would suggest this would be a good option.


Below are the steps to follow to start your Selenium C# project using MonoDevelop


Getting MonoDevelop:


1. Download the MonoDevelop for your operating system, Packages and Source Code.
2. Try to run the MonoDevelop-2.8.1.msi, you might encounter a warning.



3. Stop the installation and try to install the gtk-sharp-2.12.10.win32.msi
4. After Installing gtk-sharp-2.12.10.win32.msi try to run the MonoDevelop-2.8.1.msi and you might again encounter another error.


5. Download and Install .Netframework 4 
6. After Installing .Netframework 4, install Windos Software Development kit 
winsdk_web.exe downloaded from the MonoDevelop package.
7. Now run the MonoDevelop-2.8.1.msi and it should be installed without warnings or errors.
8. Go to Start All Programs and double click the MonoDevelop Icon to launch the application.



That looks Cool right!!!! --- If you want explore more about MonoDevelop get on to their website - http://monodevelop.com/

OK our next step is to create a project and get Selenium integrated to it.

Create a new solution in Monodevelop as shown below by selecting the under File -> New-> Solution

Once the solution is selected, new solution is opened. Select Empty Project (C#)


Give a name for the solution and browse to the location where you want to save the project. After the location is specified. click on the forward button and tick the check box for 'GTK# Support'


Click on OK and your solution is created which can be viewed in the solution explorer.


Now its time get your selenium webdrivers


"In order to create scripts that interact with the Selenium Server (Selenium RC, Selenium Remote Webdriver) or create local Selenium WebDriver script you need to make use of language-specific client drivers. Unless otherwise specified, drivers include both 1.x and 2.x style drivers."

"While drivers for other languages exist, these are the core ones that are supported by the main project." --- Extract from seleniumhq.org

After downloading the client drivers, copy over the files to the project directory where the solution is created.

Now in Monodevelop select references under the solution and right click to edit references


Select .Net Assembly tab in the Edit References window and navigate to the project location where the Selenium C# drivers are copied.

Select the following and click on Add button to add to the selected references:

Selenium.WebDriverBackedSelenium.dll
ThoughtWorks.Selenium.Core.dll
WebDriver.dll
WebDriver.Support.dll

Select the All tab in the Edit References and the following references 

nunitcore
nunit.framework
System

After all the required references are added click on OK.
(Please note you may need to add more references depending on the requirements of the script under execution)

Now its time to record a script and convert it to C# and execute it using MonoDevelop.

Record a simple script using Selenium IDE

After recording the script, play it back again and see the script is executed successfully.

Export the script as C# Webdriver from the Selenium IDE

Save the file in any desired location or with in the project file as .CS file.

Now add the file to the solution.



Check that your script is added to the solution, double click on the script to view. 


To Be Continued.......




2 comments:

  1. How do i record Selenium test cases into MonoDevelop? Please help...

    ReplyDelete
  2. You wouldn't record with MonoDevelop. Record is an Selenium IDE functionality. This would let you write Selenium RC or Webdriver scripts in C#.

    ReplyDelete