如何在 Nunit/Selenium GRID/C# 设置中使用多个浏览器

发布于 2024-08-30 11:31:39 字数 346 浏览 3 评论 0原文

我有一个 Selenium GRID 设置,上面有各种浏览器(IE6、7、8、FF 3.5.6),用 C# 编写,它们单独工作得很好。我还有一套 Selenium 测试设置,它们也可以在我传递给它们的环境中正常工作。我要求的是一种以编程方式设置不同单元测试的方法,以循环访问 Selenium GRID 上可用的所有浏览器。

浏览器并不多,因此浏览器列表或数组之类的东西很好,但我无法找到一种方法来通过浏览器进行安装和拆卸循环。我使用 C# 和 NUnit 以及连接到它的 Selenium Grid 和 3 个 Selenium RC。

如果这意味着我可以在浏览器中循环,我什至不介意更改为 MbUnit 之类的东西。

非常感谢

I have a Selenium GRID Setup with the various browsers on it (IE6, 7, 8, FF 3.5.6) written in C# and individually they work fine. I also have a set of Selenium Tests setup and they also work fine with the envirments that i pass to them. What i am asking for is a way to prgrammatically set the differant unit tests to cycle through all of the browsers available to it on the Selenium GRID.

There are not that many browsers, so things like a list or array of browsers is fine but i can't figure a way to have the Setup and TearDown cycle through the browsers. I am using C# with NUnit along with Selenium Grid and 3 Selenium RCs hooked upto it.

I Don't even mind changing to something like MbUnit if it meant I could cycle through the browsers.

Many thanks

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

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

发布评论

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

评论(3

记忆で 2024-09-06 11:31:39

一种(相当丑陋的)选项可能是在目标浏览器中传递的测试方法上使用 RowTest 扩展 - 其代价是通过设置污染实际的测试方法,并可能减慢整个测试套件的速度。

One (rather ugly) option might be using RowTest extension on test methods passing in the target browsers - at a prize of polluting the actual test methods with setup and probably slowing down the whole test suite.

宫墨修音 2024-09-06 11:31:39

如果您使用 MbUnit,则可以将 Factory 属性绑定到变量。然后让数据工厂为您想要自动化的每种类型的浏览器返回一次。它将为每个浏览器执行一次测试。

http://www.gallio.org/wiki/doku .php?id=mbunit:da​​ta-driven_testing:factory

If you are using MbUnit, you can bind a the Factory attribute to a variable. Then have the Data Factory return once of each type of browser you want to automate with. It will execute the tests once per browser.

http://www.gallio.org/wiki/doku.php?id=mbunit:data-driven_testing:factory

那伤。 2024-09-06 11:31:39

如果您使用 NUnit,则可以指定 参数化 TextFixtures 以及所有您想要在基本测试类中使用的浏览器:

namespace Tests
{
    [TestFixture("*firefox")]
    [TestFixture("*iexplore")]
    public abstract class Test
    {
        private static string _browser;

        protected Test()
        {
        }

        protected Test(string browser)
        {
            SetBrowser(browser);
        }        

        public static void SetBrowser(string browser)
        {
            _browser = browser;
        }

        [SetUp]
        public virtual void Setup()
        {
            Selenium = new DefaultSelenium(localhost, 5555, _browser, "http://www.google.com/");
            Selenium.Start();
        }

        [TearDown]
        public virtual void TearDown()
        {
            Selenium.Stop();
        }
    }
}

并且测试本身将类似于:

namespace Tests
{
    [TestFixture]
    public class Test1 : Test
    {
        public Test1(string browser)
        {
            SetBrowser(browser);
        }

        [Test]
        public void FirstTest()
        {
            ...
        }
   }
}

2)您可以通过 PNunit。缺点:每个测试都应该在 test.conf 文件中提及。优点:所有指定的浏览器将并行运行。 test.conf 文件示例,其中为两个浏览器指定了一个测试:

