Automation using WatiN is being carried out. Using couple of simultaneous threads to test the application. Few threads are failed and log report/stack trace says the following.
System.InvalidCastException: Specified cast is not valid.
at SHDocVw.IWebBrowser2.get_HWND()
at WatiN.Core.Native.InternetExplorer.IEBrowser.get_hWnd()
at WatiN.Core.Browser.get_hWnd()
at WatiN.Core.DomContainer.StartDialogWatcher()
at WatiN.Core.IE.CreateNewIEAndGoToUri(Uri uri, IDialogHandler logonDialogHandler, Boolean createInNewProcess)
at WatiN.Core.IE..ctor(Boolean createInNewProcess)
at Core.BaseWatinTestWrapper.Run()
Following this exception there is another exception being raised i.e.
System.Runtime.InteropServices.COMException Retrieving the COM class factory for component with CLSID {0002DF01-0000-0000-C000-开发者_StackOverflow社区000000000046} failed due to the following error: 80080005.
Please provide some help. Thanks in advance.
I was also using couple of threads and was getting the same error. Make your main method [MTAThread]. This fixed the problem for me.
If I'm not mistaken, WatiN explicitly is single-threaded [STApartment] - http://watin.org/documentation/sta-apartmentstate/ If you wish to have such test, I believe you need separate processes in OS-level. I can't tell for sure does you approach collide with this requirement, yet I'd suggest single instance for single browser (and it's descendent windows / processess).
Also, there might be another hickup - WatiN connects to IE using browser's internals, but if there's any Windows / User Session related activity along the way, this might bring additional confusion.
精彩评论