Selenium Grid

22 Apr 2011 by

Selenium Grid Architecture

Selenium Grid Architecture

Selenium is a fantastic web application testing package that comes with different form factors such as Selenium IDE, Selenium Remote Control (RC), Selenium WebDriver and finally Selenium Grid. It highly depends on quality assurance to choose whichever appropriated. This article we see Selenium Grid as it is a good example of distributed systems.

What is Selenium Grid actually?

In distributed systems, Cloud computing is usually running on homogeneous platform while Grid computing is running heterogeneous platform. Similarly, Selenium Grid is running on different (heterogeneous) platform, support various programming languages, support multiples unit test framework, and more importantly is cross browsers.

Architecture

Selenium Grid consists of 2 main parts:

  • Selenium Hub: the main coordinator of all Selenium Remote Control. When we start developing testing, we only point to Selenium Hub IP address. With appropriated mentioned environment, Selenium Hub will forward the request to specific environment in Selenium Remote Control. The example of environments are: *firefox, “Firefox on Linux”, “Firefox on Windows”, *safari, etc.
  • Selenium Remote Control (RC): the server that will invoke browser to be under test. It receive the command from Selenium Hub

How to Start?

  • Start Selenium Hub
    • $ ant launch-hub
  • Start Selenium Remote Control (RC)
    • $ ant -Dhost=IP_of_RC -Dport=5555 -DhubURL=http://IP_of_Hub:4444 -Denvironment="Firefox on Linux" launch-remote-control
  • Run Test from NUnit in C#. The code is exactly the same of old Selenium Remote Control (RC)
  • Selenium Grid web monitoring console
    • http://IP_of_Hub:4444/console

Source Code in NUnit and C#

using System;
using System.Text;
using NUnit.Framework;
using Selenium;

namespace SeleniumTests
{
    [TestFixture]
    public class Lycog
    {
        private ISelenium _selenium;
        private StringBuilder _verificationErrors;

        [SetUp]
        public void SetupTest()
        {
            _selenium = new DefaultSelenium("192.168.0.135", 4444, "Firefox on Windows", "http://lycog.com/");
            _selenium.Start();
            _verificationErrors = new StringBuilder();
        }

        [TearDown]
        public void TeardownTest()
        {
            try
            {
                _selenium.Stop();
            }
            catch (Exception)
            {
            }
            Assert.AreEqual("", _verificationErrors.ToString());
        }

        [Test]
        public void SearchMooreLaw()
        {
          _selenium.Open("/");
          _selenium.Click("s");
          _selenium.Type("s", "selenium");
          _selenium.Click("//form[@id='searchform']/input[2]");
          _selenium.WaitForPageToLoad("30000");
          Assert.IsTrue(_selenium.IsElementPresent("link=Web Application Testing System – Selenium"));
        }
    }
}

References

No responses yet

Leave a Reply