开发者

How to use Selenium Grid with C#?

I'm researching Selenium and have a seminar for my group... I meet many troubles with this I use C# language and write a demo SeleniumExample.dll Then I start selenium RC and NUnit and run it with NUnit to see the test report. I read testdata from XML.

Here's the SeleniumExample.dll: using System;

using System.Xml;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;

namespace SeleniumExample
{

   public class Success_Login
   {

      //User defined

       private string strURL = "http://newtours.demoaut.com/
mercurywelcome.php";
       private string[] strBrowser = new string[3] { "*iehta",
"*firefox", "*safari" };

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

               [SetUp]
               public void SetupTest()
               {
                       selenium = new DefaultSelenium("localhost", 4444,
this.strBrowser[0], this.strURL);
                       selenium.Start();
                       verificationErrors = new StringBuilder();
               }

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

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

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

               foreach (XmlNode node in docNode)
               {
                   selenium.Open("/");
                   selenium.Type("userName",
node["username"].InnerText);
                   selenium.Type("password",
node["password"].InnerText);
                   selenium.Click("login");
                   selenium.WaitForPageToLoad("30000");
                   Assert.AreEqual("Find a Flight: Mercury Tours:",
selenium.GetTitle());
               }
           }
           catch (AssertionException e)
           {
               verificationErrors.Append(e.Message);
           }
               }
   }
}

Now I want to have a demo that using Selenium Grid (SG) but I don't know how to do. I read document and understand the way SG works. I install SG and install Ant1.8. The tests will communicate with Selenium Hub. Actually, I just understand the theory I don't know how to make the tests communicate with Selenium Hub and how to make Selenium Hub control Selenium RC.

I am a new for Selenium. If anyone know this, please help me. I appreciate it so much.

THANKS, Hoang


In reality there is no major difference between Selenium RC and Selenium Grid. The only difference is that with Grid you don't have to know where the RC nodes are but if you use Selenium RC you will have to.

string hubAddress = "machineNameWithSeleniumGridHub"

[SetUp]
public void SetupTest()
{
    selenium = new DefaultSelenium(hubAddress, 4444,this.strBrowser[0], this.strURL);
    selenium.Start();
    verificationErrors = new StringBuilder();
}

When your tests run they will speak to the hub which will then push the commands out to the first available RC. I have a Selenium Tutorial on my site. It uses C# and should get you going.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