Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99418

NUnit pass data from OneTimeSetUp to all tests in that fixture

$
0
0

In NUnit, I am attempting to initialize a variable during the test fixture's OneTimeSetUp and reference that variable in all test cases under that fixture.

The OneTimeSetUpAttribute is applied to a function in a file called Initializer.cs, where I initialize a new instance of a Selenium IWebDriver named driver and apply some common configuration options. My test cases are defined in TestCases.cs in the same namespace and directory as Initializer.cs. Is it possible to somehow pass the driver variable to the test cases defined in TestCases.cs? If not, then how should I address initializing a new instance of IWebDriver on each new test run without having to initialize it during the SetUp of each test case file I add? See the code below.

I am using Visual Studio Test Explorer to execute the tests.

Initializer.cs

namespace AutomatedTests
{
    [SetUpFixture]
    public class Initializer
    {
        IWebDriver driver = null;

        [OneTimeSetUp]
        public void Before()
        {
            ChromeOptions options = new ChromeOptions();
            // some initial browser configuration here

            driver = new ChromeDriver(".");
        }

        [OneTimeTearDown]
        public void After()
        {
            driver.Close();
        }
    }
}

TestCases.cs

namespace AutoamtedTests
{
    public class TestCases
    {
        [Test]
        public void AutomatedTest()
        {
            // is it possible to reference 'driver' here?
        }
    }
}

Viewing all articles
Browse latest Browse all 99418

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>