The fourth publication from the Design & Architecture Series is about the creation of а concrete implementation of the hybrid test framework through T﻿﻿esting﻿﻿﻿﻿﻿ Fr﻿﻿amework. Also, you will find out how to find and resolve web elements though Unity IoC Container.

Create Testing Framework Driver Implementation Create a new project- HybridTestFramework.UITests.TestingFramework. Add a reference to the core project HybridTestFramework.UITests.Core (the project that contains all main interfaces). You need to install the Unity NuGet package. Add references to all Testing Framework DLLs. Please refer to my article Getting Started with Testing Framework C# in 10 Minutes. Similar to the Selenium Driver implementation you have a partial class for every core driver interface, placed under the Engine folder.

Implement IDriver Interface Below you can find the main partial class of the Testing Framework Driver. It requires an instance of the Unity IoC Container and BrowserSettings where different execution settings are placed. I am not going to explain in details the Testing Framework related classes. You can read more about them in my T﻿﻿esting Fram﻿﻿ework Series. Based on the BrowserSettings a new Testing Framework Manager is created, and a new browser instance is started.

ElementFinderService ElementFinderService is probably one of the most important classes in the whole Testing Framework concrete implementation of the hybrid test framework. First, we convert the abstract By expression to Testing Framework's find expression through the help of the extension methods placed in the ByExtensions class. Then we wait for an element with the specified expression to show up. If such an element does not exist, we throw a new ElementTimeoutException. Through the ThrowTimeoutExceptionIfElementIsNull method, we create a meaningful expression's message where you can find the name of the not-found element and the current URL. The Find context parameter can be Find's instance of the currently active browser or the Find of a specific web element. We create a new instance of the particular Testing Framework element's implementation through the ResolveElement generic method.

You can find more about the Testing Framework's find expression in my article Getting Started with Testing Framework C# in 10 Minutes.

Implement IElementFinder Interface In the partial class for the IElementFinder interface we just call the already created instance of the ElementFinderService. We pass the currently active browser's Find context to the ElementFinderService's methods.

Implement IElement Interface The parent of all Testing Framework's web elements is the HtmlControl class. So our base Element class wraps it. The find methods return Element objects. You can convert them to the specific HtmlControl classes via the As method. As you know, you can search inside web elements so the IElement interface derives from the IElementFinder interface. Again we wrap the calls to the ElementFinderService but this time, we pass the Find context of the currently located HTML control.

Implement IBrowser Interface

The different methods in this class only wrap the Testing Framework's native methods. Implement ICookieService Interface You can use the ICookieService in your tests or pages to work with cookies. The ClearAllCookies method comes in handy to assure the clean state of your browser before tests' execution.

Implement INavigationService Interface

Compared to the Selenium Driver implementation of the hybrid test framework, I believe that Testing Framework provides more advanced navigation capabilities. As you can see their usage is straightforward. Implement IJavaScriptInvoker Interface

You can use the IJavaScriptInvoker interface in your pages or tests to invoke JavaScript code. Also, it comes in handy when you create the implementation for some more sophisticated web controls such as grids, data pickers and so on. Testing Framework Driver Implementation in Tests Register Types and Instances- Unity IoC Container

The code is copy-paste from the Selenium Driver tests examples. The only difference is that instead of SeleniumDriver, we register in Unity the new TestingFrameworkDriver implementation of the hybrid test framework's engine and controls. Test Example