SlideShare a Scribd company logo
1 of 26
© 2022 Thoughtworks | Confidential
Functional Programming
in
Test Automation
-Narmadha & Sameena
1
© 2022 Thoughtworks | Confidential 2
Narmadha Ramasamy
Senior Consultant @Thoughtworks
linkedin.com/in/narmadha956/
narmadha956@gmail.com
Sameena Syed
Senior Consultant @Thoughtworks
linkedin.com/in/sameena-syed/
sameena9010@gmail.com
© 2022 Thoughtworks | Confidential
Functional
Programming
Functional Programming is a
programming style where we use Pure
functions extensively
3
© 2022 Thoughtworks | Confidential
● Functions as variables
● Functions as arguments
● Functions as return types
First class citizens – FUNCTIONS
4
© 2022 Thoughtworks | Confidential
Impure Functions
f(x)
Pure Functions
f(x)
Pure & Impure Functions
5
Same input Same output Same input
Output 1
Output 2
……….
© 2022 Thoughtworks | Confidential
Business Requirement
6
Hey Team !
Our app juice shop is ready,
can we have automated tests
to test different workflows
© 2022 Thoughtworks | Confidential
Functional Programming thinking
 IMPURE FUNCTIONS (Actions)
 PURE FUNCTIONS (Calculations)
 DATA (Data about events, users etc)
7
© 2022 Thoughtworks | Confidential
Application Tour
8
© 2022 Thoughtworks | Confidential
Business use case
Buy juice items from juice shop
o Given user is logged in
o When cart is empty
o Then user should be able to select juice items and checkout successfully
9
We need to ensure checkout of juice items works as expected, as it’s the most sold type of item.
© 2022 Thoughtworks | Confidential
User Journey
1. Login to application with registered user
2. Get all items in Juice shop portal
3. Add juices to cart
4. Navigate to cart
5. Checkout items in cart
6. Select delivery address
7. Select delivery speed
8. Select payment method
9. Validate cart total and checkout
10
© 2022 Thoughtworks | Confidential
CODE Walkthrough
11
© 2022 Thoughtworks | Confidential 12
1. Launch application -> launchApplication()
2. Login to application with registered user -> login()
3. Get all items in Juice shop portal -> getAllItems()
4. Add juices to cart -> getJuiceTypeItems(), addJuicesToCart()
5. Navigate to cart -> navigateToCart()
6. Checkout items in cart -> checkoutCart()
7. Select delivery address -> selectAddress()
8. Select delivery speed -> selectDelivery()
9. Select payment method -> payAndContinue()
10. Validate total price -> assert.equal(totalPriceDisplayed,expectedTotalPrice)
11. Validate order confirmation -> getOrderConfirmation()
Method Mapping
© 2022 Thoughtworks | Confidential
Business Requirement
13
Hey Team !
Looks like we are getting
more data and business
flows, is our existing
automated tests are scalable
???
© 2022 Thoughtworks | Confidential
 Map : Returns list of same length as input
 Filter : Returns list reduced length as input
 Reduce : Returns single object
Commonly used Higher Order Functions
14
© 2022 Thoughtworks | Confidential
CODE Refactoring
16
© 2022 Thoughtworks | Confidential
Call Graph
17
expectedTotalPrice()
addJuicesToCart()
getJuiceTypeItems()
filter() map() reduce() slice()
getAllItems()
navigateToCart() checkoutCart()
selectDeliverySpeed() getOrderConfirmation()
BUSINESS LAYER
CART OPERATIONS
ITEM OPERATIONS
selectAddress() payAndContinue()
Array-Built Ins
© 2022 Thoughtworks | Confidential
 Always separate out business rules as functions
 Using call graph to design test case
 Extract calculations from actions as much as possible
 Keep data immutable
 Avoid implicit input & output instead use function arguments & return statements
 Refactor specific names to generic names
 Duplicate code is code smell
