Specflow / Watin page checking
We are just getting started writing acceptance tests using specflow and watin. We are trying to iron out some common practices as we go along.
What is a good way to check if a user is on a specific page? For example - user x performs action y, they 开发者_如何转开发should be redirected to page z. What is the preferred way to test they are on page z? We have tried things like checking the URL, page title, page heading, etc...
They all work, but what is the most reliable?
I'd see two cases here.
First is some action is fired and you want to sure it does a redirect to the correct page. In this case I'd think the Url is the best the check as it is unique and reasonably robust to change.
Second is where you have navigated (GoTo'd) a page and want to check you're there. Again the Url is good but you might want to check on some known text so you know the page has loaded successfully too (or even a check that the it does not contain 'error'). I'd typically store text values in a resource file and give name them for what they are, e.g. HomePageLoadedText = "Welcome back Bob". Imho it makes them more explicit and should they fail it is more readable.
The most technically correct way I have done this in the past is that we had a unique page identifier in each page. For our system it was there for support purposes on an internal application "Can you look at the bottom left corner and tell me what page you are on". If your developers were to implement something similar that could be tuned on in test that would be the best way.
If that is not possible (and it probably isn't in a lot of cases) you need to find a way to uniquely identify the page you are on. URL's are supposed to be globally unique, so that is probably a good way, except that does not confirm that the correct page is being shown for a given URL.
Generally this type of testing isn't really necessary if you are interacting with components on the page that you navigated to, as if you are not on the correct page, then your test will fail when you try to do something.
精彩评论