Lucas_Santos
Lucas_Santos

Reputation: 4740

Run WatiN with BackGroundWorker to Open IE Browser

I'm just using WatIn without any others Tests framework, like NUnit or others.

When I try to run a BackGroundWorker to open IE browser, it occurs the error

An exception of type 'System.Threading.ThreadStateException' occurred in WatiN.Core.dll but was not handled in user code

Additional information: The CurrentThread needs to have it's ApartmentState set to ApartmentState.STA to be able to automate Internet Explorer.

I read some threads here on stackoverflow but, all the tests failed with the same error.

Can someone help me?

Code

BackgroundWorker _worker = new BackgroundWorker();
            _worker.WorkerReportsProgress = true;
            _worker.ProgressChanged += new ProgressChangedEventHandler(_worker_ProgressChanged);
            _worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_worker_RunWorkerCompleted);            
            _worker.DoWork += (s, e2) =>
            {
                Loga(usuario, senha);
            };
            _worker.RunWorkerAsync();

    protected void Loga(string usuario, string senha)
    {            
        using (var browser = new IE("my page here"))
        {
           //Code here
        }
    }

Upvotes: 1

Views: 774

Answers (1)

ProgrammerV5
ProgrammerV5

Reputation: 1962

You cannot fire up multiple threads with Watin. but you can fire several instances of IE:

IE browser1 = new IE();
IE browser2 = new IE();

browser1.GoTo("http://www.google.com");
browser2.GoTo("http://www.yahoo.com");

Upvotes: 1

Related Questions