Mike ASP
Mike ASP

Reputation: 2333

Adding API test cases with Selenium UI test cases

Info about my project: c# , selenium 3.9 , Nunit , windows , VS 17 , RestSharp (for API)

  1. Project is developed primarily for UI test cases but now I want to add API test cases as well , Adding additional API cases because they are time consuming if doing on UI level

  2. Issue : Whenever I run my API cases then driver gets initialized and which invokes the browser , right after that my API test kicks off and at the end I see API tests is gone well and running successfully.

  3. I know I have to change my implementation on Base class but I am not sure what I am suppose to do it so my framework clearly understand that when it to invoke driver and when to skip ?? (Or I am not sure if we can do this through Nunit annotations)

  4. Expectation : when running UI cases driver should invoke and launch browser but when running API cases driver should NOT invoke and should Not launch browser

  5. Please see implementation :

ValidateUI.cs : BaseTest

[TestFixture]

public class ValidateUI : BaseTest
{

    [Test]
    public static void testUI()
    {

    }

}

ValidateAPI.cs : BaseTest

[TestFixture]

public class ValidateAPI : BaseTest
{

    [Test]
    public static void testAPI()
    {

    }

}

BaseTest.cs

[TestFixture]
public class BaseTest
{        
    [SetUp]
    public void Init()
    {
        Driver.ConfigInit();
        Driver.LogStart();
        Driver.Initialize(Settings.BrowserType);
        LoginPage.GoTo(Settings.BrowserType);
    }
      [TearDown]
    public void Cleanup()
    {      
        Driver.Close();
    }
}

Upvotes: 1

Views: 609

Answers (1)

Charlie
Charlie

Reputation: 13736

If you don't want the API tests to use the driver, then you shouldn't derive the API fixture from BaseTest where the driver is set up.

You might try an inheritance hierarchy like this...

Base Fixture
    API Base Fixture
        API Test Fixture 1
        API Test Fixture 2
            etc.
    UI Base Fixture
        UI Test Fixture 1
        UI Test Fixture 1

Base Fixture would set up logging and other common stuff.

UI Base would set up drivers, etc.

API Base would do whatever setup your API tests need

This kind of partitioning of setup is exactly what fixtures are intended to do.

Upvotes: 1

Related Questions