# 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:
To get started, you need to complete the following prerequisites checklist:
TestProject SDK for C# is available via NuGet.
Manage NuGet Packages...
TestProject SDK
and add it to your project.A test class has to implement one of the following interfaces:
TestProject.SDK.Tests
├── IWebTest
├── IAndroidTest
└── IIOSTest
Here is an example of creating & running a test class implementing the IWebTest
interface. \
This test performs a login and expects a logout button to appear:
using OpenQA.Selenium;
using TestProject.Common.Attributes;
using TestProject.Common.Enums;
using TestProject.SDK;
using TestProject.SDK.Tests;
using TestProject.SDK.Tests.Helpers;
namespace MyFirstExample
{
public class Program
{
static void Main(string[] args)
{
using (Runner runner = new RunnerBuilder("YOUR-DEV-TOKEN")
.AsWeb(AutomatedBrowserType.Chrome).Build())
{
runner.Run(new BasicTest());
}
}
[Test(Name="Basic Test")]
class BasicTest : IWebTest
{
public ExecutionResult Execute(WebTestHelper helper)
{
// Get driver initialized by TestProject Agent
// No need to specify browser type, it can be done later via UI
var driver = helper.Driver;
driver.Navigate().GoToUrl("https://example.testproject.io/web/");
driver.FindElementByCssSelector("#name").SendKeys("John Smith");
driver.FindElementByCssSelector("#password").SendKeys("12345");
driver.FindElementByCssSelector("#login").Click();
if (driver.FindElements(By.CssSelector("#logout")).Count > 0)
return ExecutionResult.Passed;
return ExecutionResult.Failed;
}
}
}
}
Below are links to other examples with complete source code:
To debug or run the test, you will have to use the Runner class. \
Here' is an NUnit
example that executes the BasicTest
shown above:
using NUnit.Framework;
using TestProject.Common.Enums;
using TestProject.SDK.Examples.Web.Runners.Nunit.Base;
namespace TestProject.SDK.Examples.Runners.Nunit
{
public class BasicTests
{
Runner runner;
[OneTimeSetUp]
public void SetUp()
{
runner = new RunnerBuilder(DevToken).AsWeb(AutomatedBrowserType.Chrome).Build();
}
[Test]
public void TestLogin()
{
runner.Run(new BasicTest());
}
[OneTimeTearDown]
public void TearDown()
{
runner.Dispose();
}
}
}
Below are examples for initialization of other Runner types:
Desktop Web
var runner = new RunnerBuilder("DEV_TOKEN")
.AsWeb(AutomatedBrowserType...).Build();
Android
var runner = new RunnerBuilder("DEV_TOKEN")
.AsAndroid("DEVICE_UDID", "APP_PACKAGE", "ACTIVITY").Build();
Chrome on Android
var runner = new RunnerBuilder("DEV_TOKEN")
.AsAndroidWeb("DEVICE_UDID").Build();
iOS
var runner = new RunnerBuilder("DEV_TOKEN")
.AsIOS("DEVICE_UDID", "DEVICE_NAME", "APP_BUNDLE_ID").Build();
Safari on iOS
var runner = new RunnerBuilder("DEV_TOKEN")
.AsIOSWeb("IOS_DEVICE_ID", "IOS_DEVICE_NAME").Build();
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 our dashboards.
Reports can be completely disabled via RunnerBuilder
, for example:
var runner = new RunnerBuilder("DEV_TOKEN")
.WithReportsDisabled()
.AsWeb(AutomatedBrowserType...)
.Build();
There are more options to disable reporting of specific entities. \ See Disabling Reports section for more information.
The SDK will attempt to infer Project and Job names from NUnit / MSTest / XUnit attributes. \ If found, the following logic and priorities take place:
Runner
is created, is used for Project name.Runner
is created, is used for the Job name.Test
attribute on the class is used for the Test name.Examples of implicit Project & Job names inferred from annotations:
Project and Job names can be also specified explicitly using the relevant options in RunnerBuilder
, for example:
var runner = new RunnerBuilder("DEV_TOKEN")
.WithProjectName("My First Project")
.WithJobName("My First Job")
.AsWeb(AutomatedBrowserType...)
.Build();
You can specify a Project, a Job name or both. If you don't, the value will be inferred automatically. \ See Implicit Project and Job Names section for more information on how these names are inferred.
Examples of explicit Project & Job names configuration:
Tests are reported automatically when a test ends, in other works, when Runner.Run()
method execution ends.\
Test names are inferred from the [Test]
attribute's Name property if it is present, or from the test class name.
This behavior can't be overridden or disabled at this time.
Each call to Runner.Run
will create a separate test in a job report. \
Even calls in the same testing framework method behave this way.
For example, following NUnit based code, will generate the following four tests in the report:
class Test : IWebTest
{
[Parameter] public string url;
public ExecutionResult Execute(WebTestHelper helper)
{
helper.Driver.Navigate().GoToUrl(url);
return ExecutionResult.Passed;
}
}
class TestRunner {
Runner runner;
TestRunner()
{
runner = new RunnerBuilder("DevToken")
.AsWeb(AutomatedBrowserType.Chrome).Build();
}
[Test]
public void RunGoogle()
{
var test = new Test() {url = "http://www.google.com"};
runner.Run(test);
}
[Test]
public void RunTestProject()
{
var test = new Test() {url = "http://testproject.io"};
runner.Run(test);
}
[Test]
public void RunAll()
{
var test = new Test() {url = "http://www.google.com"};
runner.Run(test);
test = new Test() {url = "http://testproject.io"};
runner.Run(test);
}
[OneTimeTearDown]
public void TearDown()
{
runner.Dispose();
}
}
Report:
Report
├── RunGoogle
│ └── Navigate To https://google.com/
├── RunTestProject
│ └── Navigate To http://testproject.io
└── RunAll
├── Navigate To https://google.com/
└── Navigate To http://testproject.io
Steps are reported automatically when driver commands are executed. \ Even if this feature is disabled, or in addition, steps can still be reported manually
Notice the following line in the Extended Test example. \ This line reports a step based on provided condition and takes a screenshot:
helper.Reporter.Step("Profile information saved", profilePage.Saved, TakeScreenshotConditionType.Always);
Using the following code one can set test result message:
report.Result = "Test completed successfully";
Reporting can be disabled during Runner creation.\ If reporting was explicitly disabled when the runner was created, it can not be enabled later.
The following will create a runner with all types of reports disabled (except manual step reports):
var runner = new RunnerBuilder("DEV_TOKEN")
.WithReportsDisabled()
.Build();
Disabling commands reporting will result in tests reports with no steps, unless they are reported manually using helper.Reporter.step()
.
The following will disable driver commands reporting:
var runner = new RunnerBuilder("DEV_TOKEN")
.WithDriverCommandReportingDisabled()
.Build();
You can set custom capabilities that will be used by selenium/appium when opening the session. \
Please note that you can't override basic options like browserName
using this technique
using OpenQA.Selenium;
using TestProject.SDK;
using TestProject.Common.Enums;
var options = new ChromeOptions();
// Setting custom capability - Headless Chrome
options.AddArguments("--headless");
using (var runner = new RunnerBuilder("MY_TOKEN")
.AsWeb(AutomatedBrowserType.Chrome)
.WithOptions(options)
.Build())
TestProject SDK For C# is licensed under the LICENSE file in the root directory of this source tree.