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: http://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!