- Setup Project Skeleton
- Add Initial Libraries
- Write first Tests
- Visual Studio 2015 (Community Edition should be fine)
- Resharper (optional)
- Chrome driver
- Skills Prerequisite
- Knowledge of Nuget package installation
- Basic C# knowledge/ OOP concept (classes, Methods, Properties)
- Knowledge of Unit Test frameworks
Setup Project Skeleton
If you don’t have Visual studio installed, Get Visual studio from this URL, choose default installation type and install: https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx
ADD FIRST PROJECT
After installation, start Visual studio. We will start by creating a solution then add 3 projects.
- From the File menu > new project
- Select C# project
- Class library project and give it any name
This First project will contain reusable modules that can be used in other UI projects. Example will be logging functionality, Reporting, Emailing etc.
Add Second and Third project
The Second project will contain ‘Application Under Test’ (AUT) specific classes and libraries example will be Appium client libraries to drive a mobile automation project, but it will not need to be present in web automation projects. It will also contain the page objects specific to the AUT. This project will depend on the first project.
The third project will contain our Framework Automated Functional tests and Unit tests (Please note this is not the AUT specific Regression Tests Script) As I have previously said, we need to practice what we preach and test our framework before packaging and deployment. This project will depend on the first 2 projects.
Add Project Reference to TatAutomationFramework.Web
- Right click on the project and Select add reference
- Select Projects and solutions
- Select TatAutomationFramework.Common
Add Project Reference to TatAutomationFramework.Test
- Right Click on the solution
- Select manage nugget packages, make sure browse is selected
- Add the following packages:
- Selenium.Webdriver – (.Common, . Web)
- Selenium.Support – (.Common, . Web)
- Nunit (Version 3.4 at the time of tutorial) – (. Web and .Test Projects)
- WebDriver.ChromeDriver.win32 – (.Test Projects)
We need to also add the NUnit 3 adapter for visual studio so it can discover our tests
- Go to tools > select extension and updates
- Select online
- Search nunit.
Write First Tests
The TestBase Class
- Add a class to the .Web project name it TestBase – All Test will inherit from this class. All the Test initialization and CleanUp will be running from this class. This will avoid repeating the same setup and Cleanup functions in every testClass and keep our tests looking good. We will make it an abstract class because we don’t want instance of the class getting created.
- Add the following references to the class: System; NUnit.Framework; OpenQA.Selenium; OpenQA.Selenium.Chrome;
- Add the following properties and methods (you can name it however you please)
The TestSetup Class
- Add a class to the .Test project call it TestSetup: This Class will contain the activities we want to run once before any test is ran, and once after all the tests have finished running. It is essential to have this in the same namespace as all the tests, hence this belongs to the Test Project, however, we will call the static methods from our TestBase class.
- Add the following references to the class: System; NUnit.Framework; TatAutomationFramework.Web;
- Add the methods as shown
- Build your solution to ensure it is compiling correctly.
- Add another class to the .Test project call it anything (NavigationTests.cs?): This Class will contain our actual tests, it will extent the TestBase abstract class. From our TestBase we can see that every single test navigates to the url of our AUT and cleans up any cookie traces afterwards. This is an essential concept in Automation testing. Remember point number 18 from the Framework overview?
- We will provide ways to ensure tests are repeatable by ensuring they start and end from a known state of the Application under test
- Add the following references to your test class NUnit.Framework; TatAutomationFramework.Web
- Your first Test should look as shown, though empty, it can actually drive a browser!
- Run your first test by right clicking anywhere in the method
- Go to your test explorer, when you see the green, then you are all setup.
If you cannot find your test explorer go to Test > Windows.
Now That the initial project is setup, we are ready to start work on our actual application described here in the previous post.
Click here to be the first to know when it is published.
Any thoughts, questions, comments, addition, or anything you don’t like, do not hesitate to leave a comment or contact me. Thank you!