Selenium WebDriver应该使用哪种设计模式? [英] Which design patterns should we use with Selenium WebDriver?

查看:228
本文介绍了Selenium WebDriver应该使用哪种设计模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

页面对象模式很明显.但是,我可以做些什么来为Web应用程序构建更好的自动化测试用例呢?

Page Object Pattern is obvious. But what I can do more to build better automated test cases for web application?

推荐答案

我可能无法谈论任何标准模式,但是我考虑了以下几点:

I may not be able to talk about any standard pattern, but here are a few things that I consider:

  1. 充分利用测试执行框架.我使用TestNG.
  2. 我创建一个基本文件,该文件使用大多数TestNG批注进行设置和删除.
  3. 分离您的可重用函数,并在需要时调用它.我通常将它们添加到基类中.
  4. 如果定位器过于复杂,我个人更喜欢将定位器也保留在基本文件中.这将帮助您从一个位置更改定位器并为所有人反映.在这种情况下,请遵循良好的命名约定.
  5. 尽可能使用收藏集.
  6. 您可以使用ReportNG之类的内容来生成更加用户友好的报告.
  7. 更多地使用隐式等待,并避免使用JavascriptExecutors.
  8. 复制项目文件夹中的驱动程序和库,以实现更好的移动性和更少的外部依赖性.
  9. 将硒WD Javadoc添加到您的项目中会有所帮助.
  10. 我们还通过覆盖onTestFailure方法来确保我们有针对失败的测试用例的屏幕截图.
  11. 所有这些都是简单的编码基础知识,目的是使代码更简洁易懂,我相信您仍然会遵循.
  1. Make good use of Test Execution frameworks. I use TestNG.
  2. I create a base file which makes use of most of the TestNG annotations for Setting and Tearing up.
  3. Separate your Re-usable functions and call it wherever needed. I generally add these in the base class.
  4. I personally prefer keeping locators too in the base file if they are too complicated. This would help you to change the locator from one place and get reflected for all. In this case, do follow a good naming convention.
  5. Use collections wherever possible.
  6. You can use something like ReportNG for more user friendly reports.
  7. Make more use of implicit waits and avoid using JavascriptExecutors.
  8. Copy the Drivers and libraries within the project folders for better mobility and less external dependencies.
  9. Adding selenium WD javadoc to your project will be of some help.
  10. We also make sure we have a screenshot for failed test case by over-riding the onTestFailure method.
  11. Rest all are simple coding basics for cleaner and easy to understand code that I believe you'll be following anyway.

希望这对您有所帮助.如果我能记得的话,会增加更多的积分.另外,如果您需要更多有关这些内容的详细信息,请告诉我.

Hope this was of some help. Will add more points if I'm able to recall. Also, please let me know if you need more details for any of these things.

这篇关于Selenium WebDriver应该使用哪种设计模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