Run Selenium tests in multiple browsers one after another from C# NUnit

前端 未结 8 1684
清酒与你
清酒与你 2020-11-29 01:39

I\'m looking for the recommended/nicest way to make Selenium tests execute in several browsers one after another. The website I\'m testing isn\'t big, so I don\'t need a par

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 02:02

    This is basically just an expansion of alanning's answer (Oct 21 '11 at 20:20). My case was similar, just that I did not want to run with the parameterless constructor (and thus use the default path to the driver executables). I had a separate folder containing the drivers I wanted to test against, and this seems to work out nicely:

    [TestFixture(typeof(ChromeDriver))]
    [TestFixture(typeof(InternetExplorerDriver))]
    public class BrowserTests where TWebDriver : IWebDriver, new()
    {
        private IWebDriver _webDriver;
    
        [SetUp]
        public void SetUp()
        {
            string driversPath = Environment.CurrentDirectory + @"\..\..\..\WebDrivers\";
    
            _webDriver = Activator.CreateInstance(typeof (TWebDriver), new object[] { driversPath }) as IWebDriver;
        }
    
        [TearDown]
        public void TearDown()
        {
            _webDriver.Dispose(); // Actively dispose it, doesn't seem to do so itself
        }
    
        [Test]
        public void Tests()
        {
            //TestCode
        }
    }
    

    }

提交回复
热议问题