I am using MSTest - C#
- Selenium
to run a suite of tests. I am taking a screenshot if there is a failed step and wish to upload ( attach ) it with the trx file,
All is good when I run it as a single test of a couple of tests and the results are with the attachment.
But when I run the tests in Parallel, I am not able to see the result file with the attachment even though the test is FAILED
I get the below in the trx file
TestContext Messages: Value cannot be null. Parameter name: path
The code I am using to attach the file to the trx file is
Screenshot screenShot = ((ITakesScreenshot)driver).GetScreenshot();
string fileName = fullFilePath + "Screenshot_" + driver.testContext.TestName + DateTime.Now.ToString("yyyy-dd-MM-HH-mm-ss")+".png";
screenShot.SaveAsFile((fileName), ImageFormat.Png);
driver.testContext.AddResultFile(fileName);
Any pointers where I am going wrong. I saw a couple of links while googling and they mention this is a known issue. Is there something I can do as a work around to circumvent this issue.
Any pointers will be very helpful. Thanks
My 2 cents...
The below code solved the issue...
Directory.CreateDirectory(MyWebDriver.testContext.TestResultsDirectory);
Screenshot screenShot = ((ITakesScreenshot)MyWebDriver).GetScreenshot();
string fileName = MyWebDriver.testContext.TestResultsDirectory+"\\Screenshot_" + MyWebDriver.testContext.TestName + DateTime.Now.ToString("yyyy-dd-MM-HH-mm-ss")+".png";
screenShot.SaveAsFile((fileName), ImageFormat.Png);
Please note that MyWebDriver is an extension of Selenium WebDriver tailored for my project requirements.
Refer the below link for the cause of this issue.