NUnit (C#) integration with Asayer.
- Prerequisites
- Set it up
- Run it
- Dashboard
- Application Parameters
- Capabilities
- Integrating Asayer with your existing project
- Local Testing
- Mark Session
- Dependencies
- Troubleshooting
- Important Notes
- Microsoft Visual Studio 2012 or higher (you can download the Community Edition for free)
- Clone the repo
git clone https://github.com/asayer-io/asayer-nunit
or download it - Open the solution
asayer-nunit/asayer-nunit.sln
in Visual Studio - Build it (Build > Build Solution, which will automatically install the required NuGet packages)
- Update the
App.config
file with your Asayer API key
To run the test, proceed as follows:
- Build the project (Build > Build Solution)
- Open the Test Explorer window (Test > Windows > Test Explorer)
- Right click on the
CheckProductPage
test and choose Run Selected Tests - Go to https://dashboard.asayer.io/automate/sessions and see what happened.
Details about the test session can be found in the Dashboard under Automate > Sessions.
This is where all your executed tests are listed. You can use the filter to navigate through Passed or Failed tests (see Mark Session to learn how to mark a test).
Encloses various details like State, Duration, Execution Time, Platform/Browser as well as the User who initiated the test.
Each session gets fully recorded. The video can be played or downloaded (as part of the Assets).
All commands gets displayed in the form of a comprehensive timeline, including details such as Execution Time, Duration and Screenshot.
A screenshot is taken automatically upon the execution of each and every command. Simply hover over the cam icon to see it.
Various actions (i.e. HTTP) taking place throughout the session, are logged.
Chrome and Opera console logs are captured and displayed back.
Clicking on the Download Assets button will download a zip file enclosing:
- All screenshots
- Session recording (.webm)
- Server logs
- Browser console logs (only Chrome and Opera)
The list of your active tunnels is available in Settings > Tunnels. For more information, see Local Testing.
You can change the app settings from the App.config
file under <appSettings>
.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
...
<appSettings>
<add key="apikey" value="YOUR ASAYER API KEY" />
<add key="server" value="https://hub.asayer.io/wd/hub" />
<add key="name" value="Testing NUnit with Asayer" />
...
</appSettings>
...
</configuration>
Belows are the supported settings:
Name | Value | Description | Required |
---|---|---|---|
apikey |
Your Asayer API key | yes | |
server |
https://hub.asayer.io/wd/hub |
Asayer's Selenium hub | yes |
name |
The name of the test to execute (will be visible in the Dashboard) | yes | |
build |
The build's ID (if any) | no | |
tunnelId |
The tunnel's ID for local tests | yes for (local testing) |
You can change the caps from the App.config
file under <capabilities><settings>
.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
...
<capabilities>
<settings>
<add key="platform" value="linux" />
<add key="browserName" value="chrome" />
...
<settings>
</capabilities>
...
</configuration>
Below is the list of supported capabilities:
Name | Possible Values | Default Value | Description | Required |
---|---|---|---|---|
platform |
linux windows mac android ios any |
linux | The platform used for the test | yes |
browserName |
chrome firefox ie safari opera edge |
chrome | The browser used for the test | yes |
seleniumVersion |
2.53.1 , latest |
latest |
The selenium version used for the test | no |
browserVersion |
see the list of supported browser versions | latest |
The browser version used for the test | no |
flags |
- | A list of flags to be passed to the browser, see Fun with Flags | no | |
deviceName |
see the list of supported mobile devices | - | The android device name to use for the test | yes if platform is set to android or ios |
The list of supported browser versions are:
Name | Versions |
---|---|
edge | 15 |
opera | 48 |
firefox | 47 , 56.0.1 |
chrome | 62 |
ie | 11 |
safari | 11 |
The list of available mobile simulators/emulators is as below:
platform | deviceName |
---|---|
android |
Galaxy_S8 , LG_G6 , Pixel , Pixel_XL , Pixel_C , Nexus_5X , Nexus_6P Nexus_9 |
ios |
iPhone 5 , iPhone 5s , iPhone 6 , iPhone 6 Plus , iPhone 6s , iPhone 6s Plus , iPhone 7 , iPhone 7 Plus , iPhone SE , iPad Air , iPad Air 2 , iPad Pro |
Note: Only Android 7.1.1
and iOS 10.3
are supported.
In addition to the above mentioned capabilities, you can attach a list of <flags>
(to run the browser with) by simply adding <add key="[FLAG NAME]" value="[value|]" />
to the App.config
file under <capabilities><flags>
.
In the following example, we used some of the Chrome flags:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
...
<capabilities>
...
<flags>
<add key="--incognito" value="true" />
<add key="--start-fullscreen" value="true"/>
...
</flags>
</capabilities>
...
</configuration>
These flags will be interpreted as --incognito --start-fullscreen
(note that value=""
and value="true"
are similar).
- Kepp in mind that each browser has its own and unique list of flags:
Follow the below steps to integrate Asayer with your existing project:
- Copy the classe
AsayerWebDriver.cs
to your project - Have the required NuGet dependencies installed
- Copy or merge the
App.config
file to/with your project, , setup the Application Parameters (here) then configure the desired Capabilities (here) - In the test definition class (see example below), extend the
AsayerWebDriver
class, this will provide you with adriver
attribute
Excerpt from MyTest.cs:
using ...
namespace asayer_nunit
{
class MyTest : AsayerWebDriver
{
[Test]
public void CheckProductPage()
{
driver.Navigate().GoToUrl("http://www.asayer.io");
...
}
}
}
Local testing allows you to test your internal servers, in addition to public URLs, using Asayer's infrastucture without having to update your firewalls or proxies.
- Download
asayer-tunnel
for Windows (32bits|64bits), Linux (32bits|64bits) or Mac (32bits|64bits) - Open a terminal and
cd
to the binary folder - Execute the binary by running
asayer-tunnel_win64.exe -k API_KEY -i TUNNEL_NAME
The complete manual for the tunnel is the following:
$ asayer-tunnel_win64.exe -h
Usage:
main [OPTIONS]
Application Options:
-k, --key= The user API_KEY
-i, --id= The id of the tunnel
-p, --port= The local proxy port (default: 9090)
-w, --whitelist= List of URLs to exclude from proxy, separated by ';' (eg: url1; url2)
--proxy-url= If you are behind a proxy set its URL here, the format is HOST:PORT.
If needed, auth info can be set in --proxy-user and --proxy-password
--proxy-user= Basic auth HTTP Proxy username
--proxy-password= Basic auth HTTP Proxy password
-v, --verbose Show debug information
Help Options:
-h, --help Show this help message
Note that only -k
and -i
parameters are required.
To set up your tests for local testing, you must add the tunnelId
capability to the App.config
file under <appSettings>
section
<?xml version="1.0" encoding="utf-8"?>
<configuration>
...
<appSettings>
...
<add key="tunnelID" value="[TUNNEL_ID]" />
</appSettings>
...
</configuration>
Once done, build then run your tests as usual. HTTP traffic will then be redirected to the machine on which the asayer-tunnel
binary is running through a secure connection.
Details about the local tests can be found in the Dashboard. Local tests are marked with a plug icon.
- Local Testing is available on
chrome
,firefox
andopera
browsers only - Only 3 active tunnels are allowed per organization
Once the session is completed, you can mark the test (either passed or failed) by calling the markSession(["Passed"|"Failed"])
method of the AsayerWebDriver
superclass.
You can also rely on our REST API to do so by submitting sessionID
and sessionStatus
parameters:
Endpoint: https://dashboard.asayer.io/mark_session
Method: POST
Json: {
sessionID:this.sessionId, // Required
sessionStatus:"Passed"|"Failed", // Required
apiKey:"YOUR ASAYER API KEY (this.apikey)", // Required
}
The state will be visible in the Dashboard:
For reporting purposes, you can call the markSession(string state, string requirementID, List<AsayerTestStatus> testStatus)
method of the AsayerWebDriver
superclass.
markSession
's parameters are:
state
: the session's staterequirementID
: the session's requirement IDtestStatus
: a List ofAsayerTestStatus
--AsayerTestStatus
is an object that contains thetestId
,testStatus
See the example below:
List<AsayerTestStatus> testStatus = new List<AsayerTestStatus>();
testStatus.Add(new AsayerTestStatus("TEST ID 1", "Passed"));
testStatus.Add(new AsayerTestStatus("TEST ID 2", "Failed"));
this.markSession("Passed", "requirementId1230", testStatus);
You can also rely on our REST API by calling:
Endpoint: https://dashboard.asayer.io/mark_session
Method: POST
Json: {
sessionID:this.sessionId, // Required
sessionStatus:"Passed"|"Failed", // Required
apiKey:"YOUR ASAYER API KEY (this.apikey)", // Required
reqID: "REQUIREMENT ID", // Required
testStatus: [ // Required
{
name: "TEST ID 1",
result: "Passed"|"Failed"
},
{
name: "TEST ID 2",
result: ""Passed"|"Failed"
},
...
]
}
All of these details can be seen in the Reporting section:
This project relies on the below dependencies:
- Selenium.WebDriver
- NUnit
- NUnit3TestAdapter
- Blun.ConfigurationManager
- Newtonsoft.Json
To install the latest version of these dependencies, go to Tools > NuGet Package Manager > Manage NuGet Packages For Solution... then search/install each one of them.
Or add the missing line to your packages.config
file:
<package id="Blun.ConfigurationManager" version="1.0.5686.2674" targetFramework="net45" />
<package id="NUnit" version="3.7.1" targetFramework="net45" />
<package id="NUnit3TestAdapter" version="3.8.0" targetFramework="net45" />
<package id="Selenium.WebDriver" version="3.5.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" />
- If you are having issues with the
MoveToElement
method on Firefox (NotImplementedException: MouseMove
), this is mainly due to the current version ofSelenium.WebDriver
, to solve this issue, you can choose one of the following solutions:- Upgrade your
Selenium.WebDriver
to a newer version (3.5.1
or newer) - Replace the
MoveToElement
method, with the code below:IJavaScriptExecutor js = (IJavaScriptExecutor)driver; string jscode = "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseover', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseover');}"; js.ExecuteScript(jscode, element);
- If you are running your Firefox tests on the
any
platform, then simply disable themarionette
, this can be done in theApp.config
file by adding<add key="marionette" value="false" />
under<capabilities><settings>
- Upgrade your
- Do not remove the
[TearDown]
from theAsayerWebDriver
class as it closes your session at the end of every test (otherwise it will timeout)