I'm using the standard Microsoft approach to create automated tests (MTM, Labs, CodedUI/ UI Automation Framework).
Inside my test methods, I've created a test runner that can execute tests as a series of steps. These steps coincide with the steps captured in the test case.
What I would like to do is start adding step / action results back to the test result as a step fails / passes.
There's a lot of information out there, but every example and blog I've found refers to this:
// Create a new test run
ITestRun run = plan.CreateTestRun(false);
This creates a new test run and then from there you're expected to populate the results. The problem with this approach is my tests are already running. I want to access the current test run.
The test context object: https://msdn.microsoft.com/en-US/library/ms404699(v=vs.80).aspx, doesn't provide any help with this.
I'm not even entirely sure it's possible to add the results before the operation completes, but I guess it should be.
But how can I access the test run (even if I can just get an id) from within a running test case?
If by test results you mean the HTML log, you can find the path to it like this:
string htmlLogPath = String.Format(@"{0}\UITestActionLog.html", TestContext.TestResultsDirectory);
After that you can of course open it, and add custom results to it.