I'm trying to use browser specific resx files in some automation tests. I'm stuck at the point where I wish to instansiate the type. Can anyone point me in the right direction? I have tried activator.createInstance etc... with no luck.
public class WebAiiBaseTest : BaseTest
{
private readonly IDictionary<BrowserType, Type> resxMapper = new Dictionary<BrowserType, Type>{
{BrowserType.Chrome, typeof(Chrome)}
, {BrowserType.Safari, typeof(Safari)}
, {BrowserType.FireFox, typeof(Firefox)}
, {BrowserType.InternetExplorer, typeof(InternetExplorer)}
};
[TestFixtureSetUp]
public void FixtureSetup()
{
Initialize();
Launcher.LaunchRepairInformation();
}
[TearDown]
public void TestCleanUp()
{
Launcher.NavigateToRepairInformation();
}
[TestFixtureTearDown]
public void FixtureCleanup()
{
CleanUp();
}
protected object BrowserResx
{
get { return Activator.CreateInstance(resxMapper[ActiveBrowser.BrowserType]); }
}
}
This code returns an instance, but it is of type object. I would like to return a strongly typed instance. I have tried the generic overload for CreateInstance, like this
return Activator.CreateInstance<resxMapper[ActiveBrowser.BrowserType]>();
but Visual Studio does not like this syntax. What am I doing wrong here? Thanks for any tips or advice.
Cheers,
~ck in San Diego
your code is not correctly spelled, did you try
return Activator.CreateInstance(resxMapper[ActiveBrowser.BrowserType]);
?