The TestProject OpenSDKย allows you to execute your Selenium and Appium tests using the power of the TestProject platform. This means you’ll benefit from automatic test reporting in HTML and PDF, automatic updates and configuration of your Selenium browser drivers, collaborative reporting dashboards, and much more, all using a single, free and open-source SDK. Recently, a new member of the OpenSDK family has been released: the TestProject C# OpenSDK ๐
In this article, we’ll take a look at how to get started with this brand new C# SDK. We’ll first see how we can convert an existing Selenium-based test to a TestProject-powered test, and then we will explore some of the reporting features of the SDK.
๐ฅ Watch this live hands-on webinar recording to get started with the TestProject C# OpenSDK! ๐ฅ
Table of Contents
- Installing the TestProject C# OpenSDK
- Configuring your TestProject Agent and Developer Token
- Creating and running your first test
- Inspecting the test reports in the cloud
- SpecFlow support
- Summary
- Hands-on webinar recording + full presentation slides attached!
Installing the TestProject C# OpenSDK
The TestProject C# OpenSDK is 100% free and open-source and is available as a NuGet package.
When you add this package to your C# project, either through the NuGet package manager in Visual Studio or by using the command line, the SDK, as well as its dependencies, will be added to your project or solution.
Configuring your TestProject Agent and Developer Token
As with the other TestProject OpenSDKs (Python and Java), tests are run using the TestProject Agent, which takes care of browser driver detection, installation and configuration and sends reports to TestProject Cloud. The TestProject Agent can be downloaded from here.
By default, the SDK will communicate with the Agent on its default address, which is http://localhost:8585. If you’re running the Agent on another port, or even an entirely different machine, you can configure the correct address by setting the TP_AGENT_URL environment variable to the correct address.
After installing and registering the Agent (watch this great quick video to see it in action and learn even more about the Agent’s power), you will also need to generate and configure a developer token. You can get this token from https://app.testproject.io/#/integrations/sdk and either set it in the TP_DEV_TOKEN environment variable, or pass it explicitly in your test code when you create a new driver.
Creating and running your first test
Now that all setup work is done, let’s take the C# OpenSDK for a spin ๐คธโโ๏ธ
Here is an example test, using Selenium and the NUnit unit testing framework, that opens the TestProject demo application, logs in, and checks that a greeting message is displayed:
namespace TestProject.OpenSDK.Examples.NUnit { using NUnit.Framework; using OpenQA.Selenium; using TestProject.OpenSDK.Drivers.Web; [TestFixture] public class ExampleTest { private ChromeDriver driver; [SetUp] public void StartBrowser() { this.driver = new ChromeDriver(); } [Test] public void ExampleTestUsingChromeDriver() { this.driver.Navigate().GoToUrl("https://example.testproject.io"); this.driver.FindElement(By.CssSelector("#name")).SendKeys("John Smith"); this.driver.FindElement(By.CssSelector("#password")).SendKeys("12345"); this.driver.FindElement(By.CssSelector("#login")).Click(); Assert.IsTrue(this.driver.FindElement(By.CssSelector("#greetings")).Displayed); } [TearDown] public void CloseBrowser() { this.driver.Quit(); } } }
๐ก For those of you that are familiar with developing Selenium-based tests in C#, this code will probably be easy to understand. The most important thing is that we use the ChromeDriver class from the TestProject OpenSDK, rather than the same class from Selenium itself. This is the only thing you need to change in your existing tests to start using the power of the TestProject platform.
Inspecting the test reports
Once your TestProject Agent and the corresponding development token have been configured, the Agent will automatically report your test results to the TestProject cloud. After running the above test, if you go to the Reports tab, you’ll see a project called ‘NUnit’:
๐ก Note: The C# OpenSDK supports automatically inferring project and job names for all major C# unit testing frameworks, i.e., MSTest, NUnit and xUnit.NET. The project name, unless explicitly specified, is the last section of the namespace that the current test is in (hence in this case ‘NUnit’). The automatically inferred job name is the name of the class that the test method is in, in this case, ‘ExampleTest’.
If you open this ‘NUnit’ project, you’ll see the ‘ExampleTest’ job, corresponding test executions, and the tests that have been run as part of these:
As you can see, adding the OpenSDK to our C# Selenium-based test and running it through the TestProject Agent produced a detailed report containing all the driver commands that were executed during this test.
Like the other OpenSDKs, the TestProject C# OpenSDK offers a variety of options to customize your reporting. These options have been described in an article covering the Python OpenSDK. All options and settings described in that article are available in the C# OpenSDK, too.
SpecFlow support
An incredibly exciting feature of the TestProject C# OpenSDK is that it does not only support the major C# unit testing frameworks MSTest, NUnit, and xUnit.NET, but that it offers cloud reporting of SpecFlow-based tests, too. What exactly this entails, you will read in an upcoming article, coming soon! ๐๐
Summary
As we’ve seen in this tutorial, with just one unified SDK (that’s also available in Java and Python, by the way), developers and testers receive a go-to toolset, solving some of the greatest challenges in open-source test automation. Using this SDK will save you a lot of time, with the following benefits that come out of the box:
* Open source and available as a Maven dependency / a NuGet package / a PyPI project.
* 5-minute simple Selenium and Appium setup with a single Agent deployment.
* Automatic test reports in HTML/PDF format (including screenshots and customization capabilities).
* Collaborative reporting dashboards with execution history and RESTful API support.
* Always up-to-date with the latest and stable Selenium driver version.
* A simplified, familiar syntax for both web and mobile applications.
* Complete test runner capabilities for both local and remote executions, anywhere.
* Cross-platform support for Mac, Windows, Linux, and Docker.
* Ability to store and execute tests locally on any source control tool, such as Git.
For those of you who prefer watching tutorials โ You should definitely watch this hands-on webinar recording hosted by Bas Dijkstra and Matthias Rappย โจ
๐ Get the Presentation Slidesย ๐
I liked this OpenSDK very much, easier to build the tests integrated with the TestProject Agent.
I still have a question that I couldn’t find here: what if I want to build using Test Project’s TDD with data coming from csv file for example? In the previous SDK you have, for example:
[ParameterAttribute(DefaultValue = “NotFound”, Direction = ParameterDirection.Input)]
public string machineName;
But I downloaded the new SDK and couldn’t find this. Is there any topic related to this in the new SDK?
Thanks in advance!
Luiz Waldrich
I was reading https://docs.testproject.io/testproject-sdk/overview/sdk-v1-vs-opensdk-v2 and I found my answer =)