开发者

How do i use more than one browser in Nunit/Selenium GRID/C# Setup

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 Se开发者_运维知识库tup 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


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.


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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