ad

Friday, March 25, 2016

Coded UI Tests: Error Resolution “COM object that has been separated from its underlying RCW cannot be used”.

This error may come across a coded UI developer while executing test cases. This error is occurred if you are using a same static class across two test cases.
For example in my scenario, I have created a static class called "MainCall". In this class, I have put all the UIMAP class references. So that I can call any test case of any UIMAP from the "MainCall" class.
The class is as below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SaadAutomation.Maps.UIMap1;
using SaadAutomation.Maps.UIMap2;
using SaadAutomation.Maps.UIMap3;
namespace SaadAutomation
{

class
MainCall
{

private static UIMap1 _spMap;
private static UIMap2 _cMap;
private static UIMap3 _crMap;

public static UIMap1 SPMap
{
get {
if (_spMap == null)
_spMap = new UIMap1();
return _spMap;
}
}

public static UIMap2 CMap
{
get{
if (_cMap == null)
_cMap = new UIMap2();
return _cMap;
}
}

public static UIMap3 CRMap
{
get{
if (_crMap == null)
_crMap = new UIMap3();
return _crMap;
}
}
}
}


I was calling functions like this in a test method.
[TestMethod]

public void ExampleTestCase1 ()
{
MainCall.SPMap.Method1();
MainCall.SPMap.Method2();
MainCall.CMap.Method1();
MainCall.CRMap.CloseAllWindows();
}
[TestMethod]

public
void ExampleTestCase2 ()
{
MainCall.CRMap.Method1();
MainCall.CMap.Method2();
MainCall.SPMap.Method1();
}
When I run both of the above test methods together, I got this error message.
System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used.
So I searched on the internet and found the solution. It is just a setting change in the local.testsettings file.
Resolution:
To resolve this error, open your .testsettings file in any XML editor. This file is located under solution items.
Add this line (marked bold)
<Description>These are test settings for Trace and Test Impact.</Description>
<Execution>


Don't forget to restart visual studio after that. Now you will be able to run your test cases and this error will not come inshallah.
There is one side effect of adding this line. You will not be able to debug your test. See my another post about the mentioned issue.
What other errors you encounter? Post here as comments and we will try to find the solution together.

22 comments:

  1. very helpful thanks for sharing would be interested in seeing posts like these.

    ReplyDelete
  2. There is no Bold Line that shows the Solution

    ReplyDelete
  3. wow...nice blog, very help full information. Thanks for sharing.
    Best Software company in New jersey, USA

    ReplyDelete

  4. Digital Transformation |Austere Technologies
    Very good informative article. Thanks for sharing such nice article, keep on up dating such good articles.

    ReplyDelete
  5. Wow!! What a interesting blog.. Really awesome to read and so informative blog.. Keep ongoing such a great blog..Internet Of Things

    ReplyDelete
  6. VERY INFORMATIVE BLOG. KEEP SHARING SUCH A GOOD ARTICLES.
    Best Cloud Solutions | Austere Technologies

    ReplyDelete
  7. Really great blog, it's very helpful and has great knowledgeable information. Thanks for sharing, keep updating such a good informative blog.

    Best IT Security Services | Austere Technologies

    ReplyDelete
  8. Great article, really very helpful content you made. Thank you, keep sharing.

    Quality Managment Services | Austere Technologies

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. Excellent information you made in this blog, very helpful information. Thanks for sharing.

    Best Commerce College| Avinash college of commerce

    ReplyDelete
  11. Great article, really very helpful content you made. Thank you, keep sharing.

    Best junior college in Hyderabad | Avinash College of commerce

    ReplyDelete
  12. Hi Thanks for the nice information its very useful to read your blog. We provide Software Development Services

    ReplyDelete
  13. Wow...Excellent informative blog, really helpful. Thank you.

    Best CAM Training in hyd | ISFS

    ReplyDelete