cheezy/page-object — pull request #154 by elzoiddy (2013-01-23 00:51:36+00:00)
Title: has_expected_title? sometimes show misleading error messages when raising exception

Hi,

I don't know if I am the only one experiencing this. Every once in a while(1 in ~50), has_expected_title? would raise exceptions like this

Expected title 'App - Login' instead of 'App - Login'

This is very puzzling. Both are strings and both are exactly the same down to the bytes. It turned out that the generated has_expected_title? sometimes print out misleading messages due to the asynchronous nature of the title call.

```ruby
63 has_expected_title = expected_title === title
64 raise "Expected title '#{expected_title}' instead of '#{title}'" unless has_expected_title
```

If title method @ line 63 returns ''(empty string), but by the second time we call it @ line 64 it returns the title (maybe when the page is sufficiently loaded for selenium to get a title) we would get this weird message of 'App - Login' instead of 'App - Login'.

I have refactored the generated method a bit to store the results of the first title method call and then use it in the comparison operation and exception thrown from that. I think it's probably up to the caller of this method to make sure the page is "sufficiently" loaded to check the title, hopefully the exception message would be less confusing.

Let me know what you think.

Thanks

Observed on:
OS X
ruby 1.8.7 ( I notice this on 1.9.3 too)
Firefox 18.0.1