1

I'm writting Automatic Test in .NET and I have a little issue with [SetUp] - it's doesn't go before [Test] and Chrome Browser doesn't even open a new window - I have no idea why.

using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System.Net;
using System.Threading;
using Tests.Settings;

namespace Tests.TestCaseScenario
{
    public class BaseTestCaseTemplate
    {
        protected string password;
        protected string userName;
        protected string websideURL;

        public IWebDriver Driver = new ChromeDriver();

        //load before each test
        [SetUp]
        public void SetUp()
        {
            //load userconfig.json
            var UserConfigReader = new UserConfigReader();

            var CurrentUserConfig = UserConfigReader.LoadJsonConfigToObj(UserConfigPath);

            password = CurrentUserConfig.Password;
            userName = CurrentUserConfig.UserName;
            websideURL = CurrentUserConfig.WebsiteURL;

            Driver.Navigate().GoToUrl(websideURL);
            Driver.Manage().Window.Maximize();

        }
    }
}

And here's my test class

using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;

namespace Tests.TestCaseScenario
{
    [TestClass]
    public class SimplyChecking : BaseTestCaseTemplate
    {
        [Test]
        public void ApplicationCheckerSimple()
        {

            HomePage homePage = new HomePage();
            homePage.Login(userName, password);
        }
    }
}

and my Page class:

using OpenQA.Selenium;
using OpenQA.Selenium.Support.PageObjects;

namespace Tests.Pages
{
    public class HomePage : BasePageTemplate
    {
        [FindsBy(How = How.Id, Using = "UserName")]
        private IWebElement UserName;

        [FindsBy(How = How.Id, Using = "Password")]
        private IWebElement Password;

        [FindsBy(How = How.ClassName, Using = "btn-primary")]
        private IWebElement LoginButton;

        public void Login(string user, string password)
        {
            UserName.SendKeys(user);
            Password.SendKeys(password);
            LoginButton.Click();
        }
    }
}

Test do not even run - It doesn't return any value (pass or fail) but when I change [Test] for [TestMethod] it runs and gives a negative result.

Kacper G
  • 27
  • 7
  • Please add namespaces, and make sure your setup and tests are all in the same namespace. – Murray Foxcroft Jan 30 '19 at 16:51
  • I've updated code with namespaces from Visual Studio – Kacper G Jan 30 '19 at 16:56
  • 1
    Why do you have both Microsoft.VisualStudio.TestTools.UnitTesting and NUnit.Framework? Probably only need to be referencing one of these. – PhilS Jan 30 '19 at 16:58
  • 1
    If you are using NUnit then the class should have a [TestFixture] with the method having [Test] and attributes – PhilS Jan 30 '19 at 17:00
  • If you are using Microsoft.VisualStudio.TestTools.UnitTesting its [TestClass] for the the class and [TestMethod] for the test method – PhilS Jan 30 '19 at 17:02
  • I've changed [TestClass] to [TestFixture] and still nothing... – Kacper G Jan 30 '19 at 17:03
  • and I've added [TestFixture] to BaseTestCaseTemplate class - still nothing. – Kacper G Jan 30 '19 at 17:04
  • I will guess you may need to have SetUp in your Test class and from it call base.SetUp like shown in this asnwer: https://stackoverflow.com/questions/17659213/nunit-and-setup-in-base-classes – JanT Jan 30 '19 at 17:08
  • Which test runner are you using? Is it identifying the test classes and test methods? – PhilS Jan 30 '19 at 18:10
  • The solution: https://stackoverflow.com/questions/51967866/visual-studio-15-8-1-not-running-ms-unit-tests – Kacper G Jan 31 '19 at 10:25

0 Answers0