Running a Selenium RC test using C#

Running a Selenium RC test using C#

What is Selenium RC?

  • It is a tool that enables us to write automated web application UI tests.
  • Typical includes support for languages as given under
    • Java
    • C#
    • Python
    • PHP
    • Ruby On Rails
    • Perl

Selenium RC Components

The basic function of the selenium server is to

  • Launch and Kill browsers
  • Interpret and run the Selenese commands
  • Act as HTTP proxy to intercept and verify HTTP messages between browser and AUT

Let’s see the steps to write and execute a basic script under Selenium RC.

1)      You have already identified the scenario on your web application that you need to test.

2)      Identify the start point and end point for your script.

3)      In this case, I am beginning with the login, navigating to the home page on successful login and then returning back to the login page by a logout.

4)      I invoked the login page for the web application. (Refer to the figure given below).

Web Application - Login Screen
Web Application - Login Screen

5)      I go to Tools >> Selenium IDE to invoke the IDE reference given within the firefox browser.

Invoke Selenium IDE in firefox
Invoke Selenium IDE in firefox

6)      Selenium IDE is invoked. Please refer to the figure

Record your Selenium IDE test
Record your Selenium IDE test

7)      Now click the Record button and record your script/ scenario.

8)      Selenium IDE will be populated with the resultant script instructions. You can see the steps in the figure given below.

Selenium IDE script recorded
Selenium IDE script recorded

9)      Once the script has been recorded into the Selenium IDE, you can run/ execute it and verify for its correctness. Now this script needs to be converted into the RC script.

10)   Go to Options >> Options to invoke the options setup window. You will find a checkbox entry labeled as “Enable experimental features”. Check this entry and click OK.

Experimental features enabled for Selenium RC
Experimental features enabled for Selenium RC

11)   Now you are ready for conversion to the applicable format as deemed fit.

12)   Go to Options >> Formats and select the C# format. Refer to the figure given below.

Convert your Selenium IDE script to C sharp format
Convert your Selenium IDE script to C sharp format

13)   On selecting the C# format, you will notice your stepwise IDE instructions automatically converted to the relevant C# code.

Selenium IDE test converted into C# format
Selenium IDE test converted into C# format

14)   Open Visual Studio and Select Visual C# >> Windows >> Class Library.

C# Windows Library invoked in Visual Studio
C# Windows Library invoked in Visual Studio

15)   Open the class library and copy the converted C# code into this class library file.

C# selenium test script copied into Visual Studio
C# selenium test script copied into Visual Studio

16)   Now remember the things to be done at this point

  1. Save the Class Library file
  2. Rename the namespace (It is originally shown as SeleniumTests during conversion, change it to an appropriate classname.
  3. Change the project name
  4. Add references to Nunit dlls.

17)   The Nunit references for dotnet need to be downloaded into a folder from which you can refer to the associated .dll files.

Add reference to Selenium Nunit references
Add reference to Selenium Nunit references
Nunit references added
Nunit references added

18)   Now create the build by Debug >> Build <<classlibrary>>. The figure below shows the build carried out successfully.

Build successfully created
Build successfully created

19)   Once the build is created successfully, we need to get this into Nunit for our test. As the build is created, you will find the corresponding dll created into a folder as illustrated below.

Location of .DLL after build creation
Location of .DLL after build creation

20)   Open Nunit and open the Nunit project by navigating to this resultant dll file. The figures shows the selection of the resultant .dll file.

Select the resultant .DLL
Select the resultant .DLL

21)   Now invoke the Selenium server by typing java –jar <<selenium-server-jar-file>>.jar

22)   Once the .dll file is opened within NUnit, now click the RUN button to carry out the test.

23)   On successful test verification, the NUnit will show the results in Green. Please refer to the figure below.

Successful NUnit Test - Passed
Successful NUnit Test - Passed

24)   Incorrect results or dependency errors will be shown in NUnit as indicated below.

Indication of Error in NUnit
Indication of Error in NUnit

Once you learn how to get your SElenium RC scripts ready and working, you can work up to the next level by adding exceptions, writing output to particular folders and so on.

So the very best from me for a successful Selenium RC venture. Thank you.

Advertisements

18 thoughts on “Running a Selenium RC test using C#

  1. Hello Abhi,

    Do you have any documentation for converting the NUnit Test results to html report?

    Best regards,
    Thota Raj Sekhar.

    Like

  2. Have you ever thought about including a little bit more
    than just your articles? I mean, what you say is valuable and
    everything. Nevertheless think about if you added some great photos or videos to give your posts more, “pop”!
    Your content is excellent but with images and videos, this site could
    certainly be one of the greatest in its niche. Good blog!

    Like

  3. thank you for the guide, it is very helpful.
    i have a question about step 21.
    if someone is running windows 7, where do they start the selenium rc?

    thank you

    Like

    1. Hi,
      This could be a possible solution to resolve your issues with Windows 7.

      Selenium RC 1.0.x was used predominantly with IE6 and IE7. However with Windows 7 and Vista making inroads, IE9 is typically used.

      – Ensure that you get the latest Selenium 2.0 from their website
      – Ensure to run the files as an Administrator
      – If it still shows you errors, it could be due to the security protected mode enabled. You can go to Internet options, navigate to Security tab and disable a checkbox for “Enable Protected Mode”. You will be able to proceed with Windows 7 too then…. All the best.

      Like

  4. This is very excellent work actually for a selenium beginners Abhilash….As mentioned in the 6th screen shot….how can i get the C# (Remote control) option in IDE..Can u pls tell us?

    Like

  5. Hai abhilash….As u said for the last screen…this occurs when there is dependency error or incorrect…can you tell me what exactly could be the solution for the screen shot as u provided….i got the same exact error output….pls let me have the solution for this

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s