Successfully reported this slideshow.
Your SlideShare is downloading. ×

API Testing. Streamline your testing process.

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 84 Ad

API Testing. Streamline your testing process.

Download to read offline

Slides from IT talk: «API Testing. Streamline your testing process. A step by step tutorial»

Code on github: https://github.com/a-oleynik/soap-ui
Webinar on youtube: https://www.youtube.com/watch?v=x2ALtuCjuUo

DataArt P. https://www.meetup.com/ru-RU/DataArt-Wroclaw-IT-talk/events/246967484/?eventId=246967484 Wroclaw, 2018, February 15

Slides from IT talk: «API Testing. Streamline your testing process. A step by step tutorial»

Code on github: https://github.com/a-oleynik/soap-ui
Webinar on youtube: https://www.youtube.com/watch?v=x2ALtuCjuUo

DataArt P. https://www.meetup.com/ru-RU/DataArt-Wroclaw-IT-talk/events/246967484/?eventId=246967484 Wroclaw, 2018, February 15

Advertisement
Advertisement

More Related Content

Slideshows for you (20)

Similar to API Testing. Streamline your testing process. (20)

Advertisement

Recently uploaded (20)

Advertisement

API Testing. Streamline your testing process.

  1. 1. API Testing: Streamline your testing process Andrii Olieinik Senior QA Automation Engineer
  2. 2. About me • Senior QA Automation Engineer • About 10 years of work in Quality Assurance area • PhD, Theoretical physics 2
  3. 3. Agenda • UI testing vs. API testing • Testing pyramid • HTTP/HTTPS • Web services • SOAP • REST • Tools • Postman • SoapUI • REST • Homework 3
  4. 4. UI test duration 4
  5. 5. Automated UI testing vs. automated API testing Automated API test Automated UI test Depends on API yes yes Depends on UI no yes Duration ~1..10^2 ms ~1..10^2 s and more 5
  6. 6. Testing pyramid 6 Unit tests API tests GUI tests
  7. 7. Ice Cream Cone 7
  8. 8. Testing Cupcake 8
  9. 9. Testing pyramid 9 Unit tests API tests GUI tests
  10. 10. Testing pyramid 10 Unit tests API tests GUI tests
  11. 11. Web services • The W3C defines a "Web service" as "a software system designed to support interoperable machine-to-machine interaction over a network". • In a Web service, Web technology such as the HTTP, originally designed for human-to-machine communication, is utilized for machine-to-machine communication, more specifically for transferring machine readable file formats such as XML and JSON. Types: • SOAP • RESTful • … 11
  12. 12. Web services 12
  13. 13. Hypertext Transfer Protocol • The Hypertext Transfer Protocol (HTTP) is an application protocol for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web. 13
  14. 14. HTTP • HTTP is connectionless • HTTP is media independent • HTTP is stateless 14
  15. 15. HTTP • HTTP Version (HTTP/1.0) • Uniform Resource Identifiers • Character Sets (US-ASCII) • Content Encodings (Accept-encoding: gzip) • Media Types (application/json) • Header Fields • Message Body • Response code 15
  16. 16. HTTP headers 16
  17. 17. HTTP methods • GET - to retrieve information from the given server using a given URI. Requests using GET should only retrieve data and should have no other effect on the data • HEAD - Same as GET, but it transfers the status line and the header section only • POST - A POST request is used to send data to the server using HTML forms • PUT - Replaces all the current representations of the target resource with the uploaded content • DELETE - Removes all the current representations of the target resource given by URI • CONNECT - Establishes a tunnel to the server identified by a given URI • OPTIONS - Describe the communication options for the target resource • TRACE - Performs a message loop back test along with the path to the target resource • PATCH - The PATCH method applies partial modifications to a resource 17
  18. 18. REST • REST stands for Representational State Transfer. (It is sometimes spelled "ReST".) It relies on a stateless, client-server, cacheable communications protocol -- and in virtually all cases, the HTTP protocol is used. REST is an architecture style for designing networked applications. • REST is an architecture style for designing networked applications. The idea is that, rather than using complex mechanisms such as CORBA, RPC or SOAP to connect between machines, simple HTTP is used to make calls between machines. 18
  19. 19. REST demo • JSONPlaceholder: https://jsonplaceholder.typicode.com/ • National Digital Forecast Database (NDFD) REST Web Service: http://graphical.weather.gov/xml/rest.php • Narodowy Bank Polski: http://api.nbp.pl/en.html 19
  20. 20. REST • Endpoint • Resource • Methods (Post/Get/…) • Media type for the data (JSON, XML) 20
  21. 21. CRUD CRUD • Create • Read • Update • Delete HTTP • Post • Get • Put • Delete 21
  22. 22. Tools • Postman • SoapUI • Jmeter • REST Assured: https://github.com/rest-assured/rest-assured • Apache HttpClient: http://hc.apache.org • Async Http Client: https://github.com/AsyncHttpClient/async-http-client • RestTemplate https://docs.spring.io/spring/docs/current/javadoc- api/org/springframework/web/client/RestTemplate.html • … 22
  23. 23. Postman 23
  24. 24. Postman • REST requests • SOAP requests +/- • Collections (test sets) • Scripts • Variables • Execute from command line (with Newman) • Integration with CI (with Newman) • JUnit reports (with Newman) • Web Service Mocking 24
  25. 25. SoapUI 25
  26. 26. SoapUI • REST requests • SOAP requests • Tests • Test suits • Scripts • Variables • Execute from command line • Integration with CI • Integration with Maven • JUnit reports • Web Service Mocking 26
  27. 27. SoapUI testcase 27
  28. 28. SoapUI assertions 28
  29. 29. More details • Postman docs: https://www.getpostman.com/docs/ • Scripts in Postman: https://www.getpostman.com/docs/postman/scripts/intro_to_scripts • Structuring and Running Tests (SoapUI): https://www.soapui.org/Functional-Testing/structuring- and-running-tests.html • Getting Started with REST Testing in SoapUI: https://www.soapui.org/rest-testing/getting- started.html • Newman: https://github.com/postmanlabs/newman • JSON Formatter & Validator: https://jsonformatter.curiousconcept.com/ • JSONLint - The JSON Validator: http://jsonlint.com/ 29
  30. 30. WSDL • Web Services Description Language (WSDL, pronounced 'wiz-dul') is an XML-based language that is used for describing the functionality offered by a Web service. A WSDL description of a web service (also referred to as a WSDL file) provides a machine-readable description of how the service can be called, what parameters it expects and what data structures it returns. WSDL stands for Web Services Description Language • WSDL is used to describe web services • WSDL is written in XML • WSDL is a W3C recommendation 30
  31. 31. WSDL parts • Data types definition (types) – the definition of sent and received XML service messages. • Data elements (message) – message used by web-service. • Abstract operations (portType) – the list of operations that can be performed with messages. • Service binding (binding) – the way the message will be delivered 31
  32. 32. WSDL examples • ISBN Test: http://webservices.daehosting.com/services/isbnservice.wso?WSDL • Country Information: http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL • Number Conversion: http://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL • Bankleitzahlen Service: http://www.thomas-bayer.com/axis2/services/BLZService?wsdl • National Digital Forecast Database (NDFD) SOAP Web Service: http://graphical.weather.gov/xml/ 32
  33. 33. SOAP • SOAP stands for Simple Object Access Protocol • SOAP is an application communication protocol • SOAP is a format for sending and receiving messages • SOAP is platform independent • SOAP is based on XML • SOAP is a W3C recommendation 33
  34. 34. SOAP 34
  35. 35. SOAP 35
  36. 36. Tools • Postman • SoapUI • Axis: http://axis.apache.org/axis2/java/core/ • REST Assured: https://github.com/rest-assured/rest-assured • Apache HttpClient: http://hc.apache.org • Async Http Client: https://github.com/AsyncHttpClient/async-http-client • RestTemplate https://docs.spring.io/spring/docs/current/javadoc- api/org/springframework/web/client/RestTemplate.html • … 36
  37. 37. More details • w3schools about SOAP: http://www.w3schools.com/xml/xml_soap.asp • w3schools about WSDL: http://www.w3schools.com/xml/xml_wsdl.asp • SoapUI: https://www.soapui.org/downloads/soapui/alternate-platforms.html • Your First SoapUI Project: https://www.soapui.org/getting-started/your-first-soapui-project.html 37
  38. 38. Possible task • Create a project against any weather API. For example you can take NIST SOAP or REST service. Get temperature for San Francisco at 9 a.m. on the day of your choice. Add assertion if the temperature is grater than 0. 38
  39. 39. Questions • Questions? 39
  40. 40. Project file • Project data are stored in separate xmls files 40
  41. 41. Properties • Project, TestSuite and TestCase have properties 41
  42. 42. Project properties 42
  43. 43. Properties Transfer • Transferring Property Values: https://www.soapui.org/functional-testing/properties/transferring- properties.html 43
  44. 44. Property Expansion • ${#Scope#Property-name[#xpath-expression]} • ${#Project#Property-name}refers to a Project Property • ${#TestSuite#Property-name} refers to a TestSuite Property • ${#TestCase#Property-name} refers to a TestCase Property • ${TestStep-name#Property-name} refers to a property in a named TestStep. 44
  45. 45. Assertions (Property Content) • Contains • Not Contains • JsonPath Count • JsonPath Existance Match • JsonPath Match • JsonPath RegEx Match • XPath Match • XQuery Math 45
  46. 46. Assertions (Property Content) 46
  47. 47. Assertions (Property Content) 47
  48. 48. Assertions (Property Content) • JsonPath Count 48
  49. 49. Assertions (Property Content) • JsonPath Match 49
  50. 50. Assertions (Compliance, Status and Standarts) • HTTP Download all resource • Invalid HTTP Status Codes • Not SOAP Fault • Schema Compliance • SOAP Fault • SOAP Request • SOAP Response • Valid HTTP Status Codes • WS-Addressing Request • WS-Addressing Response • WS-Security Status 50
  51. 51. Script assertion 51
  52. 52. Script assertion • JsonSlurper 52
  53. 53. Other assertions • SLA • JMS • JDBC • Security 53
  54. 54. Groovy scripts 54
  55. 55. Groovy scripts 55
  56. 56. Setup/TearDown scripts • Suite Setup/TearDown • TestCase Setup/TearDown 56
  57. 57. Data Driven testing 57
  58. 58. Data Driven testing 58
  59. 59. Data Driven testing 59
  60. 60. Custom reporting 60
  61. 61. Custom reporting 61
  62. 62. Custom reporting 62
  63. 63. More details (Groovy) • Groovy Documentation: http://groovy-lang.org/documentation.html • Groovy JDK API Documentation: http://groovy-lang.org/gdk.html • SoapUI Tips & Tricks: https://www.soapui.org/scripting-properties/tips-tricks.html • 10 Groovy scripts on your finger tips – soapUI: https://learnsoapui.wordpress.com/2011/07/17/10- groovy-scripts-on-your-finger-tips-soapui/ • SoapUI Groovy: Slurping JSON in Script Assertions: https://thetestsuite.wordpress.com/2013/09/30/soapui-groovy-slurping-json-in-script-assertions/ • XML Parsing in soapUI: http://www.robert-nemet.com/2011/11/groovy-xml-parsing-in-soapui.html 63
  64. 64. TestRunner 64
  65. 65. TestRunner (options) • ..SoapUI-5.2.1bintestrunner.bat • testrunner.bat -s"TestSuite 1" -r -j D:REST-Project-1-soapui-project.xml -f D:SoapUI-5.2.1report • a : Turns on exporting of all test results, not only errors • c : The TestCase to run, used to narrow down the tests to run • e : The endpoint to use when invoking test-requests, overrides the endpoint set in the project file • f : Specifies the root folder to which test results should be exported • j : Turns on exporting of JUnit-compatible reports, see below • P : Sets project property with name=value, e.g. -Pendpoint=Value1 -PsomeOtherProperty=value2 • s : The TestSuite to run, used to narrow down the tests to run 65
  66. 66. SoapUI logs • By default in ..SoapUI-5.2.1bin • soapui-log4j.xml • soapui.log • soapui-errors.log • global-groovy.log 66
  67. 67. Authorization • Steps to run Twitter API with SoapUI: http://acodediary.com/twitter-api-with-soapui/ 67
  68. 68. Authorization (generate bearer token) 68
  69. 69. Authorization (get access token) 69
  70. 70. Authorization (result) 70
  71. 71. Integration with Maven (project structure) • To execute project run command: mvn integration-test 71
  72. 72. Integration with Maven (project structure) 72
  73. 73. Integration with Maven (execution result) 73
  74. 74. Integration with Maven (pom.xml) 74
  75. 75. Integration with Maven (pom.xml) 75
  76. 76. Integration with Maven (extensions) • Put additional jars into ext folder • Or add new module to the project 76
  77. 77. Listeners • Create my-listeners.xml file in SoapUI-5.2.1binlisteners • Create MyListener.java, compile it in jar file and put in SoapUI-5.2.1binext • Create a directory build • Run java compilation from the command line: • javac -cp soapui-5.2.1.jar com/dataart/api/listeners/MyListener.java -d ./build • Go to the build folder (cd build) and create a jar • jar cvf YourJar.jar * 77
  78. 78. Listeners (source code) 78
  79. 79. Listeners (result) 79
  80. 80. More details • Rupert Anderson SoapUI Cookbook • Charitha Kankanamge Web Services Testing with soapUI 80
  81. 81. More details • JSONPath - XPath for JSON: http://goessner.net/articles/JsonPath/ • Running Functional Tests (TestRunner): https://www.soapui.org/test-automation/running-functional- tests.html • SoapUI source code: https://github.com/SmartBear/soapui • SoapUI and Maven: https://www.soapui.org/test-automation/maven/maven-2-x.html • Source code in SoapUI maven: http://stackoverflow.com/questions/30320647/source-code-in- soapui-maven • Extending soapU: https://www.soapui.org/extension-plugins/old-style-extensions/developing-old- style-extensions.html • SoapUI JavaDoc: https://www.soapui.org/apidocs/allclasses-noframe.html 81
  82. 82. More details • Custom report: https://github.com/a-oleynik/SoapUI/blob/master/CustomReport.groovy • Maven project with SoapUI example: https://github.com/a-oleynik/SoapUI/tree/master/api-test • Listener code example: https://github.com/a-oleynik/SoapUI/tree/master/Listener 82
  83. 83. Possible task • Create custom report into an xml file. • Create a Data Driven test and read data from excel file. • Create a Maven project for your SoapUI project. Set the project up and execute it from the command line. 83
  84. 84. Questions • Questions? 84

×