Selenium - Selenium best practices

分享一个大牛的人工智能教程。零基础!通俗易懂!风趣幽默!希望你也加入到人工智能的队伍中来!请点击人工智能教程

  1. Use page objects pattern, and consider use Selenium PageFactory. (Page object methods should return a value.)
  2. Preferred selector order : id > name > links text > css > xpath.
  3. Get name of the running test.
  4. Be fluent.
  5. Be robust and portable.
  6. Avoid Thread.sleep prefer Wait or FluentWait.
  7. Use relative URLs.
  8. Create your dataset.
  9. Fresh browser per test.
  10. Keep your test scripts separate from the framework, though it is in the same codebase.
  11. In page objects and other framework classes, if there is some issue to log/write, output it as a state other than a failure (e.g. "[WARN] Login link was not found." or "[INFO] Homepage initialization complete."). Only use assertions and report [FAIL] in the actual test code/script.
  12. From the start, build your framework read a configuration file for things like the target server url to test, database to get data from, logging levels, etc. You may want to also start with the ability to pass the config file name as a parameter when launching your tests. And place your configuration in .properties.
  13. Use TestNG. JUnit works fine, but use TestNG. Then learn about grouping tests and using datasources. They will give you incredible flexibility.
  14. Keep driver use (FireFoxDriver, ChromeDriver, etc) inside the page objects. Don't let them appear in your test scripts.
  15. Use @BeforeClass and @AfterClass (or their variants) to setup and teardown drivers and connections to outside resources (a driver is an outside resource).
  16. Reporting.
    This is a very crucial piece which many ignore while creating the framework. The report that you present is what other teams would see. It should be simple, concise and easy to access.
    Another point about reporting is sending email alerts to the team whenever a test fails. No one wants to/can keep an eye on a test suite all the time. If something fails, framework should alert the users. It should also be noted that too much of alerts will cause the teams to ignore it. So alert the teams only on failures and not at the end of every execution.
  17. Write a test case script as small as possible.
  18. Write test cases as independent with each other. Write each test as its own unit. Write the tests in a way that won't be reliant on other tests to complete.
  19. Store locators separately. (Do not include locators in test script flow.)
  20. Write a different method for each common/unique/specific action. (Even though it has one line to execute no problem but, it should be a separate method.)
  21. Reuse the code (methods). Do not duplicate code anywhere. (I mean don't copy paste any lines from one file to another. Instead of the create a methods with those lines and call that method in both files.)
  22. Have separate library called utility with Reporting, necessary credentials, browser configurations, etc.
  23. Have common naming structure. Such as method name, class name, variable names.
  24. Creating methods to pre-load data for testing should not be done using Selenium, existing APIs should be leveraged to create data for the AUT.
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值