Practices to Follow
18
© 2022 Thoughtworks | Confidential
New Requirement
19
Clients have decided to give
bonus points for cart price
above 999 !
Can we develop this asap
© 2022 Thoughtworks | Confidential
Currying
How to stop passing the same arguments repeatedly to different functions??
• Use currying
Transformation of a function with multiple arguments to a function with single arg and
returns a function that takes the other args
20
© 2022 Thoughtworks | Confidential
CODE Refactoring
22
© 2022 Thoughtworks | Confidential
Call Graph
23
expectedTotalPrice()
addItemsToCart()
geRequiredItems()
filter() map() reduce() slice()
getAllItems()
navigateToCart() checkoutCart()
calcDeliveryCharges() getOrderConfirmation()
BUSINESS LAYER
CART OPERATIONS
ITEM OPERATIONS
selectAddress() payAndContinue()
Array-Built Ins
calcBonusPoints()
© 2022 Thoughtworks | Confidential
 Dynamic systems
 Distribution
 Data heavy systems
 Concurrent systems
FP is more suitable for
24
© 2022 Thoughtworks | Confidential
Other FP languages
25
• Elixir
• Erlang
• Common Lisp
• Haskell
• F#
• Clojure
• Elm
• Racket
• OCaml
• Idris
• PureScript
• Wolfram
• Scala
• Python
• Kotlin
• JavaScript
© 2022 Thoughtworks | Confidential
● Data immutability affects performance. If
performance takes a hit , then code will have to be
refactored
● Recursion is complex than loop iteration
Disadvantages
26
© 2022 Thoughtworks | Confidential
References
27
https://www.manning.com/books/grokking-simplicity
https://www.youtube.com/watch?v=BQ-9e13kJ58&t=2035s
https://www.youtube.com/watch?v=sCAR8ZPM6ew
https://dev.to/darkmavis1980/a-practical-example-on-how-to-use-currying-in-javascript-1ae9
© 2022 Thoughtworks | Confidential 28
THANK YOU !!

More Related Content

Similar to SelConf_Final_Final.pptx

Similar to SelConf_Final_Final.pptx (20)

Kanverse.ai - InsurTech Innovation Award 2022
Kanverse.ai - InsurTech Innovation Award 2022Kanverse.ai - InsurTech Innovation Award 2022
Kanverse.ai - InsurTech Innovation Award 2022
 
CMDB Building Blocks
CMDB Building BlocksCMDB Building Blocks
CMDB Building Blocks
 
Preparing_for_PCA_Workbook.pptx
Preparing_for_PCA_Workbook.pptxPreparing_for_PCA_Workbook.pptx
Preparing_for_PCA_Workbook.pptx
 
How to implement payment gateway integration for non-credit card on Magento2
How to implement payment gateway integration for non-credit card on Magento2How to implement payment gateway integration for non-credit card on Magento2
How to implement payment gateway integration for non-credit card on Magento2
 
Partner Briefing_January 25 (FINAL).pptx
Partner Briefing_January 25 (FINAL).pptxPartner Briefing_January 25 (FINAL).pptx
Partner Briefing_January 25 (FINAL).pptx
 
Enhanced governance and tag depoloyment with GTM Templates - Yasen Lilov | Me...
Enhanced governance and tag depoloyment with GTM Templates - Yasen Lilov | Me...Enhanced governance and tag depoloyment with GTM Templates - Yasen Lilov | Me...
Enhanced governance and tag depoloyment with GTM Templates - Yasen Lilov | Me...
 
OPS Executive insights Webinar - Tanzu Slides
OPS Executive insights Webinar - Tanzu SlidesOPS Executive insights Webinar - Tanzu Slides
OPS Executive insights Webinar - Tanzu Slides
 
What is Comindware
What is ComindwareWhat is Comindware
What is Comindware
 
Streamline Incentives with Oracle Incentive Cloud Compensation | SoftClouds I...
Streamline Incentives with Oracle Incentive Cloud Compensation | SoftClouds I...Streamline Incentives with Oracle Incentive Cloud Compensation | SoftClouds I...
Streamline Incentives with Oracle Incentive Cloud Compensation | SoftClouds I...
 
Accelerate Application Migration - August 5, 2020
Accelerate Application Migration - August 5, 2020Accelerate Application Migration - August 5, 2020
Accelerate Application Migration - August 5, 2020
 
