Repository navigation
5. Running tests from .NET
[Introduced in 0.10.0]
Ability to run JS integration tests from .NET test frameworks was introduce. It could be useful whe you want to use JS integration tests with specification written in for example in SpecFlow. In order to use this feature one need to install additional nuget package into specs project: Install-Package Sitecore.TestRunnerJS.Extensions
After that additional setting will appear in app.config file. Add your environment real values to this settings:
<!--Add full path to the Sitecore.TestrunnerJS package folder-->
<add key="Sitecore.TestRunnerJS.PackagePath" value="path_to_testrunner_package"/>
<!--Add your website under test instance name-->
<add key="Sitecore.TestRunnerJS.InstanceName" value="name_of_sitecore_instance"/>
<!--Add your SPEAK application under test name-->
<add key="Sitecore.TestRunnerJS.ApplicationName" value="name_of_speak_application"/>You are ready to use JS integration tests with your .NET testing environment. To do this just use TestRunner.Create() to create instance of TestRunner and then call Execute method with following parameters:
- Url of page under test
- Mocha.js grep that will determine which test to run
Please consider the following example with xUnit test that is running js integration test:
public class SampleTest
{
[Fact]
public void ShouldRunPhantomTest()
{
// Create instance of runner that is responsible for running JS integration tests
var runner = TestRunner.Create();
// Execute specified test
// In order to execute one should pass page under test and
// mocha grep that will filter out and run necessary tests
runner.Execute(
"/sitecore/shell/sitecore/client/Applications/SampleApp/FirstPage?sc_testrunnerjs=1",
"Another page Should load test from ActionTextBox into ResultTextBox on Action button click"
);
}
}Please take a look on Sample application. It provides example project with such a test