I have coded some automated web tests in C#, they use the Coded UI Test Library.
These tests are not a bunch of recorded actions, They have been coded and executed on IE.
I am using Visual Studio 2010 and I'm trying to launch my tests on Firefox 3.6. I have already installed the required components for this purpose.
The problem is that I want to choose the browser I want to use to test my applications, so I want to change the field "currentBrowser" but I cannot have access to this property because is a static member property.
I have tried to use Reflection library to access the property, but I cannot achieve it.
This is an example of my current code:
BrowserWindow browserWin = new BrowserWindow();
// Copy the dll
Assembly testAssembly = Assembly.LoadFile(@"c:\Microsoft.VisualStudio.TestTools.UITesting.dll");
// get type of class BrowserWindow from just loaded assembly
Type BrowserWindowType = testAssembly.GetType("Microsoft.VisualStudio.TestTools.UITesting.BrowserWindow");
object browserInstance = Activator.CreateInstance(BrowserWindowType, new object[] {});
PropertyInfo BrowserPropertyInfo = BrowserWindowType.GetProperty("CurrentBrowser");
//set value of property: public
BrowserPropertyInfo.SetValue(browserInstance,"FireFox", null);
// get value of property: public
string value = (string)BrowserPropertyInfo.GetValue(browserInstance, null);
I have also tried this line of code:
typeof(BrowserWindow).InvokeMember("set_CurrentBrowser", BindingFlags.InvokeMethod | BindingFlags.DeclaredOnly |BindingFlags.Public | BindingFlags.Static, null, bw, args,null,null,null);
But the property's value "currentBrowser" never is modified.
Do I need some kind of special permissions? Maybe something like "ReflectionPermission"
Thank you very much