-1

I had created a simple program to run selenium in chrome driver session but it does not open any browser like in Java does. Im execute the test via Test Explorer window in Visual Studio. How to run this test by NUnit?

Please help. Thanks.

namespace Automation_Framework.TestManager
{
    [TestFixture]
    class ChromeTestManager
    {
        private WebDriverManager webDriverManager;
        private IWebDriver driver;

        public ChromeTestManager()
        {
            webDriverManager = new WebDriverManager();
        }

        [SetUp]
        public void setup()
        {
            webDriverManager.createDriver("chrome");
            driver = webDriverManager.getDriver();
        }

        [Test]
        public void test()
        {
            driver.Url = "http://www.google.com.my";
            driver.Navigate().GoToUrl("http://www.google.com.my");
        }



        [TearDown]
        public void shutdown()
        {
            driver.Close();
        }


    }
}

I am currently run the test inside main but it does not have the full life cycle of test fixture. How to run it with full life cycle of the test fixture?

1 Answer 1

1

Make sure you have the NUnit test adapter also installed under your nuget packages, otherwise visual studio won't be able to run your tests.

enter image description here

Looking at your code snippet I had to make some changes shown below to get it working on my side. Please refer to WebDriverManager's github page for further info on the library.

namespace Automation_Framework.TestManager
{
    [TestFixture]
    public class ChromeTestManager
    {
        private DriverManager webDriverManager;
        private IWebDriver driver;

        public ChromeTestManager()
        {
            webDriverManager = new DriverManager();
        }

        [SetUp]
        public void setup()
        {
            webDriverManager.SetUpDriver(new ChromeConfig());            
            driver = new ChromeDriver();
        }

        [TestCase]
        public void test()
        {
            driver.Url = "http://www.google.com.my";
            driver.Navigate().GoToUrl("http://www.google.com.my");
        }

        [TearDown]
        public void shutdown()
        {
            driver.Close();
        }
    }
}
Sign up to request clarification or add additional context in comments.

5 Comments

I have the NUnit3TestAdapter but it does not run any test.
what happens when you put a break point in your testcase or testsetup and run test under "Debug Test" option?
It shows Unexpected error detected. Check the Tests Ouput pane for details.
this is an issue with your setup with nunit, I am positive that if you remove code references from selenium, your test will still face this issue. try to setup a new project from scratch and add the appropriate nuget packages for nunit; see if a method with testcase attribute is executed or not. the selenium portion is just fine.
I tried to setup a new project but still facing the same error. Can u send u sln file to me?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.