Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
RELOADED
SELENIUM
TESTING
PATTERNS
JAVAONE 2017
CON3276
SAN FRANCISCO - 4 OCTOBER 2017
JORGE HIDALGO
VICENTE GONZÁLEZ
ACCENTURE DELIVERY CENTER IN SPAIN
ACCENTURE GLOBAL JAVA CAPABILITY
SEQUELS ARE NEVER ANY GOOD… REALLY?
Copyright © 2017 Accenture All rights reserved.
PRESENTER INTRODUCTIONS
Jorge Hidalgo
@_deors
deors
Senior Technology Architect
Global Java Community Lead
Accenture Spain
Father of two children, husband, Irish flute &
whistle player, video gamer, master chief
apprentice, sci-fi ‘junkie’, Star Wars fan,
eternal Lego journeyman, gadget lover and
in love with Raspberry Pi computers
Vicente González
@viarellano
viarellano
Technology Architect
Global Java Community Champion
Accenture Spain
52 month experience husband, proud father
of 3 years old princess Regina, senior beach
user, cooking lover, associate paddle player,
master Feria de Abril enthusiast, Sevilla FC fan
and Pearl Jam ninja evangelizer
REVISITING SELENIUM BEST PRACTICES AND PATTERNS
Copyright 2017 Accenture. All rights reserved. 3
SELENIUM RELOADED
Tips for Setting up a Selenium Grid
XPath and Testability
Effective use of APIs and Interfaces
Continuous Testing for Microservices
#TIP 1:
USING JSON FOR
CONFIGURATION
Copyright 2017 Accenture. All rights reserved. 4
#TIP 1: USING JSON FOR CONFIGURATION
Copyright 2017 Accenture. All rights reserved. 5
#TIP 2:
MANAGING NODES
WITH
VISGRID
Copyright 2017 Accenture. All rights reserved. 6
#TIP 2: MANAGING NODES WITH VISGRID
Copyright 2017 Accenture. All rights reserved. 7
VISGRID
DESKTOP JAVA APPLICATION THAT HELPS MANAGING HUBS AND
NODES
• Download from https://codoid.com/wp-content/uploads/2017/09/Visgrid-<version>.zip
• Decompress Visgrid-<version>.zip
• java –jar visgrid-1.14.jar
VisGrid is provided by Codoid (https://codoid.com/) under Apache License
#TIP 3:
CREATING AN
EPHEMERAL GRID
Copyright 2017 Accenture. All rights reserved. 8
#TIP 3: CREATING AN EPHEMERAL GRID
Copyright 2017 Accenture. All rights reserved. 9
YOU CAN CONFIGURE AND LAUNCH NODES FROM YOUR
CODE
• Add the Selenium Server dependency to your POM
#TIP 3: CREATING AN EPHEMERAL GRID
Copyright 2017 Accenture. All rights reserved. 10
Use the GridLauncher to create server instances with different roles
#TIP 4:
MANAGING DRIVERS
BINARIES
WEBDRIVERMANAGER
Copyright 2017 Accenture. All rights reserved. 11
#TIP 4: MANAGING DRIVERS BINARIES
WEBDRIVERMANAGER
Copyright 2017 Accenture. All rights reserved. 12
WebDriverManager
An OpenSource Project that helps one of the most commons
nightmares while using Selenium:
Managing the webdriver binaries.
https://github.com/bonigarcia/webdrivermanager
#TIP 4: MANAGING DRIVERS WITH
WEBDRIVERMANAGER
Copyright 2017 Accenture. All rights reserved. 13
Add the dependency
Use the DriverManager
#TIP 4: MANAGING DRIVERS WITH
WEBDRIVERMANAGER
Copyright 2017 Accenture. All rights reserved. 14
Fully configurable using the API
Or parameters
#TIP 5:
XPATH IS NOT
UNDER YOUR
CONTROL
Copyright 2017 Accenture. All rights reserved. 15
XPath usage in Selenium depends on:
Native capabilities for XPath of each browser
If not available, Selenium provides its own implementation
#TIP5: XPATH IS NOT UNDER YOUR CONTROL
An example from the Selenium documentation
#TIP5: XPATH IS NOT UNDER YOUR CONTROL
COROLLARY:
NEVER, NEVER
USE XPATH
Using XPath for
interacting with
your web is not
a PREDICTABLE
nor
REPEATABLE
approach.
#TIP 6:
ALTERNATIVES:
PROVIDE PREDICTABLE
ID TO YOUR WEB
ELEMENTS
Copyright 2017 Accenture. All rights reserved. 19
Instead of investing a lot in creating highly
complicated ways to interact with the elements in
your application, consider change the application
instead
- Overriding ID of your web elements
- Creating anchor elements that helps on
accessing your elements
#TIP6: ALTERNATIVES: PROVIDE
PREDICTABLE ID TO YOUR WEB ELEMENTS
COROLLARY:
THINK ON
TESTABILITY
One of the
drivers when
you define your
web framework
should be the
ability to test
the application
#TIP 7:
USING API
EFFECTIVELY:
THE ISELECT
INTERFACE
Copyright 2017 Accenture. All rights reserved. 22
The ISelect Interface provide methods to interact
with elements of type Select.
The Select implementation provides methods for:
• Select (by Index, by Value, by Text)
• Deselect (All, by Index, by Value, by Text)
Works with MultiSelect
#TIP7: USING API EFFECTIVELY: THE ISELECT
INTERFACE
#TIP 8:
THE ACTION
BUILDER CAN
ALSO HELPS
Copyright 2017 Accenture. All rights reserved. 24
We are using Selenium to emulate human
interaction with the application under test
The Action Interface Builder can be useful when
try to explicitly guide the interaction through your
web page
#TIP8: THE ACTION BUILDER CAN ALSO
HELPS
#TIP 9:
CONTINUOUS
TESTING FOR
MICROSERVICES
Copyright 2017 Accenture. All rights reserved. 26
Jenkins as Orchestrator
CONTINUOUS DELIVERY PIPELINES
Copyright © 2017 Accenture. All rights reserved. 27
Test scope is limited
to one service/app
Test scope is
end-to-end
Jenkins as Orchestrator
CONTINUOUS DELIVERY TRIGGERS
Copyright © 2017 Accenture. All rights reserved. 28
Trigger on code/config/test change
Tests are in the same code repo
Trigger after any component
is promoted and deployed
Trigger on end-to-end test change
End-to-end tests (and test data)
are in separate code repo
May reuse tests from components
corollary:
consider it as an
application
When you are
using Selenium
you are creating
an application
to test your
application
creditsRepositories:
https://github.com/viarellano/deors.demos.petclinic
https://github.com/deors/deors.demos.petclinic
Presentation from JavaOne 2016
https://es.slideshare.net/deors/javaone-2016-con3080-testing-
java-web-applications-with-selenium-a-cookbook

More Related Content

JavaOne 2017 CON3276 - Selenium Testing Patterns Reloaded

  • 1. RELOADED SELENIUM TESTING PATTERNS JAVAONE 2017 CON3276 SAN FRANCISCO - 4 OCTOBER 2017 JORGE HIDALGO VICENTE GONZÁLEZ ACCENTURE DELIVERY CENTER IN SPAIN ACCENTURE GLOBAL JAVA CAPABILITY SEQUELS ARE NEVER ANY GOOD… REALLY?
  • 2. Copyright © 2017 Accenture All rights reserved. PRESENTER INTRODUCTIONS Jorge Hidalgo @_deors deors Senior Technology Architect Global Java Community Lead Accenture Spain Father of two children, husband, Irish flute & whistle player, video gamer, master chief apprentice, sci-fi ‘junkie’, Star Wars fan, eternal Lego journeyman, gadget lover and in love with Raspberry Pi computers Vicente González @viarellano viarellano Technology Architect Global Java Community Champion Accenture Spain 52 month experience husband, proud father of 3 years old princess Regina, senior beach user, cooking lover, associate paddle player, master Feria de Abril enthusiast, Sevilla FC fan and Pearl Jam ninja evangelizer
  • 3. REVISITING SELENIUM BEST PRACTICES AND PATTERNS Copyright 2017 Accenture. All rights reserved. 3 SELENIUM RELOADED Tips for Setting up a Selenium Grid XPath and Testability Effective use of APIs and Interfaces Continuous Testing for Microservices
  • 4. #TIP 1: USING JSON FOR CONFIGURATION Copyright 2017 Accenture. All rights reserved. 4
  • 5. #TIP 1: USING JSON FOR CONFIGURATION Copyright 2017 Accenture. All rights reserved. 5
  • 6. #TIP 2: MANAGING NODES WITH VISGRID Copyright 2017 Accenture. All rights reserved. 6
  • 7. #TIP 2: MANAGING NODES WITH VISGRID Copyright 2017 Accenture. All rights reserved. 7 VISGRID DESKTOP JAVA APPLICATION THAT HELPS MANAGING HUBS AND NODES • Download from https://codoid.com/wp-content/uploads/2017/09/Visgrid-<version>.zip • Decompress Visgrid-<version>.zip • java –jar visgrid-1.14.jar VisGrid is provided by Codoid (https://codoid.com/) under Apache License
  • 8. #TIP 3: CREATING AN EPHEMERAL GRID Copyright 2017 Accenture. All rights reserved. 8
  • 9. #TIP 3: CREATING AN EPHEMERAL GRID Copyright 2017 Accenture. All rights reserved. 9 YOU CAN CONFIGURE AND LAUNCH NODES FROM YOUR CODE • Add the Selenium Server dependency to your POM
  • 10. #TIP 3: CREATING AN EPHEMERAL GRID Copyright 2017 Accenture. All rights reserved. 10 Use the GridLauncher to create server instances with different roles
  • 11. #TIP 4: MANAGING DRIVERS BINARIES WEBDRIVERMANAGER Copyright 2017 Accenture. All rights reserved. 11
  • 12. #TIP 4: MANAGING DRIVERS BINARIES WEBDRIVERMANAGER Copyright 2017 Accenture. All rights reserved. 12 WebDriverManager An OpenSource Project that helps one of the most commons nightmares while using Selenium: Managing the webdriver binaries. https://github.com/bonigarcia/webdrivermanager
  • 13. #TIP 4: MANAGING DRIVERS WITH WEBDRIVERMANAGER Copyright 2017 Accenture. All rights reserved. 13 Add the dependency Use the DriverManager
  • 14. #TIP 4: MANAGING DRIVERS WITH WEBDRIVERMANAGER Copyright 2017 Accenture. All rights reserved. 14 Fully configurable using the API Or parameters
  • 15. #TIP 5: XPATH IS NOT UNDER YOUR CONTROL Copyright 2017 Accenture. All rights reserved. 15
  • 16. XPath usage in Selenium depends on: Native capabilities for XPath of each browser If not available, Selenium provides its own implementation #TIP5: XPATH IS NOT UNDER YOUR CONTROL
  • 17. An example from the Selenium documentation #TIP5: XPATH IS NOT UNDER YOUR CONTROL
  • 18. COROLLARY: NEVER, NEVER USE XPATH Using XPath for interacting with your web is not a PREDICTABLE nor REPEATABLE approach.
  • 19. #TIP 6: ALTERNATIVES: PROVIDE PREDICTABLE ID TO YOUR WEB ELEMENTS Copyright 2017 Accenture. All rights reserved. 19
  • 20. Instead of investing a lot in creating highly complicated ways to interact with the elements in your application, consider change the application instead - Overriding ID of your web elements - Creating anchor elements that helps on accessing your elements #TIP6: ALTERNATIVES: PROVIDE PREDICTABLE ID TO YOUR WEB ELEMENTS
  • 21. COROLLARY: THINK ON TESTABILITY One of the drivers when you define your web framework should be the ability to test the application
  • 22. #TIP 7: USING API EFFECTIVELY: THE ISELECT INTERFACE Copyright 2017 Accenture. All rights reserved. 22
  • 23. The ISelect Interface provide methods to interact with elements of type Select. The Select implementation provides methods for: • Select (by Index, by Value, by Text) • Deselect (All, by Index, by Value, by Text) Works with MultiSelect #TIP7: USING API EFFECTIVELY: THE ISELECT INTERFACE
  • 24. #TIP 8: THE ACTION BUILDER CAN ALSO HELPS Copyright 2017 Accenture. All rights reserved. 24
  • 25. We are using Selenium to emulate human interaction with the application under test The Action Interface Builder can be useful when try to explicitly guide the interaction through your web page #TIP8: THE ACTION BUILDER CAN ALSO HELPS
  • 26. #TIP 9: CONTINUOUS TESTING FOR MICROSERVICES Copyright 2017 Accenture. All rights reserved. 26
  • 27. Jenkins as Orchestrator CONTINUOUS DELIVERY PIPELINES Copyright © 2017 Accenture. All rights reserved. 27 Test scope is limited to one service/app Test scope is end-to-end
  • 28. Jenkins as Orchestrator CONTINUOUS DELIVERY TRIGGERS Copyright © 2017 Accenture. All rights reserved. 28 Trigger on code/config/test change Tests are in the same code repo Trigger after any component is promoted and deployed Trigger on end-to-end test change End-to-end tests (and test data) are in separate code repo May reuse tests from components
  • 29. corollary: consider it as an application When you are using Selenium you are creating an application to test your application
  • 30. creditsRepositories: https://github.com/viarellano/deors.demos.petclinic https://github.com/deors/deors.demos.petclinic Presentation from JavaOne 2016 https://es.slideshare.net/deors/javaone-2016-con3080-testing- java-web-applications-with-selenium-a-cookbook