In my WebDriver Series, you can find lots of useful information about how to use Selenium WebDriver for UI automation. As you probably know one of the newest and coolest Microsoft technologies is .NET Core. However, prior the release of Visual Studio 2017 Preview 2 we were unable to run WebDriver tests using .NET Core projects. In this article, I am going to show you how to combine them and "experience the future".

What Problem Are We Trying to Solve? If you use Visual Studio 2017 15.2 and try to create .NET Standard library, by default the library targets .NETStandard 1.4.

When you try to install the Selenium.WebDriver NuGet the following error occurs.

Old NuGets that target .NET Framework are not compatible with applications that target .NET Core or .NET Standard < 2.0. From 2.0 version and above Microsoft will make them work. So our goal here will be to upgrade our projects to .NETStandard 2.0. Two years ago while we were working on the first version of the BELLATRIX test automation framework, I did this research so that we can be sure that the framework can run on both Windows and OSX. Selenium WebDriver + .NET Core First, you will need to install Vis﻿ual﻿ Studio 2017 Preview 2. This is an early access version of the tooling where .NET Core 2.0 and .NET Standard 2.0 are supported. This means that you will be able to combine .NET Core applications with .NET Framework NuGets that do not have .NET Core support. This is the case of Selenium.WebDriver. Also, you can download the .NET Core SDK and command line tools. I will show you later how you can use them to run simultaneously tests that use different test frameworks such as MSTest, NUnit and XUnit. When you are ready, create a new .NET Standard class library and open the project's Properties. You will need to change the target framework to .NETStandard 2.0.

Install WebDriver NuGets I will show you how to configure the most common drivers- FirefoxDriver, ChromeDriver and EdgeDriver. So we will need to install a couple of NuGets to do that. One of the coolest new feature of the .NET Core tooling is that the package.config is gone and all packages are referenced directly in the project's MSBuild file. Moreover, you can edit the project files without unloading and reloading the projects.

When you run your tests, you will notice that error about System.Security.Permissions DLL occurs. To fix it, you need to install the System.Security.Permissions NuGet package (the prerelease version). Install MSTest Framework NuGets You need to install the MSTest.TestFramework and MSTest.TestAdapter NuGets. Through the later, you will see your tests in the Test Explorer window. Install NUnit Framework NuGets For NUnit, you need the NUnit and NUnit3TestAdapter NuGets. Make sure that you check the "Include prerelease" checkbox in the NuGet Packages Window. You will need to install an alpha version of the NUnit test adapter. The older(stable) versions are not compatible with .NET Core.

Install xUnit Framework NuGets Similar to others you need xunit and xunit.runner.visualstudio packages to be able to run XUnit tests. Finally, you need one last NuGet package so that you can execute tests from .NET Standard class library- Microsoft.NET.Test.Sdk. Below you can find the list of all references, you need only to copy them to your project file, and they will be installed automatically.

Configure Different Selenium Drivers FirefoxDriver You can use FirefoxDriver without any problems but as you will see this is not the case for the rest of the drivers.

ChromeDriver If you use the default constructor of ChromeDriver, the following exception is thrown. Message: OpenQA.Selenium.DriverServiceNotFoundException : The chromedriver.exe file does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at http://chromedriver.storage.googleapis.com/index.html. This happens because the NuGet packages for .NET Core projects are loaded from a global place instead of the packages folder of the .NET Framework projects. To fix it, we need to specify the path to the execution folder.

EdgeDriver A similar exception is thrown for the EdgeDriver, the fix is similar.

MSTest Tests in .NET Core

NUnit Tests in .NET Core

xUnit Tests in .NET Core