Thursday, 4 June 2015

Best Practices Selenium using TestNG



Best practices for Maintaining Existing Scripts and New Scripts
    Using TestNG
  • It enables user to set execution priorities for the test methods. As per business requirement Test method can be executed.




  • Parallel testing can be done using TestNG
  • Supports annotations for e.g @AfterTest, @BeforeTest, @AfterSuite, BeforeSuite()
  • We can do parameterization using TestNG
  • Readily supports integration with various tools and plug-ins like build tools (Ant, Maven etc.), Integrated Development Environment (Eclipse)
  • Facilitates user with effective means of Report Generation using ReportNG
  • TestNG, by default, generates a different type of report for example an HTML and an XML report.


POM (Page Object Model) based approach
  • This Page class will find the WebElements of that web page and also contains Page methods which perform operations on those WebElements
  • Name of these methods should be given as per the task they are performing i.e., if a loader is waiting for payment gateway to be appear, POM method name can be "make_GoogleSearchDisplay()"




Use Files library for code reuse
  • If the flow of our logic changes we just have only one place to update
  • To test whether our changes worked, we only have to run one of the tests to verify. All other tests use the same code so it should work
  • A lot more expressive as we look at the code. With well named methods, we create a higher level of abstraction that is easier to read and understand
  • If the UI changes (an id of a field), we go to our one method, update the id and we are good to go
  • Flexible and extensible: The possibilities are limitless. At this point we can use conditions, loops, exceptions, you can do your own reporting, etc..


For frequent changes we use Excel sheet or CSV file
We can use excel sheet for storing our test data. It is easy to maintain the data in excel and also easy to modify the test data as per the business requirements.






Use custom exception which can be easily understood
  • Custom exception helps to clearly understand the error. Please find below some key points for using custom exceptions:
  • Add situation specific data to an exception. Ideally this data would help another developer to track down the source of the error.
  • Provides a type safe mechanism for a developer to detect an error condition. 
  • No existing exception adequately described my problem.

    Additional For Existing Scripts
  • Execute existing scripts (Regression Testing) on different environments.
  • Create well structured Test data.
  • Bug reporting for failures.
  • Modify developed code, as coding standards are already specified.

No comments:

Post a Comment