How to make the selected testcript is run in selenium grid

Posted by Yui on Stack Overflow See other posts from Stack Overflow or by Yui
Published on 2010-04-15T10:39:16Z Indexed on 2010/04/15 10:43 UTC
Read the original article Hit count: 475

Filed under:

Hi,

I can launch some remote control by using: ant launch-remote-control

but I dont know how my script connect to hub? I set up ant, selenium-grid on the same computer. I have an grid.dll which is written by C# and run through NUnit. The test data is read from xml file (ValidData.xml) The example code is below :

using System.Collections.Generic; using System.Linq; using System.Text; using System; using System.Xml; using System.Text.RegularExpressions; using System.Threading; using NUnit.Framework; using Selenium;

namespace Grid { public class Class1 { //User defined

    private string strURL = "http://gmail.com/";
    private string[] strBrowser = new string[3] { "*iehta", "*firefox", "*safari" };
   string hubAddress = "192.168.20.131"; // IP of my computer

    // System defined
    private ISelenium selenium;
    private StringBuilder verificationErrors;

    [SetUp]
    public void SetupTest()
    {

        selenium = new DefaultSelenium(hubAddress, 4444, this.strBrowser[1], this.strURL);// do i need to identify browser when I defined it when launching a remote control
        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());
    }

    private string[] name;

    [Test]
    public void LoginPassedTest()
    {
        try
        {
            XmlDocument doc = new XmlDocument();
            XmlNode docNode;

            doc.Load("ValidData.xml");
            docNode = doc["TestCase"];

            foreach (XmlNode node in docNode)
            {
                selenium.Open("/");
                selenium.WaitForPageToLoad("50000");
                selenium.Type("Email", node["username"].InnerText);
                selenium.Type("Passwd", node["password"].InnerText);
                selenium.Click("signIn");
                selenium.WaitForPageToLoad("100000");
                name = (selenium.GetText("//div[@id='guser']/nobr/b").Split('@'));

                try
                {
                    Assert.AreEqual(node["username"].InnerText, name[0]);
                    Assert.AreEqual("Sign out", selenium.GetText(":r6"));
                }
                catch (AssertionException e)
                {
                    verificationErrors.Append(e.Message);
                }

                selenium.Click(":r6");
            }
        }
        catch (AssertionException e)
        {
            verificationErrors.Append(e.Message);
        }
    }
}    

}

Step I run this script: 1.I build that script into DLL 2.I start hub by using command "ant lauch-hub" 3.I start 2 remote controls by using command : ant -Dport=5566 -Denvironment="*chrome" launch-remote-control ant -Dport=5577 -Denvironment="*iexplore" launch-remote-control 4.Then I open Nunit and load DLL (code above) and run 5.The NUNit doesnot respond anything.

I think there are some missing things but I dont know. How can the test script (DLL) know which is sequence of remote control is selected to run the test????

Please help me!! Thank you so much

Yui.

© Stack Overflow or respective owner

Related posts about selenium-grid