Thursday, 4 June 2015

Best Practices Selenium using PHPUNIT



Best practices for Maintaining Existing Scripts and New Scripts
    PHPUNIT
  • We will provide reports in XML, XHTML
  • Business Driven Development style readable steps
  • Data Cleanup
  • Page Objects and Step Objects included
  • We will test Controllers, library and model functions
  • Can integrate with Zend framework
  • Parallel Execution
  • We will provide code coverage
  • We will use specific assertions
    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.
  • Will not modify developed code.

No comments:

Post a Comment