SwiftAnt EDI Services_Microsoft Gold Partner
SwiftAnt EDI Services_Microsoft Gold PartnerSwiftAnt EDI Services_Microsoft Gold Partner
SwiftAnt EDI Services_Microsoft Gold Partner
 
Business iQ: What It Is and How to Start - AppD Summit Europe
Business iQ: What It Is and How to Start - AppD Summit EuropeBusiness iQ: What It Is and How to Start - AppD Summit Europe
Business iQ: What It Is and How to Start - AppD Summit Europe
 
Preparing_for_PCA_Workbook.pptx
Preparing_for_PCA_Workbook.pptxPreparing_for_PCA_Workbook.pptx
Preparing_for_PCA_Workbook.pptx
 
A long way from Monolith to Service Isolated Architecture #MM19NL
A long way from Monolith to Service Isolated Architecture #MM19NLA long way from Monolith to Service Isolated Architecture #MM19NL
A long way from Monolith to Service Isolated Architecture #MM19NL
 
Supply Chain Management
Supply Chain ManagementSupply Chain Management
Supply Chain Management
 
Overview and Walkthrough of the Application Programming Model with SAP Cloud ...
Overview and Walkthrough of the Application Programming Model with SAP Cloud ...Overview and Walkthrough of the Application Programming Model with SAP Cloud ...
Overview and Walkthrough of the Application Programming Model with SAP Cloud ...
 
Con1169 office depot scm cloud mbx session
Con1169 office depot scm cloud mbx sessionCon1169 office depot scm cloud mbx session
Con1169 office depot scm cloud mbx session
 
Ecommerce Proposal Template Powerpoint Presentation Slides
Ecommerce Proposal Template Powerpoint Presentation SlidesEcommerce Proposal Template Powerpoint Presentation Slides
Ecommerce Proposal Template Powerpoint Presentation Slides
 
Performance Testing
Performance TestingPerformance Testing
Performance Testing
 
Agados biz. introductio
Agados biz. introductioAgados biz. introductio
Agados biz. introductio
 

Recently uploaded

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Dr.Costas Sachpazis
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
Tonystark477637
 

Recently uploaded (20)

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 

