How to capture Test Case ID that's current being run in the MTM in C# test method - microsoft-test-manager

How to capture Current Test Case ID that's current being run in the MTM pragmatically using C# code?
Thanks & Regards,
woodson

Had the same question and found the answer: how-to-retrieve-the-id-of-the-workitem-that-started-an-automated-test
Basically you get it from the TestContext with string tcId = TestContext.Properties["__Tfs_TestCaseId__"].ToString();

Related

Extracting Test Outcome( Passed , Failed Test Case/Feature Count) in BDD Jenkins

Our Requirement is to Publish a custom HTML Email Message after the completion of the Cucumber(Ruby) Test
execution. I need to Pass following in my html reports.
Test Case Passed Count ,
Test Case Fail Count ,
Pass% etc
Please let us know how I can extract those value from cucumber json report and pass it. Is there any pre define environment variable which stores those value?
Regards,
Shubhra Goyal
Did you try Jelly script?
You may want to look at these plugins that will help you.
https://wiki.jenkins.io/display/JENKINS/Email-ext+plugin
https://github.com/jenkinsci/email-ext-plugin

Run multiple test same build from different tests project

Need your help in the following scenario:
I have a solution with 2 projects with different unit tests
Those projects generate 2 different dll: *deployment.dll and *database.dll
I have a build on TFS that I want to use to run those tests, I'm using "Test Case Filter" to filter the categories of my tests
(TestCategory=TEST1|TestCategory=TEST2|TestCategory=TEST3|TestCategory=TEST4)
and in "Test Sources Spec" I'm filtering both dll (*deployment.dll;*database.dll)
*.deployment.dll has TEST2, TEST3, TEST4
*.database.dll has TEST1
This doesn't work, tests of *database.dll does not run. Test selected in Visual Studio Test Runner
Could you please help on that? If I make the build with only 1 dll, for example, *.database.dll, TEST1 runs well.
(UPDATE) SCENARIO 1
Test Case Filter: TestCategory=TEST1|TestCategory=TEST1|TestCategory=TEST2|TestCategory=TEST3|TestCategory=TEST4
Test Sources Spec: *database.dll;*deployment.dll
only runs TEST1
(UPDATE) SCENARIO 2
Test Case Filter: TestCategory=TEST1|TestCategory=TEST1|TestCategory=TEST2|TestCategory=TEST3|TestCategory=TEST4
Test Sources Spec: **\*deployment.dll;*database.dll
only runs TEST2,TEST3,TEST4
(UPDATE) Does not find tests in Database.dll
I've tested in TFS 2015.3, XAML build, but couldn't reproduce your issue. I'd like to share my steps here for your reference:
I have a solution with some projects, 2 of them are UnitTest projects (UnitTestProject1, UnitTestProject2).
In UnitTest1 project, I added TestCategory for two test case, check screenshot below:
[TestMethod()]
[TestCategory("Pro")]
public void M1Test()
{
//
}
[TestMethod()]
[TestCategory("Dev")]
public void M2Test()
{
//
}
Similar to Step2, in UnitTest2 project, I added TestCategory for two test case, check screenshot below:
[TestMethod()]
[TestCategory("Pro1")]
public void M3Test()
{
//
}
[TestMethod()]
[TestCategory("Dev1")]
public void M4Test()
{
//
}
Edit "Test Case Filter" and "Test Sources Spec" in build definition like below screenshot and queue a build:
The test result is as expected. Only M1Test and M2Test in UnitTestProject1, M3Test and M4Test in UnitTestProject2 are tested.
Finally, it's solved :)
So, what I have done to solve this problem, was, change Build Process Template.
There are one step in this process, calling: "FindMatchingFiles"
I change this value as the below image shows. (however, from now on, I must use "**\*" in all my filters that use this process template). This operation make sure that I have the assemblies with fullpath destination complete.
If you have different solutions, please post here :)
Special thank you to #Cece - MSFT for all support

CodedUI TestCaseFilter

I'm using a CSV file as a DataSource in my CodedUI tests. The file looks like so:
Environment,URL
Live,www.example.com
Stage,stage.example.com
Test,test.example.com
I'd like to be able to setup my TestCaseFilter to selectively run the tests on only one of the environments when running the vstest.console.exe commandline. I can't seem to find any way to do that, i.e. it looks like the TestCaseFilter commandline parameter only supports specific properties. Am I wrong? Is there a way to pass a custom property to TestCaseFilter so that only the tests that pertain to a specific DataRow are executed?
The DataSource in my tests is setup like so:
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\environments.csv", "environments#csv", DataAccessMethod.Sequential)]
And I am referencing the environment in each test like so:
var url = TestContext.DataRow["URL"].ToString();
Thanks for any insight.
The simple and best way is to add another column next to the environment column in your testdata file. Say the column name is RunStatus. The values should either be 'Yes' or 'No', the logic is that the URL which has Runstatus as Yes should be included for the execution.
Before the TestMethod, have a condition to check the Runstatus of the row is Yes. If it's Yes, then Run the TestMethod.
[TestMethod]
public void RunTheTest(TestContext testcontext)
{
if(testcontext.DataRow["RunStatus"].ToString()=="Yes")
{
TestMethod1();
}
}
Hope it helps. Good luck !!

Ruby Appium assert

I have to initiate a Appium webdriver using code below.
driver=Appium::Driver.new(desired_caps)
And it is working for starting an app and quits during execution.
Can any one please give examples on how to do the assert for element exists and specific value comparison?
You've created "driver", then next step is just
driver.start_driver
Then you can use all methods in appium ruby_lib, for example
driver.text('some text')
driver.button('button_name/id/text')
To check element exist:
exists { button('sign in') } ? puts('true') : puts('false')
You said it started then quit, it might be normal, it quits if test arrives the last step, except you add test steps or put some sleep time.
Highly recommend you to check the examples:
https://github.com/jlipps/appium-ruby-example
and also the ruby_lib doc:
https://github.com/appium/ruby_lib/tree/master/docs

HP UFT API Test - Saving Response/Checkpoint values

Is there a way to capture and store (or write to a file) the values returned in the Response? (Checkpoint values)
Using HP UFT 11.52
Thanks,
Lynn
I figured it out. In UFT API under Standard Activities, there are File function modules including "Write to File". I added the module to the test, set the path and other properties, passed the variable to the file and it worked! Couldn't be easier.
I mentioned this on my other answer , you can also write it programatically if you have dynamic array response please refer below:
https://stackoverflow.com/a/28012383/3972994
After running a test, in the test folder, you can find a Snapshots/LastIteration directory.
In it you can find the return value for each step saved in a txt file.
Pay attention that if you data drive the step, only the last iteration will be saved to file.
However, in the Test's log (Test dir/Log/vtd_user.log) you can find all the iterations persisted
Thanks,
Yossi
You do not need to use the standard activities if you do this
var iResponse = this.Activity.responsebody;
System.IO.File.WriteLines(#"directorypath&FileName);
the above will write the response to the file and rewrite it for every run

Resources