开发者

When testing a web-app, what is the best way to test that I'm on the right page?

开发者 https://www.devze.com 2023-04-10 20:03 出处:网络
I\'m currently building tests using Capybara/Rails, and want to know the most reliable/standard way for testing that I am on the correct page in the following situations:

I'm currently building tests using Capybara/Rails, and want to know the most reliable/standard way for testing that I am on the correct page in the following situations:

Standard Integration Test, including off-site links Remote Production Tests (an assortment of t开发者_JAVA技巧ests that can be run on the production server to insure everything is still working)

As is, I'm insuring certain fairly unique elements exist on each page, but some of the pages are fairly similar, or with the primary difference being different dynamically generated content that is hard to check. I would use the URL, but I'm not sure if that's consistent with Rails - I know different routes are possible to get to a page, but I'm not sure if actually visiting the page gives some sort of retrievable "true address".

Also, I'm not doing the product from scratch and it's under active development, so while I could go in and add some unique identifier to every page, I'd prefer to have a solution that made as few changes to the existing code-base as possible.


Why not using the title of the page? It should be unique (If it's not, you should probably revisit that and make it unique). I don't see any reason that would imply having same titles for two different pages...


You should be able to get the current url/path using current_url or current_path and compare with a valid route to ascertain equality. you can check out http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Session#current_path-instance_method or https://github.com/jnicklas/capybara and see "The DSL"

0

精彩评论

暂无评论...
验证码 换一张
取 消