.NET MSTest

Installation

We need to include the MSTest kit by using:

dotnet add package CloudBeat.Kit.MSTest

Install a specific version of a package

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

Initialization

import:

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

Inherit the CbTest class and wrap the webdriver:

```csharp
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:

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

Use attribute [CBStep] to describe your test case:

```csharp
		[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:

```csharp
        [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

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

Creating MSTest project in Cloudbeat

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

Projects

Decide who will have accessibility to this project

Upload the binaries as a zip

Add assembly names and finish

And that's how you have a new MSTest project

Running Test Cases

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

Running Tests Cases

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

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

Last updated