Pregunta

I am using WatiN to test my website.

I would like to open few URLs in the same time, and click on a button in each of them simultaneously.

I know that i need to implement it using multi-threading , but my attempt failed.

        using (var browser =new IE())
        {

            var th1 = new Thread(() => { browser.GoTo("http://www.google.com"); });
            th1.SetApartmentState(ApartmentState.STA);
            th1.Start();
            var th2 = new Thread(() => { browser.GoTo("http://www.google.com"); });
            th2.SetApartmentState(ApartmentState.STA);
            th2.Start();
        }

The problem is that only one browser is opened.

¿Fue útil?

Solución

In you're only opening one browser, then 'go'ing twice. What you have is like opening a browser window, typing in the Address bar, then typing in that same address bar again.

You need to open two browsers.

EG:

var firstBrowser = new IE();
var secondBrowser = new IE();
firstBrowser.GoTo("www.google.com");
secondBrowser.GoTo("www.cnn.com");

The above is written from memory and therefore may not be 100% exactly correct, but is the general idea to get two browsers open that you can work with.

Otros consejos

so if th1 and th2 started but program crashed and the two browsers still open in background

when starting program again, the program can not define firstbrowser and second browser because they are open yet and no closed, what is your idea for it?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top