Testwarez 2013 - Warsztat SoapUI

1,131 views

Published on

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

Testwarez 2013 - Warsztat SoapUI

  1. 1. Testy obciążeniowe Testy funkcjonalne Wsparcie dla popularnych protokołów Tworzenie testów metodą Drag and Drop Testy bezpieczeostwa Wbudowane statystyki Możliwośd używania skryptów Wsparcie dla SSL Automatyzacja Nagrywanie HTTP Symulacja usług sieciowych Wsparcie społeczności Sprawdzanie zgodności ze standardami
  2. 2. Agenda • Acceptance Test-Driven Development FEATURE: IN ORDER to manage contacts from various applications AS an international corporation I WANT a service with REST API • Some examples of soapUI usage • Some examples of Groovy scripts Resources: http://bit.ly/16FdgyK
  3. 3. REST GET http://localhost:8080/testwarez/contacts?q=Steve REQUEST METHOD GET RESOURCE BASE http://localhost:8080/testwarez RESOURCE PATH /contacts QUERY STRING q=Steve CONTENT-TYPE ... HEADER...
  4. 4. Scenario 1: Fetching all contacts GIVEN service available at base url AND database containing 5 contacts WHEN I send GET request for /contacts resource THEN I should receive response with code 200 AND 5 entity tags containing contact details
  5. 5. Displaying information in soapUI // Static text log.info "Displaying text in soapUI script log" // Dynamic text def query = "q=Jacek" log.info "Parameter query: ${query}" log.info "Parameter query: " + query // soapUI related variables log.info "Request for ${mockRequest.path}" log.info "method: ${mockRequest.httpRequest.method}" log.info "with params: ${mockRequest.httpRequest.queryString}" def dir = context.expand('${projectDir}'); log.info "Project saved in ${dir}"
  6. 6. Scenario 2: Fetching filtered contacts GIVEN service available at base url AND database provisioned according to the example WHEN I send GET request for /contacts?q=<query> THEN I should receive response containing <#> contacts Example: | query | rysiek | Steve | XNAS |# |1 |2 |0 | | | |
  7. 7. Returning file content in response import com.eviware.soapui.impl.wsdl.mock.WsdlMockResult def docRoot = mockRunner.mockService.docroot if ( queryString == "q=Steve" ) { mockRunner.returnFile ( mockRequest.httpResponse, new File("${docRoot}contacts-q-Steve") ) mockRequest.httpResponse.status = 200 return new WsdlMockResult( mockRequest ) }
  8. 8. Regular expressions // Let's define sample variables def testedString = "q=Steve&updated=2013-10-14" def pattern = /q=([^&]*.*)/ // ==~ tests, if String matches the pattern assert testedString ==~ pattern assert !("holla" ==~ pattern) // =~ return Matchers qParams = ( testedString =~ pattern ) assert qParams[0] =-[q=Steve, Steve] assert qParams[0][1] == 'Steve'
  9. 9. Scenario 3: Fetching contact by contactId GIVEN service available at base url WHEN I send GET request for /contacts/<contactId> THEN I should receive response with <code> AND content of message should contain <details> Example: | contactId | code | 103fbd | 200 | 000000 | 500 | details | | Bill Gates | | Fault |
  10. 10. soapUI API http://www.soapui.org/apidocs // Getting reference to project object def tc = testRunner.testCase def testStep = tc.testSteps["TestStep name"] // Setting or getting properties tc.setPropertyValue("contactId", "103fbd" ) testStep.getPropertyValue("ResponseAsXml") // Executing test step def result = testStep.run( testRunner, context ) //if( result.status == TestStepStatus.OK ){} // Running in load context if( context.LoadTestContext != null ) no = context.RunCount as Integer
  11. 11. Groovy lists // Defining lists def queries = ['rysiek', 'Steve', 'none'] def queriesAndNo = [['rysiek','1'], ['Steve', '2'], ['none', '0']] // Accessing list elements log.info queries[0] log.info "${queriesAndNo [0][0]}: ${queriesAndNo [0][1]}" log.info "${queriesAndNo [-1][0]}: ${queriesAndNo [-1][1]}" // Iterating over collection elements queriesAndNo.each { log.info "${it[0]}: ${it[1]}" } tc.metaClass.properties*.name
  12. 12. Groovy and XML // Parsing text def rootNode = new XmlSlurper().parseText( '<root><one a1="uno!"/><two>Some text!</two></root>' ) // Reading elements assert rootNode.name() == 'root' assert rootNode.one[0].@a1 == 'uno!' assert rootNode.two.text() == 'Some text!' rootNode.children().each { assert it.name() in ['one','two'] }
  13. 13. Scenario 4: Adding contact GIVEN service available at base url AND having contactId 103fbd in the database WHEN I send PUT request containing <contactId> THEN I should receive response with <status code> AND I should be able to get added Example: | contact details | 103fbf | 103fbd | status code | 200 | 403 | | |
  14. 14. Groovy and files // Opening file def file = new File("tmp") //Writing content of request to file file << mockRequest.httpRequest.inputStream // Reading from file file.readLines() // Other methods file.exists() file.renameTo("newFIleName")
  15. 15. Groovy and XML <entry> <id>103fbd60efd5725</id> <category>CEO</category> <title type="text">Bill Gates</title> <firstname>Bill</firstname> <lastname>Gates</lastname> </entry> // Opening xml file def entry = new XmlSlurper().parse(file) // Reading elements def id = entry.id.text() def category = entry.category as String det titleType = entry.title.@type.text()

×