Setup() runs before the test and creates a new driver. No special configuration is needed at this point.
MyFirstTest() is the actual test. It navigates to the TestProject example page, types user name and password, clicks the login button and checks the logout button is visible.
TearDown runs after the test and quits the driver. It is good practice to quit your driver once you finish using it.
That's all the code we need to write our first test!
Now let's make it run.
Running the Test
To run tests using TestProject's OpenSDK you need to first install and register the TestProject Agent (download link). You also need a development token which can be obtained here.
You can add the development token to your code, but a better way would be to specify it using an environment variable. To do this we need to add a .runsettings to the project.
The contents of the .runsettings file should be as follows:
<!-- List of environment variables we want to set-->
And that's it! Time to run our test. Here's how it's done:
Make sure your agent is running and registered.
Open the test explorer by opening the Test menu and selecting the Test Explorer option.
Press the Options button (rightmost button) and make sure Configure Run Settings -> Auto Detect runsettings File is enabled.
Press the Play button and watch your test run!
Well done, you just ran your first test!
Let's check the result and see what happened in the report.
Customize Your Report
Now that we ran our first test, let's check the report.
When you run tests that use TestProject's driver, reports are created on the platform automatically.
Here's the report that was created by our test:
As you can see, OpenSDK inferred project, job and test names all by itself and reported all driver actions as steps. Here's how it does it:
Project name is inferred from the test class' namespace - in this case it's MyFirstOpenSDKTest.NUnit
Job name is inferred from the test class name - in this case it's ExampleTest
Test name is inferred from the test method's name - in this case it's MyFirstTest
It's a great start. However, These are "programmer names" and do not look nice in the report.
Let's improve them!
Project, Job & Test Names
First, let's specify project & job names ourselves. This is done in the driver's constructor.
Simply change the SetUp method to the following:
driver =newChromeDriver(chromeOptions:newChromeOptions(),projectName:"My First C# Project",jobName:"My First C# Job");
Now we can run our test and get a new report:
Notice how the project and job names changed, but the test name still looks weird. Let's fix that as well.
Luckily for us, TestProject's OpenSDK knows to infer test name from the NUnit attribute.
All we need to do is change our [Test] attribute as follows:
[Test(Description ="My First Test")]
Now we can run our test again and check the new report:
Custom step reports
The last thing we want to do is report a few extra steps, to make our report look more robust. Luckily for us, TestProject's drivers contain an easy-to-use reporting mechanism for manually reporting steps.
Let's add a few extra step reports to our current test: