TestStack / TestStack.Seleno

Seleno helps you write automated UI tests in the right way by implementing Page Objects and Page Components and by reading from and writing to web pages using strongly typed view models.
http://teststack.github.com/TestStack.Seleno/
MIT License
180 stars 60 forks source link

How do you have per test method seleno host? #203

Closed 82949712 closed 9 years ago

82949712 commented 9 years ago

So if you use a static instance of SelenoHost it will be shared between all tests, but I would like a SelenoHost for each of the test so that they can run concurrently, I would like to be able to pass the host object to Page Objects easily, is there anything like the context binding and injection in Seleno like what the SpecFlow does?

robdmoore commented 9 years ago

I'm not sure what SpecFlow features you are referring to, feel free to post a link to a description.

Regardless, let's see if I can answer your question.

First and foremost, you can have a per-test seleno host by simply using a using statement:

using (var host = new SelenoHost()) {
    host.Run(...);
    // ...
}

I would strongly recommend against doing that though as when you call host.Run there is a lot of overload so your test runs will be very slow. Instead I'd recommend you statically spin up multiple SelenoHosts and then have some mechanism to choose between all the instances you have available (maybe similar to how connection pools work for sql).

You don't pass the host object to a page object, you resolve the initial page object from the host using the NavigateToInitialPage method and then from there use the Navigate property or GetComponent method within the page object to get other page objects.

The conversation on this thread may also be helpful: https://github.com/TestStack/TestStack.Seleno/issues/166

82949712 commented 9 years ago

Thanks for the help. I have got the solution.

robdmoore commented 9 years ago

No worries