Skip to content

SabotageAndi/csharp-sdk

 
 

Repository files navigation

TestProject SDK For C#

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

TestProject SDK 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 TestProject SDK, 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 SDK supports .NET Standard 2.0 and newer.

Test Development

Using a TestProject driver is exactly 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;

...

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

Drivers

The TestProject SDK 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
├── Generic
│   └── GenericDriver

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

Development Token

The SDK 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

TestProject SDK 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 SDK 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(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(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(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(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(new ChromeOptions());
driver.Report().DisableCommandReports(true);

Disable command redaction

When reporting driver commands, the SDK 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(new ChromeOptions());
driver.Report().DisableRedaction(true);

SpecFlow support

The SDK 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 SDK 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 SDK can be found here:

License

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

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.0%
  • Other 1.0%