> For the complete documentation index, see [llms.txt](https://docs.cloudbeat.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cloudbeat.io/supported-testing-frameworks/dotnet-mstest.md).

# .NET MSTest

{% hint style="success" %}
The steps on this page can be done for you by an AI coding agent: see [AI-Assisted Project Setup](/get-started/ai-assisted-project-setup.md).
{% endhint %}

## Installation

We need to include the MSTest kit by using:

```
dotnet add package CloudBeat.Kit.MSTest
```

### Install a specific version of a package <a href="#install-a-specific-version-of-a-package" id="install-a-specific-version-of-a-package"></a>

```
dotnet add package CloudBeat.Kit.MSTest --version 4.7.0
```

## Initialization

import:

```
using CloudBeat.Kit.MSTest;
```

Inherit the CbTest class and wrap the webdriver:

```
namespace CbExamples.MSTest.Infra
{
    [TestClass]
    public abstract class WebDriverTest : CbTest
    {
        private IWebDriver _driver = null;

        public EventFiringWebDriver Driver { get; private set; }

        [TestInitialize]
        public void SetUpWebDriver()
        {
            ChromeOptions options = new ChromeOptions();
            _driver = new ChromeDriver(options);
            Driver = new EventFiringWebDriver(_driver);
            CbMSTest.WrapWebDriver(Driver);
        }
    }
}
```

## Applying CBStep Attribute in your test cases

Import:

```
using CloudBeat.Kit.MSTest.Attributes;
```

Use attribute **\[CBStep]** to describe your test case:

```
[CbStep("Open \"Login\" page")]
public void Open()
{
    driver.Navigate().GoToUrl(baseUrl ?? DEFAULT_BASE_URL);
}
```

You can also use variables in the step description, to do that we'll put **username** in curly braces:

```
[CbStep("Type \"{username}\" in \"Username\" field")]
public void EnterUsername(string username)
{
	var usernameFld = UsernameField;
	if (usernameFld == null)
	   Assert.Fail("Username field not found");
	usernameFld.Click();
	usernameFld.SendKeys(username);
}
```

## Create Binaries

Before uploading our project to CloudBeat, we have to create a binaries zip folder, in your project folder open cmd and run the following command:

```
dotnet build
```

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2Fgit-blob-73cfef5bb328d09d7370c8ddd2ff1475d5d24d07%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

a bin folder should be created, now go to bin -> debug and create a zip from net.6.0

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2Fgit-blob-f04f6561a79c7c7c104c45a3d5e907c065f3192b%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

## Creating MSTest project in Cloudbeat

Go to projects tab and create a new project and choose **MSTest - Binaries**

{% content-ref url="/pages/-Luhc-7l\_JV43u6esfU6" %}
[Projects](/references/projects.md)
{% endcontent-ref %}

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2Fgit-blob-155c832dc305b03f9ce1c445d422ff0a1962e3d3%2F2024-03-31%2015_35_47-Projects%20-%20CloudBeat.jpg?alt=media" alt=""><figcaption></figcaption></figure>

Decide who will have accessibility to this project

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2Fgit-blob-ab25f705ca351f053c5891bfceaab848de74bf0c%2F2024-03-31%2015_37_40-Projects%20-%20CloudBeat.jpg?alt=media" alt=""><figcaption></figcaption></figure>

Upload the binaries as a zip

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2Fgit-blob-2634c6001fe04d705d038787226023ad327b6311%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Add assembly names and finish

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2Fgit-blob-d76f72908fc54e24c5af8797bcc7d999f55e87f2%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

And that's how you have a new MSTest project

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2Fgit-blob-f44d7fd957f0f44954d1ef5455324a0c4b1fb02a%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

## Running Test Cases

Go to Cases under Testing tab, there you will see all your test cases

{% content-ref url="/pages/-LuhLvlMu9fDYoHu0rJI" %}
[Running Tests Cases](/fundamentals/executing-tests.md)
{% endcontent-ref %}

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2Fgit-blob-e404ba9a1a9bbf76603592f0645c0ae43c64ee2a%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Select a browser to run your test on, save changes and run

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2Fgit-blob-bd6c904985e6d90b5e3636d4a2503f98f57c06d7%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

You will see the results based on the **\[CbSteps]** that were added in your project

<figure><img src="https://1835512707-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LuDeDlFo7eLPBFbUgtb%2Fuploads%2Fgit-blob-986b51d1feb1a83044dc40a47a0583adb12f8ff0%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
