如何在 C# 中使用 Selenium Grid?

发布于 2024-08-26 11:56:40 字数 2614 浏览 5 评论 0原文

我正在研究硒并为我的小组举办研讨会...... 我遇到了很多麻烦 我使用 C# 语言并编写了一个演示 SeleniumExample.dll 然后我开始 selenium RC 和 NUnit 并用 NUnit 运行可以看到测试报告。 我从 XML 读取测试数据。

这是 SeleniumExample.dll:使用系统;

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
                       }
                       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);
           }
               }
   }
}

现在我想要一个使用 Selenium Grid (SG) 的演示,但我不知道 怎么办。我阅读了文档并了解 SG 的工作方式。我安装 SG并安装Ant1.8。测试将与 Selenium Hub 进行通信。 其实我只懂理论,不知道怎么做 测试与 Selenium Hub 通信以及如何制作 Selenium Hub 控制硒RC。

我是硒的新手。如果有人知道这个,请帮助我。我 非常感谢。

谢谢, 黄

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
                       }
                       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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

累赘 2024-09-02 11:56:40

实际上,Selenium RC 和 Selenium Grid 之间没有重大区别。唯一的区别是,使用 Grid,您不必知道 RC 节点在哪里,但如果您使用 Selenium RC,则必须知道。

string hubAddress = "machineNameWithSeleniumGridHub"

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

当您的测试运行时,它们将与集线器通信,然后集线器将命令推送到第一个可用的 RC。我的网站上有一个 Selenium 教程。它使用 C#,应该可以帮助您上手。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文