c# - 如何在 C# 中使用 Selenium Grid?

标签 c# selenium selenium-grid

我正在研究 Selenium 并为我的小组举办研讨会...... 我遇到了很多麻烦 我使用 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 控制 Selenium RC。

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

谢谢, 黄先生

最佳答案

实际上,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。我的 site 上有一个 Selenium 教程。它使用 C#,应该可以帮助您上手。

关于c# - 如何在 C# 中使用 Selenium Grid?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2505987/

相关文章:

selenium - 无法通过 TestNG Dataprovider 并行运行超过 10 个测试

c# - 在 Azure Blob 存储上上传大文件时出现 "Stream is too long"

c# - 如何在 C# 中查找和使用进程 ID 将击键发送到 Excel 应用程序

c# - 在 C++ 中调用 C# WPF 代码

java - 45000 毫秒后无法连接到端口 7055 上的主机 127.0.0.1。使用 FF 版本 26.0 和 selenium 独立 jar 2.39

javascript - 将 Intern 与 Selenium 和动态 proxyUrl 结合使用

c# - 为什么我得到 Ice::MemoryLimitException,即使是 Ice.MessageSizeMax=2000000

c# - 在 OpenQA.Selenium (C#) 中找不到 WebDriverWait 类

python - 使用 Selenium (Python) 从输出框中获取值

node.js - 从文件 Selenium node.js 添加解压的扩展