测试网络应用程序时,测试我是否位于正确页面的最佳方法是什么?
我目前正在使用 Capybara/Rails 构建测试,并且想知道在以下情况下我位于正确页面上的最可靠/标准的测试方法:
标准集成测试,包括站外链接 远程生产测试(可以在生产服务器上运行的各种测试,以确保一切仍然正常工作)
按原样,我确保每个页面上都存在某些相当独特的元素,但有些页面非常相似,或者与主要区别是动态生成的内容不同,难以检查。我会使用 URL,但我不确定这是否与 Rails 一致 - 我知道可以通过不同的路线到达页面,但我不确定实际访问该页面是否会提供某种可检索的“真实地址” 。
另外,我不是从头开始制作该产品,它正在积极开发中,因此虽然我可以进入并向每个页面添加一些唯一标识符,但我更希望有一个对现有代码进行尽可能少更改的解决方案 -尽可能的基础。
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 tests 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不使用页面标题?它应该是唯一的(如果不是,您可能应该重新审视它并使其独一无二)。我没有看到任何理由暗示两个不同的页面具有相同的标题......
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...
您应该能够使用 current_url 或 current_path 获取当前 url/路径,并与有效路由进行比较以确定是否相等。你可以查看 http://rubydoc.info/github/jnicklas /capybara/master/Capybara/Session#current_path-instance_method 或 https://github.com/jnicklas/capybara 并查看“DSL”
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"