In Nunit C# Im trying to open the application only once and make modification to it, for example i created this demo of Notepad application. In my real time project,i just have to log in to the application just once and execute all 100 test cases and only then close the Desktop application. Kindly tell me what am i doing wrong here,thanks a lot! Btw,im new to C#
using NUnit.Framework;
using OpenQA.Selenium.Remote;
using System;
using OpenQA.Selenium;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace Notepad
{ }
[SetUpFixture]
public class BaseClass
{
public static IWebDriver driver;
[OneTimeSetUp]
public static void AssemblyInitalize()
{
var dc = new DesiredCapabilities();
dc.SetCapability("app", @"C:\\Windows\\System32\\notepad.exe");
driver = new RemoteWebDriver(new Uri("http://localhost:9999"), dc);
Thread.Sleep(5000);
}
[OneTimeTearDown]
public static void oneTearDown()
{
driver.FindElement(By.Id("Close")).Click();
}
}
---First Test---
namespace Notepad
{ [TestFixture]
public class Notepad2:BaseClass
{
[Test]
public void test2()
{
driver.FindElement(By.Id("15")).SendKeys("My Teacher ");
}
}
}
---- Second Test Class ----
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
namespace Notepad
{ [TestFixture]
public class NoteTest : BaseClass
{
[Test]
public void Test()
{
driver.FindElement(By.Id("15")).SendKeys("...is Coming now");
}
}
}
From the documentation, OneTimeSetup is called once before all tests in a TestFixture. Your example has two fixtures, so the set up is called twice. You need to have all your tests in the same Fixture.
This behaviour is different to the old [Setup] on SetupFixture attribute, which ran once for all tests in a namespace.