3

From what I have read about functional programming, it is considered to be more concise, more testable, and have fewer side effects. Would it be good to use for UI test automation?

Context: I am working in protractor with JavaScript and JavaScript supports functional programming concepts to an good extent. So I explored and experimented with concepts like higher order functions,immutability,pure functions,no side effects and functors like map, reduce, and filter, but I could not get it to a meaningful state in the context of UI automation. Does anyone have experience using it with Protractor/nightwatch or another javascript based UI test automation framework who could share some insights on using a more functional approach opposed to Object oriented or procedural approach.

Expectation: It would be great if someone can share some code examples with a few typical automation use cases to explain it in the automation context, as opposed to generic programming scenarios. Also some insights on how it can improve the code for test automation; my primary design goals are maintainability, reusability and readability.

Example: To give an concrete typical scenario, in UI automation we need to interact with UI Grid and verify the content from an specific row and column based on some condition, and verify it with some expected values.

  • Do you know and use any of functional programming languages? Did you researched it has bindings for Selenium? Languages are tools, you select the best tool for the task at hand. – Peter M. - stands for Monica May 22 '17 at 14:50
  • Peter, I am working in javascript which has functional features but I could not take advantage of its features in UI automation like first class functions and writing higher order functions with abstractions.. – Vishal Aggarwal May 28 '17 at 2:58
2

Functional programming can indeed be a powerful tool, but it requires a very different way of thinking than OOP or procedural programming. It isn't a magic hammer, though, so isolated examples are unlikely to be very helpful in knowing when to use it. I would recommend developing a deep understanding of it, perhaps even learning a truly functional language such as Scheme or Haskell. Once you develop that understanding, you will have a better idea of what situations it makes sense to use it in, and when a different paradigm would better meet your design goals.

One good resource is the book and MIT lectures Structure and Interpretation of Computer Programs, which uses Scheme. There are plenty of coding exercises in the book, and the course does a deep dive into the underlying functional programming concepts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.