logo logo

How to Write a Functional Test with a Basic Test Automation Framework

This tutorial is the the next step in Creating a test automation framework with C#, Selenium 3 and Nunit; after creating the reporting module in the previous tutorial, we can finally start writing an automated functional test with the test automation framework we’ve just created.


Tutorial Overview:

Class 1 – Creating an Automated Test Using Selenium WebDriver 3 and C#

Class 2 – How to Create a Test Automation Framework Architecture with Selenium WebDriver 3

Class 3 – Utilizing Test Automation Framework with Advanced Capabilities


Before we begin creating a functional test, we’ll need to create a new project in the Solution, in order to have a separation between the framework’s project to the automated tests themselves.

There are two main reasons for separating the framework’s project and the tests’ project:

  1. Modularity of the code
  2. Easier to maintain a project that is dedicated to the tests

The Project will be called ‘AutomatedTestCases’. Next, change the name of the class while creating the project in Sanity.cs

It should appear as follows in the screenshot:

Creating a new project in Solution to perform a functional test

 

 

 

 

 

 

 

 

 

The automated functional tests will be executed on the blog’s page in the following url: https://blog.testproject.io

Open the file Sanity.cs and paste the following piece of code:

using NUnit.Framework;
using OpenQA.Selenium;
using Test;

namespace AutomatedTestCases
{
    [TestFixture]
    public class Sanity : AutomationCore
    {
        [Test]
        public void ClickContactUs()
        {
            Browsers.getDriver.FindElement(By.Id("menu-item-1296")).Click();
        }
    }
}

Lets get into more detail about the steps of the code above:

The first step is to include the project of the automation framework into the automated tests project. This is performed by adding ‘using Test;’

Afterwards, we’ll need to inherit from the AutomationCore, in order to make the framework and browser launch before executing any tests. Next, we’ll be starting with the automated tests.

Browsers.getDriver.FindElement(By.Id(“menu-item-1296”)).Click();

We are receiving the WebDriver from our Browser’s class and then in order to locate the element we’ll be using the FindElement method while passing the element’s Id. After we have the element we can click on it.

When the functional test is complete, the results will appear in the ‘Test Explorer’ window.

Functional test passed in the TEST EXPLORER window

 

 

 

 

 

 

 

 

 

 

 

 

 

Obviously, the report we created has to appear in the path we’ve configured for it.

Report appearing in the path we've configured for it

 

 

 

Report appearing in the path we've configured for it

 

 

 


You have now completed the last step in designing your selenium testing framework, continue on to the Next tutorial where we’ll be covering the implementation of advanced capabilities when creating a test automation framework, and specifically: Page Object Pattern: Advantages & Implementation.

I would be happy to see your questions/ ideas / stories in the comments below!


 

About the author

Asya Galinsky

Comments

8 5 comments
  • Islam October 20, 2017, 4:12 pm

    I have created two projects as mentioned in the tutorials(1

    • Islam October 20, 2017, 4:27 pm

      Hi Asya,

      Thanks for sharing such nice tutorials. There is minor refinement required as per my point of view. Your tutorials lack the complete steps defining like currently i am facing an issue which is…..I have configured two separate projects as mentioned in the tutorial and i am not able to start them because i don’t know what Output type required for each project, currently i have configured the output type of both projects as Class library.

      While i tried to start the project i am facing an error i.e. there should be one executable project. Please help me, although i have marked the Automatedtestcases project as startup project.

      After that i have marked the Output type of Automatedtestcases project as Windows Application and other one as Class library but system is doing nothing upon start.

      Regards,
      Muhammad Islam
      +92-345-4057636

      • Oren Nahum November 1, 2017, 9:16 pm

        Hi Islam,
        You don’t need to change the Output type of project.
        You don’t need to run the projects with F5 (Run) like a regular project.

        You should be running the tests from the Visual studio built in TestRunner.
        AutomatedTestCases -> ClickContactUs right click and Run

  • rose_123 May 4, 2018, 5:29 pm

    Hi Asya,
    Thanks for this tutorial. It was very helpful! I have a question for you though. Pagefactory is going to be deprecated very soon. Can you please show us how to modify the existing code in your tutorial based on that? I am asking about these specific lines:
    private static T getPages() where T : new ()
    {
    var page = new T();
    PageFactory.InitElements(Browsers.getDriver, page);
    return page;
    }

  • Jasmine James October 23, 2018, 9:00 am

    Hi,
    Thanks for the tutorial. I tried creating test cases in AutomatedTestCases project.
    Browsers.getDriver.FindElement(By.Id(“ist-ib”)) this line throws me an exception “System.NullReferenceException: ‘Object reference not set to an instance of an object”.Could you please help me to sort this problem.

Leave a Reply

FacebookLinkedInTwitterEmail