Installing Selenium Grid with MbUnit and Gallio

In this article I will explain you how you can install and run your Selenium C# scripts on Selenium Grid using MbUnit and Gallio
1. Download Gallio runner
2. Unzip the files to C:\GallioBundle-3.2.603.0
3. Add reference to Mbunit and Gallio in your selenium framework

4. Add MbUnit.Framework namespace to the test script.

5. Add following attributes in AssemblyInfo.cs

6. Add [Parallelizable] attribute to each Test Secripts you want to run in parallel

7. Rebuild the test solution
8. Download Selenium Grid
9. Unzip the files to C:\SeleniumGrid
10. You will have install Java JDK and Ant
11. Go to the selenium grid folder on Command prompt C:\SeleniumGrid and type ant launch-hub
12. Open a new command prompt C:\SeleniumGrid and type ant –Dport=6666 –Denvironment=*iexplore launch-remote-control to launch RC for Internet Explorer
13. Open a new command prompt C:\SeleniumGrid and type ant –Dport=5555 –Denvironment=*firefox launch-remote-control to launch RC for FireFox
14. Now open a new browser window and type http://localhost:4444/console
15. You will see the Selenium Grid Hub 1.0.8-SNAPSHOT

16. Create two selenium test scripts one to run on FireFox and the other on IE
Code for SeleniumGrid1.cs

using System;
using System.Text;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading;
using Selenium;
using MbUnit.Framework;
namespace SeleniumTests
{
[TestFixture]
[Parallelizable]
public class SeleniumGrid1
{
private ISelenium selenium;
private StringBuilder verificationErrors;
[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com.au/");
selenium.Start();
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}

[Test]
public void SGridTest1()
{
selenium.Open("/");
selenium.Type("q", "seleniumwiki.com");

selenium.Click("btnG");
selenium.WaitForPageToLoad("30000");
try
{
Assert.IsTrue(selenium.IsTextPresent("Selenium Wiki"));
}
catch (Exception e)
{
verificationErrors.Append(e.Message);
}
}
}
}

Code for SeleniumGrid2.cs

using System;
using System.Text;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading;
using Selenium;
using MbUnit.Framework;
namespace SeleniumTests
{
[TestFixture]
[Parallelizable]
public class SeleniumGrid2
{
private ISelenium selenium;
private StringBuilder verificationErrors;

[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.google.com.au/");
selenium.Start();
verificationErrors = new StringBuilder();
}

[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}

[Test]
public void SGridTest2()
{
selenium.Open("/");
selenium.Type("q", "seleniumwiki.com");

selenium.Click("btnG");
selenium.WaitForPageToLoad("30000");
try
{
Assert.IsTrue(selenium.IsTextPresent("Selenium Wiki"));
}
catch (Exception e)
{
verificationErrors.Append(e.Message);
}
}
}
}

17. Go to C:\GallioBundle-3.2.603.0\bin and double click on Gallio.Icarus.exe
Gallio Icarus window is opened and then you will have to load the dll file with your tests (Selenium Scripts).
Once the dll file is loaded you will see the two test scripts loaded. Select both the tests and click on the start button.

Submitted By Irina Burdilo

If you found this solution helpful or have something extra to add, feel free to share it here by commenting below.

