Skip to content

bart-tricentis/csharp-opensdk

 
 

Repository files navigation

TestProject OpenSDK For C#

TestProject is a Free Test Automation platform for Web, Mobile and API testing. To get familiar with TestProject, visit our main documentation website.

The TestProject OpenSDK is a single, integrated interface to scripting with the most popular open source test automation frameworks.

From now on, you can effortlessly execute Selenium and Appium native tests using a single automation platform that already takes care of all the complex setup, maintenance and configs.

With one unified SDK available across multiple languages, developers and testers receive a go-to toolset, solving some of the greatest challenges in open source test automation.

With the TestProject OpenSDK, users save a bunch of time and enjoy the following benefits out of the box:

  • 100% open source and available as a NuGet dependency.
  • 5-minute simple Selenium and Appium setup with a single Agent deployment.
  • Automatic test reports in HTML/PDF format (including screenshots).
  • 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.

Getting Started

To get started, you need to complete the following prerequisites checklist:

Installation

The TestProject C# OpenSDK is available via NuGet.

This OpenSDK supports .NET Standard 2.0 and newer.

Test Development

Using a TestProject driver is identical to using a Selenium driver. Changing the import statement is enough in most cases.

The following examples use the ChromeDriver, but they are applicable to all other supported drivers.

Here's an example of how to create a TestProject version of ChromeDriver:

// using OpenQA.Selenium.Chrome; <-- Replaced
using TestProject.OpenSDK.Drivers.Web;
using ChromeOptions = OpenQA.Selenium.Chrome.ChromeOptions;

...

public class MyTest {
  ChromeDriver driver = new ChromeDriver(chromeOptions: new ChromeOptions());
}

Drivers

The TestProject OpenSDK overrides standard Selenium/Appium drivers with extended functionality. Below is the packages structure containing all supported drivers:

TestProject.OpenSDK.Drivers
├── Web
│   ├── ChromeDriver
│   ├── EdgeDriver
│   ├── FirefoxDriver
│   ├── InternetExplorerDriver
│   ├── SafariDriver
│   └── RemoteWebDriver
├── Android
│   └── AndroidDriver
├── Generic
│   └── GenericDriver

The GenericDriver can be used to run non-UI tests and still report the results to TestProject.

Development Token

The OpenSDK uses a development token for communication with the Agent and the TestProject platform. Drivers search the developer token in an environment variable TP_DEV_TOKEN. This token can be also provided explicitly using the constructor:

ChromeDriver driver = new ChromeDriver(token: "your_token_goes_here");

Remote Agent

By default, drivers communicate with the local Agent listening on http://localhost:8585.

The Agent URL (host and port) can be also provided explicitly using this constructor:

ChromeDriver driver = new ChromeDriver(remoteAddress: "your_address_and_port_go_here");

It can also be set using the TP_AGENT_URL environment variable.

Reports

The TestProject OpenSDK reports all driver commands and their results to the TestProject Cloud. Doing so allows us to present beautifully designed reports and statistics in its dashboards.

Reports can be completely disabled using this constructor:

ChromeDriver driver = new ChromeDriver(disableReports: true);

Implicit Project and Job Names

By default, the OpenSDK will attempt to infer Project and Job names when you're using NUnit, MSTest or XUnit as a testing framework.

If any of these unit testing frameworks is detected, the following reporting settings will be inferred:

  • The project name will be equal to the final segment of the namespace that your test class is part of. For example, if your test class is in the TestProject.OpenSDK.Example namespace, the project name will be equal to Example.
  • The job name will be equal to the name of your test class.
  • The test name will be equal to the name of your test method.

Examples of implicit project and job names inferred from annotations:

Explicit Names

Project and job names can also be specified explicitly using this constructor:

ChromeDriver driver = new ChromeDriver(projectName: "your_project_name", jobName: "your_job_name");

Examples of explicit project and job name configuration:

Tests Reports

Automatic Tests Reporting

Tests are reported automatically when a test ends or when driver quits. This behavior can be overridden or disabled (see the Disabling Reports section below).

In order to determine whether a test has ended, the call stack is inspected, searching for the current test method. When the test name is different from the latest known test name, it is concluded that the execution of the previous test has ended. This is supported for MSTest, NUnit and XUnit.

Manual Tests Reporting

To report tests manually, you can use the driver.Report().Test() method, for example:

ChromeDriver driver = new ChromeDriver(chromeOptions: new ChromeOptions());
driver.Report().Test("My First Test");

It is important to disable automatic tests reporting when using the manual option to avoid any collision.

Steps

Steps are reported automatically when driver commands are executed. If this feature is disabled, or in addition, manual reports can be performed, for example:

ChromeDriver driver = new ChromeDriver(chromeOptions: new ChromeOptions());
driver.Report().Step("User logged in successfully");

Disabling Reports

If reports were not disabled when the driver was created, they can be disabled or enabled later. However, if reporting was explicitly disabled when the driver was created, it can not be enabled later.

Disable all reports

This will disable all types of reports:

ChromeDriver driver = new ChromeDriver(chromeOptions: new ChromeOptions());
driver.Report().DisableReports(true);

Disable automatic test reports

This will disable automatic test reporting. All steps will end up in a single test report, unless tests are reported manually using driver.Report().Test():

ChromeDriver driver = new ChromeDriver(chromeOptions: new ChromeOptions());
driver.Report().DisableAutoTestReports(true);

Disable driver command reports

This will disable driver command reporting. The resulting report will have no steps, unless reported manually using driver.Report().Step():

ChromeDriver driver = new ChromeDriver(chromeOptions: new ChromeOptions());
driver.Report().DisableCommandReports(true);

Disable command redaction

When reporting driver commands, the OpenSDK performs redaction of sensitive data (values) sent to secured elements. If the element is one of the following:

  • Any element with type attribute set to password
  • With XCUITest, on iOS an element type of XCUIElementTypeSecureTextField

the values sent to these elements will be converted to three asterisks - ***. This behavior can be disabled as follows:

ChromeDriver driver = new ChromeDriver(chromeOptions: new ChromeOptions());
driver.Report().DisableRedaction(true);

SpecFlow support

The OpenSDK also supports automatic reporting of SpecFlow features, scenarios and steps through the TestProject OpenSDK SpecFlow plugin.

After installing the plugin package using NuGet, SpecFlow-based scenarios that use an OpenSDK driver will be automatically reported to TestProject Cloud.

When the plugin detects that SpecFlow is used, it will disable the reporting of driver command and automatic reporting of tests.

Instead, it will report:

  • A separate job for every feature file
  • A test for every scenario in a feature file
  • All steps in a scenario as steps in the corresponding test

Steps are automatically marked as passed or failed, and Scenario Outlines are supported to create comprehensive living documentation from your specifications on TestProject Cloud.

A working example project can be found here.

Examples

More usage examples for the OpenSDK can be found here:

License

The TestProject OpenSDK For C# is licensed under the LICENSE file in the root directory of this source tree.

Packages

No packages published

Languages

  • C# 99.2%
  • Other 0.8%