2

Selenium の研究をしていて、グループでセミナーを開催しています... これで多くの問題に遭遇します C# 言語を使用してデモを作成します SeleniumExample.dll 次に、selenium RC と NUnit を起動し、NUnit で実行してテスト レポートを表示します。XML から testdata を読み取りました。

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を制御させる方法がわからないという理論を理解しています。

私はセレンの初心者です。誰かがこれを知っているなら、私を助けてください。とても感謝しています。

ありがとう、ホアン

4

1 に答える 1

3

実際には、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# を使用しており、すぐに使用できるはずです。

于 2010-03-24T08:30:32.120 に答える