6 thoughts on “Installing Selenium Grid with MbUnit and Gallio

  1. ndhai says:

    I tried your test and here’s some problem when I tried to modify it:

    1/ My firefox profile can not be found, where can I specific my “firefox.exe” for the grid to understand in both server and RC

    2/ I tried to start hub and slaves by selenium-server-standalone-2.8.0.jar. Here is my config:
    hub
    java -jar selenium-server-standalone-2.8.0.jar -role hub
    slave 1:
    java -jar selenium-server-standalone-2.8.0.jar -role rc -hub http://localhost:4444/grid/register -browser browserName=iexplore,platform=WINDOWS -port 5556
    slave 2:
    java -jar selenium-server-standalone-2.8.0.jar -role rc -hub http://localhost:4444/grid/register -browser browserName=safari,platform=WINDOWS -port 5557

    I went to http://localhost:4444/grid/console to check and everything is fine
    However, when I run the test, it throw me an error: System.Net.WebException: The remote server returned an error: (500) Internal Server Error.

    Please tell me why I encounter this error? Thank you !

  2. sadik ali says:

    This is good tutorials but we have need to run single script run in different-2 browser as in TestNG

    How it possible?

    Thanks,
    Sadik Ali

  3. TheX says:

    It’w work on WebDriver(Selenium2)
    but 50/50.
    sometime Webdriver return NoSuchElementExecption. if i tun test without parallelizing, all’s works.
    maybe a bug?!

  4. Amit Mishra says:

    Hi Pavandeep,

    I configured the selenium script as per your post.
    But the script doesn’t pass through Gallio.
    Please suggest what can be the cause behind this failure.

    Many Thanks,

    EXECUTION LOG OF MY GALLIO TEST REPORT IS GIVEN BELOW:

    Root
    020
    Results: 2 run, 0 passed, 2 failed, 0 inconclusive, 0 skipped
    Duration: 6.191s
    Assertions: 1

    seleniumgrid
    020
    Duration: 3.794s, Assertions: 1.
    File: C:\seleniumRC\selenium scripts\seleniumgrid\seleniumgrid\bin\Release\seleniumgrid.DLL
    CodeBase: C:\seleniumRC\selenium scripts\seleniumgrid\seleniumgrid\bin\Release\seleniumgrid.DLL
    Copyright: Copyright © 2012
    FileVersion: 1.0.0.0
    Product: seleniumgrid
    Title: seleniumgrid
    Version: 1.0.0.0
    Framework: MbUnit v3.3 build 454
    seleniumgrid1
    010
    Duration: 0.708s, Assertions: 0.
    TheUntitledTest

    Duration: 0.675s, Assertions: 0.
    Set Up
    Selenium.SeleniumException: ERROR: Could not retrieve a new session
    at Selenium.HttpCommandProcessor.DoCommand(String command, String[] args) in c:\Projects\WebDriver\trunk\dotnet\src\Selenium.Core\HttpCommandProcessor.cs:line 100
    at Selenium.HttpCommandProcessor.Start() in c:\Projects\WebDriver\trunk\dotnet\src\Selenium.Core\HttpCommandProcessor.cs:line 163
    at SeleniumTests.seleniumgrid1.SetupTest() in C:\seleniumRC\selenium scripts\seleniumgrid\seleniumgrid\seleniumgrid1.cs:line 22
    Tear Down
    System.NullReferenceException: Object reference not set to an instance of an object.
    at SeleniumTests.seleniumgrid1.TeardownTest() in C:\seleniumRC\selenium scripts\seleniumgrid\seleniumgrid\seleniumgrid1.cs:line 36
    seleniumgrid2
    010
    Duration: 3.747s, Assertions: 1.
    TheUntitledTest

    Duration: 3.725s, Assertions: 1.
    Execute
    Selenium.SeleniumException: XHR ERROR: URL = https://www.google.com/ Response_Code = 12017 Error_Message = Unknown
    at Selenium.HttpCommandProcessor.DoCommand(String command, String[] args) in c:\Projects\WebDriver\trunk\dotnet\src\Selenium.Core\HttpCommandProcessor.cs:line 100
    at SeleniumTests.seleniumgrid2.TheUntitledTest() in C:\seleniumRC\selenium scripts\seleniumgrid\seleniumgrid\seleniumgrid2.cs:line 43

  5. Gaurav says:

    One Query on parallelization:

    How Can I execute single test on multiple devices using this framework? Currently I am able to execute different test on different platform.

Leave a Reply

Your email address will not be published. Required fields are marked *