I am new to Automated testing (new to coding) and have been teaching myself C# and selenium using Visual Studio and MS Test. I am trying to get the test name (As defined from test Method) so I can insert this into a config class for my Browserstack/CBT comparison and review testing.
What I want to be able to define is something like
Testname = Name of test (from test method) so I can then insert this into my driver file
IWebDriver driver;
DesiredCapabilities caps = new DesiredCapabilities();
caps.SetCapability("name", Testname);
Reading online I know there is a TestName capability in MS Test however I am not able to figure out how to utilise it for my purpose.
Any help greatly appreciated happy to give additional info if needed.
regards
Richard
The easier way to get the name of the test method in MS Test is by using the TestContext property:
First, inside your test class add the following line (if not already exist):
public TestContext TestContext { get; set; }
MS-Test will set this property to a TestContext object relevant for the current test.
Then you can use:
string testName = TestContext.TestName;
...
caps.SetCapability("name", testname);