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

I have Selenium GRID Setup with various browsers (IE6, 7, 8, FF 3.5.6) written in C #, and individually they work fine. I also have a Selenium Tests test suite, and they also work great with the areas that I pass them. What I'm asking is a way to program various unit tests to cycle through all the browsers available to him on Selenium GRID.

There are not many browsers, so things like a list or an array of browsers are great, but I cannot understand how the installation cycle and TearDown go through browsers. I am using C # with NUnit along with Selenium Grid and 3 Selenium RC connected to it.

I don't even mind switching to something like MbUnit, if that means I could iterate over browsers.

Many thanks

+3
source share
3 answers

One (rather ugly) option is to use the RowTest extension for test methods that run in target browsers - a prize for polluting actual test methods with customization and probably slowing down the entire test suite.

0
source

If you use MbUnit, you can bind the attribute Factoryto a variable. Then return Data Factoryonce for each type of browser with which you want to automate. It will run the tests once in the browser.

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

0

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. , . .

0

Source: https://habr.com/ru/post/1742855/


All Articles