3

I'm using VS 2015 community. My Selenium C# test case always runs twice. The Test Case Explorer window shows 1 test case was run but the pass result shows two of the same test cases were executed. What is wrong with my test or framework? I have created a Test File with testcase (NunitDemo.cs) under my project.

I attached a screenshot to my Solutions Explorer window as well.

using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;


namespace DemoNunit
{

    [TestFixture]
    public class NunitDemo
    {
        private IWebDriver driver;

        [Test]
        public void tc_newAccount()
        {
            //open browser and navigate to aut
            driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://www.trainingrite.net");

            //click on signup button
            driver.FindElement(By.CssSelector("input.submitbtn")).Click();


            //enter firstname,  lastname, email, password
            driver.FindElement(By.Id("ctl00_MainContent_txtFirstName")).Clear();
            driver.FindElement(By.Id("ctl00_MainContent_txtFirstName")).SendKeys("Ren");
            driver.FindElement(By.Id("ctl00_MainContent_txtLastName")).Clear();
            driver.FindElement(By.Id("ctl00_MainContent_txtLastName")).SendKeys("G");
            driver.FindElement(By.Id("ctl00_MainContent_txtEmail")).Clear();
            driver.FindElement(By.Id("ctl00_MainContent_txtEmail")).SendKeys("[email protected]");
            driver.FindElement(By.Id("ctl00_MainContent_txtPassword")).Clear();
            driver.FindElement(By.Id("ctl00_MainContent_txtPassword")).SendKeys("12345");
            driver.FindElement(By.Id("ctl00_MainContent_txtVerifyPassword")).Clear();
            driver.FindElement(By.Id("ctl00_MainContent_txtVerifyPassword")).SendKeys("12345");
            driver.FindElement(By.Id("ctl00_MainContent_txtHomePhone")).Clear();
            driver.FindElement(By.Id("ctl00_MainContent_txtHomePhone")).SendKeys("951-265-1234");
            driver.FindElement(By.Id("ctl00_MainContent_txtCellPhone")).Clear();
            driver.FindElement(By.Id("ctl00_MainContent_txtCellPhone")).SendKeys("760-855-1234");
            driver.FindElement(By.Id("ctl00_MainContent_txtInstructions")).Clear();
            driver.FindElement(By.Id("ctl00_MainContent_txtInstructions")).SendKeys("Running first selenium automation scripts in C#!");

            //click on submit button
            driver.FindElement(By.Id("ctl00_MainContent_btnSubmit")).Click();


            //verify new customer is added successfully
            Assert.AreEqual("Customer information added successfully",  driver.FindElement(By.Id("ctl00_MainContent_lblTransactionResult")).Text);

        }
    }
}
2
  • Check if you call tc_newAccount() as a method from other class/test. Commented Apr 8, 2016 at 8:52
  • I'm not calling tc_newAccount from another class. Are you saying to instantiate it and run it to see if it runs twice? Still a good idea, I will try. Commented Apr 9, 2016 at 21:45

2 Answers 2

2

Do you have both the Nunit 2.x and 3.x Test Adapter installed in VS? If so try removing one of them and running the test.

Sign up to request clarification or add additional context in comments.

3 Comments

i did have two adaptors so I removed the nunit test adaptor and left the adaptor with the frameworkinstalled, made another build, but it still ran twice.
oops i did had three adaptors so I removed the nunit.testadaptor and left the adaptor with the framework installed and i also removed the nUnitConsole, made another build, but it ran once as desired. Thank you very much.
Can you please mark the question as answered if your issue has been resolved?
2

As an addition to Dmitry's answer, if you have the NUnitTestAdapter installed via the Extensions as well as via the NuGet package, the tests will run twice. This is a known issue.

Comments

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.