<TestGroup>
  <ParallelTests>  
    <ParallelTest>
      <Name>Tests</Name>
        <Tests>

          <TestConf>
            <Name>Test1FF</Name>
            <Assembly>Test.dll</Assembly>
            <TestToRun>Test.Tests.Test1</TestToRun>
            <Machine>localhost:8080</Machine>
            <TestParams>
              <string>*firefox</string>
            </TestParams>
          </TestConf>

          <TestConf>
            <Name>Test1IE</Name>
            <Assembly>Test.dll</Assembly>
            <TestToRun>Test.Tests.Test1</TestToRun>
            <Machine>localhost:8080</Machine>
            <TestParams>
              <string>*iexplore</string>
            </TestParams>
          </TestConf>

        </Tests>
      </ParallelTest>
    </ParallelTests>
</TestGroup>

基本测试类将类似于:

using NUnit.Framework;
using PNUnit.Framework;

namespace Tests
{
    [TestFixture]
    public class Test
    {
        private string browser;

        protected Test()
        {
        }     

        [SetUp]
        public virtual void Setup()
        {
            browser = PNUnitServices.Get().GetTestParams();
            Selenium = new DefaultSelenium(localhost, 5555, browser, "http://www.google.com/");
            Selenium.Start();
        }

        [TearDown]
        public virtual void TearDown()
        {
            Selenium.Stop();
        }
    }
}

3) 您可以在 app.config 中指定浏览器并通过 TeamCity 更改它。没有研究这个解决方案,所以不能给你一个例子。
希望前两个解决方案会有所帮助。

If you use NUnit, you can specify parameterized TextFixtures with all browsers you want at base test class:

namespace Tests
{
    [TestFixture("*firefox")]
    [TestFixture("*iexplore")]
    public abstract class Test
    {
        private static string _browser;

        protected Test()
        {
        }

        protected Test(string browser)
        {
            SetBrowser(browser);
        }        

        public static void SetBrowser(string browser)
        {
            _browser = browser;
        }

        [SetUp]
        public virtual void Setup()
        {
            Selenium = new DefaultSelenium(localhost, 5555, _browser, "http://www.google.com/");
            Selenium.Start();
        }

        [TearDown]
        public virtual void TearDown()
        {
            Selenium.Stop();
        }
    }
}

And tests itself will be something like that:

namespace Tests
{
    [TestFixture]
    public class Test1 : Test
    {
        public Test1(string browser)
        {
            SetBrowser(browser);
        }

        [Test]
        public void FirstTest()
        {
            ...
        }
   }
}

2) You can specify browsers via PNunit. Cons: each test should be mentioned in test.conf file. Pros: all specified browsers will be run in parallel. Example of test.conf file with one test specified for two browsers:

<TestGroup>
  <ParallelTests>  
    <ParallelTest>
      <Name>Tests</Name>
        <Tests>

          <TestConf>
            <Name>Test1FF</Name>
            <Assembly>Test.dll</Assembly>
            <TestToRun>Test.Tests.Test1</TestToRun>
            <Machine>localhost:8080</Machine>
            <TestParams>
              <string>*firefox</string>
            </TestParams>
          </TestConf>

          <TestConf>
            <Name>Test1IE</Name>
            <Assembly>Test.dll</Assembly>
            <TestToRun>Test.Tests.Test1</TestToRun>
            <Machine>localhost:8080</Machine>
            <TestParams>
              <string>*iexplore</string>
            </TestParams>
          </TestConf>

        </Tests>
      </ParallelTest>
    </ParallelTests>
</TestGroup>

And base test class will be something like that:

using NUnit.Framework;
using PNUnit.Framework;

namespace Tests
{
    [TestFixture]
    public class Test
    {
        private string browser;

        protected Test()
        {
        }     

        [SetUp]
        public virtual void Setup()
        {
            browser = PNUnitServices.Get().GetTestParams();
            Selenium = new DefaultSelenium(localhost, 5555, browser, "http://www.google.com/");
            Selenium.Start();
        }

        [TearDown]
        public virtual void TearDown()
        {
            Selenium.Stop();
        }
    }
}

3) You can specify browsers in app.config and change it via TeamCity. Didn't investigate this solution, so can't give you an example.
Hopes first two solutions will help.

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