2

In our Cruise Control build, we run a suite of Selenium tests for 3 browsers. To do that, we run the same suite of tests through MSTest but we change the app.config file between each run to setup the browser to be used.

The problem is that in the MSTest Report page in Cruise Control, we see the three test runs but we are not able to see which browser is used for each test run.

Ideally, I would like to do something like passing the name of the browser as a parameter to MSTest so that it writes it into the trx file but I didn't see any possibility for that. The only thing I'm thinking about is giving a specified output name for the trx file and then use a Powershell script to change the xml inside this file.

Do you have a better idea?

Merwan
  • 453
  • 1
  • 5
  • 16

2 Answers2

4

Following Elena advice, I looked at the TestContext object in MSTest. I ended up creating a specific unit test in my test suite to add the browser name to the trx file like so:

[TestClass]
public class ConfigurationTests
{
    public TestContext TestContext { get; set; }

    [TestMethod]
    public void DisplayBrowserUsedForSeleniumTests()
    {
        string browserName = ConfigurationManager.AppSettings["DriverName"];
        TestContext.WriteLine("for {0} browser.", browserName);
    }
}

And in my output trx file I now have something like:

<UnitTestResult testName="DisplayBrowserUsedForSeleniumTests">
  <Output>
    <TextMessages>
      <Message>for Firefox browser</Message>
    </TextMessages>
  </Output>
</UnitTestResult>

Finally, I changed the Cruise Control xslt transformation for MSTest report to display the browser information in the summary title:

   <h2>Summary <xsl:value-of select="*[local-name()='Results']/*[local-name()='UnitTestResult'][@testName='DisplayBrowserUsedForSeleniumTests']"/></h2>
Merwan
  • 453
  • 1
  • 5
  • 16
1

Here are some posts that could help you:

I did not try it but they sound like to be what you are looking for.

EDIT: Just for the case the links above get broken someday:

Adding custom data to trx result file

You can add a TestProperty attribute to your TestMethod and it will appear in your trx file.

[TestProperty("Severity", "1")]

Thanks,

Anuj

Marked as answer by singhhome Friday, August 20, 2010 2:34 PM Friday, August 20, 2010 5:53 AM

Adding additional test result information.

To add an additional file in TRX file- You can add this with the help of following method present in TestContext for every test.

TestContext.AddResultFile(filePath) where filePath is the path of the file you want to add in the test result file.

To get the TestResult file name during the test run- You can use following property to get this

TestContext.TestRunDirectory It'll give you the directory name where the logs are stored for the test run with the complete path. For a test run the directory name and the trx file name would be same hence if you concatenate this string with .trx you can very well access the test result file.

Following is a sample code snippet.

[TestMethod]
public void CodedUITestMethod1()
{
        //add a file stored at c:\ location to the test result file
        this.TestContext.AddResultFile(@"c:\file.bmp");

        //Print the trx file name
        string testRunDirectory = TestContext.TestRunDirectory;
        string testRunTRXFileName = String.Concat(testRunDirectory, ".trx");
        Console.WriteLine("TestResult file : " + testRunTRXFileName);
}

Proposed as answer by Deepak.Singhal [MSFT]Microsoft employee Wednesday, February 10, 2010 1:32 PM Marked as answer by Flying_Tiger Wednesday, February 10, 2010 1:52 PM

Elena
  • 1,928
  • 1
  • 15
  • 23
  • I posted the full answer to my problem below for reference but your answer helped me to find the missing part I needed. – Merwan Jun 20 '12 at 13:22
  • these links are broken :( – iOne May 25 '18 at 12:47
  • @iOne both links are still working perfectly for me. I've just extended my original answer by the content provided by linked articles. – Elena Jun 10 '18 at 09:08