SelConf_Final_Final.pptx

  • 1. © 2022 Thoughtworks | Confidential Functional Programming in Test Automation -Narmadha & Sameena 1
  • 2. © 2022 Thoughtworks | Confidential 2 Narmadha Ramasamy Senior Consultant @Thoughtworks linkedin.com/in/narmadha956/ narmadha956@gmail.com Sameena Syed Senior Consultant @Thoughtworks linkedin.com/in/sameena-syed/ sameena9010@gmail.com
  • 3. © 2022 Thoughtworks | Confidential Functional Programming Functional Programming is a programming style where we use Pure functions extensively 3
  • 4. © 2022 Thoughtworks | Confidential ● Functions as variables ● Functions as arguments ● Functions as return types First class citizens – FUNCTIONS 4
  • 5. © 2022 Thoughtworks | Confidential Impure Functions f(x) Pure Functions f(x) Pure & Impure Functions 5 Same input Same output Same input Output 1 Output 2 ……….
  • 6. © 2022 Thoughtworks | Confidential Business Requirement 6 Hey Team ! Our app juice shop is ready, can we have automated tests to test different workflows
  • 7. © 2022 Thoughtworks | Confidential Functional Programming thinking  IMPURE FUNCTIONS (Actions)  PURE FUNCTIONS (Calculations)  DATA (Data about events, users etc) 7
  • 8. © 2022 Thoughtworks | Confidential Application Tour 8
  • 9. © 2022 Thoughtworks | Confidential Business use case Buy juice items from juice shop o Given user is logged in o When cart is empty o Then user should be able to select juice items and checkout successfully 9 We need to ensure checkout of juice items works as expected, as it’s the most sold type of item.
  • 10. © 2022 Thoughtworks | Confidential User Journey 1. Login to application with registered user 2. Get all items in Juice shop portal 3. Add juices to cart 4. Navigate to cart 5. Checkout items in cart 6. Select delivery address 7. Select delivery speed 8. Select payment method 9. Validate cart total and checkout 10
  • 11. © 2022 Thoughtworks | Confidential CODE Walkthrough 11
  • 12. © 2022 Thoughtworks | Confidential 12 1. Launch application -> launchApplication() 2. Login to application with registered user -> login() 3. Get all items in Juice shop portal -> getAllItems() 4. Add juices to cart -> getJuiceTypeItems(), addJuicesToCart() 5. Navigate to cart -> navigateToCart() 6. Checkout items in cart -> checkoutCart() 7. Select delivery address -> selectAddress() 8. Select delivery speed -> selectDelivery() 9. Select payment method -> payAndContinue() 10. Validate total price -> assert.equal(totalPriceDisplayed,expectedTotalPrice) 11. Validate order confirmation -> getOrderConfirmation() Method Mapping
  • 13. © 2022 Thoughtworks | Confidential Business Requirement 13 Hey Team ! Looks like we are getting more data and business flows, is our existing automated tests are scalable ???
  • 14. © 2022 Thoughtworks | Confidential  Map : Returns list of same length as input  Filter : Returns list reduced length as input  Reduce : Returns single object Commonly used Higher Order Functions 14
  • 15. © 2022 Thoughtworks | Confidential CODE Refactoring 16
  • 16. © 2022 Thoughtworks | Confidential Call Graph 17 expectedTotalPrice() addJuicesToCart() getJuiceTypeItems() filter() map() reduce() slice() getAllItems() navigateToCart() checkoutCart() selectDeliverySpeed() getOrderConfirmation() BUSINESS LAYER CART OPERATIONS ITEM OPERATIONS selectAddress() payAndContinue() Array-Built Ins
  • 17. © 2022 Thoughtworks | Confidential  Always separate out business rules as functions  Using call graph to design test case  Extract calculations from actions as much as possible  Keep data immutable  Avoid implicit input & output instead use function arguments & return statements  Refactor specific names to generic names  Duplicate code is code smell Practices to Follow 18
  • 18. © 2022 Thoughtworks | Confidential New Requirement 19 Clients have decided to give bonus points for cart price above 999 ! Can we develop this asap
  • 19. © 2022 Thoughtworks | Confidential Currying How to stop passing the same arguments repeatedly to different functions?? • Use currying Transformation of a function with multiple arguments to a function with single arg and returns a function that takes the other args 20
  • 20. © 2022 Thoughtworks | Confidential CODE Refactoring 22
  • 21. © 2022 Thoughtworks | Confidential Call Graph 23 expectedTotalPrice() addItemsToCart() geRequiredItems() filter() map() reduce() slice() getAllItems() navigateToCart() checkoutCart() calcDeliveryCharges() getOrderConfirmation() BUSINESS LAYER CART OPERATIONS ITEM OPERATIONS selectAddress() payAndContinue() Array-Built Ins calcBonusPoints()
  • 22. © 2022 Thoughtworks | Confidential  Dynamic systems  Distribution  Data heavy systems  Concurrent systems FP is more suitable for 24
  • 23. © 2022 Thoughtworks | Confidential Other FP languages 25 • Elixir • Erlang • Common Lisp • Haskell • F# • Clojure • Elm • Racket • OCaml • Idris • PureScript • Wolfram • Scala • Python • Kotlin • JavaScript
  • 24. © 2022 Thoughtworks | Confidential ● Data immutability affects performance. If performance takes a hit , then code will have to be refactored ● Recursion is complex than loop iteration Disadvantages 26
  • 25. © 2022 Thoughtworks | Confidential References 27 https://www.manning.com/books/grokking-simplicity https://www.youtube.com/watch?v=BQ-9e13kJ58&t=2035s https://www.youtube.com/watch?v=sCAR8ZPM6ew https://dev.to/darkmavis1980/a-practical-example-on-how-to-use-currying-in-javascript-1ae9
  • 26. © 2022 Thoughtworks | Confidential 28 THANK YOU !!

Editor's Notes

  1. Business layer should only call cart layer