logo logo

Getting Started with TestProject C# OpenSDK

Getting Started with TestProject C# OpenSDK

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

  1. Installing the TestProject C# OpenSDK
  2. Configuring your TestProject Agent and Developer Token
  3. Creating and running your first test
  4. Inspecting the test reports in the cloud
  5. SpecFlow support
  6. Summary
  7. 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’:

NUnit report

๐Ÿ’ก 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:

TestProject Reports - NUnit Selenium C# Reports in Cloud

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ย ๐Ÿ‘ˆ

Avatar

About the author

Bas Dijkstra

Bas teaches companies around the world how to improve their testing efforts through test automation. He is an independent trainer, consultant and developer living in the Netherlands. When he’s not working he likes to take his bicycle for a ride, go for a run or read a good book.

Join TestProject Community

Get full access to the world's first cloud-based, open source friendly testing community. Enjoy TestProject's end-to-end test automation Platform, Forum, Blog and Docs - All for FREE.

Join Us Now  

Comments

13 2 comments

Leave a Reply

popup image

A new world for test automation

Join 150,000 testing & dev teams taking their web & mobile testing to new heights, using #1 FREE test automation platform, designed to help deliver quality at speed.
Get Started
FacebookLinkedInTwitterEmail