0

I'm 2 days old .NET C# coder trying to get control on ProjectA - WinForm from ProjectB - C# console app.

Basically I'm using WatiN to automate test within WebBrowser control in ProjectA.

When I run ProjectB which executes winformWithWebBrowserTest.exe, the winform with webbrowser shows up. But then it fails to access form1. How can I access the webbrowser control from ProjectB ???

Error:

System.Runtime.IteropServices.InvalidComObjectException
COM
object that has been separated from its underlying RCW cannot be used

ProjectA WinForm: (winformWithWebBrowserTest.exe)

namespace WindowsFormsApplication1
{
    public partial class Form1 : System.Windows.Forms.Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    }//end class

}//end namespace

Project B console app: (WatinConsoleExample.cs)

namespace ConsoleApplication1
{
    class WatinConsoleExample
    {
        [STAThread]
        static void Main(string[] args)
        {
            //run ProjectA exe
            System.Diagnostics.Process Proc = new System.Diagnostics.Process();
            Proc.StartInfo.FileName = "C:\\Users\\m-takayashiki\\Documents\\Visual Studio 2010\\Projects\\winformWithWebBrowserTest\\winformWithWebBrowserTest\\bin\\Release\\winformWithWebBrowserTest.exe";
            Proc.Start();


            WindowsFormsApplication1.Form1 form1 = new Form1();

            var t = new Thread(() =>
            {
                Settings.AutoStartDialogWatcher = false;
                //exception occurs below ..........
                var ie = new IE(form1.webBrowser1.ActiveXInstance);
                ie.GoTo("http://www.google.com");
                ie.TextField(Find.ByClass("lst")).TypeText("this is awesome!!");
                ie.Button(Find.ByName("btnG")).Click();
            });
            t.SetApartmentState(ApartmentState.STA);
            t.Start();

        }
    }
}
Meow
  • 18,371
  • 52
  • 136
  • 180
  • Is there a particular reason you don't just run the website directly in a browser, and use one of the many browser automation tools out there to drive it, such as watin or selenium? – Tom E Mar 08 '11 at 17:10
  • My project is to enable automation against webbrowser in .NET using Selenium, but seems like WatiN is the way to go. – Meow Mar 09 '11 at 00:41

1 Answers1

1

You cannot do it , since both processes are running in their seperate process space & you need to go over interprocess communication which is not recommended for a 2 days old:).

Furqan Hameedi
  • 4,372
  • 3
  • 27
  • 34
  • Is there alternatives so that I can run the .exe(built from c#) which popup up winform and have my separate c# code to run WatiN against it??? – Meow Mar 08 '11 at 08:38
  • There might be some alternative, but I am unaware of any such, apologies to u . – Furqan Hameedi Mar 08 '11 at 08:42
  • hmm how about window handler? Maybe that would work.. I have to test though. – Meow Mar 08 '11 at 09:32
  • 2
    There is a mechanism used by Visual Studio, when you debug your program, it creates a process programatically and loads you app in that process in the same process space and hence provide you debugging capabilities, i think you should research a bit on this. – Furqan Hameedi Mar 08 '11 at 09:44