Testwarez 2013 - Warsztat SoapUI

15
Wsparcie dla popularnych protokołów Testy funkcjonalne Tworzenie testów metodą Drag and Drop Możliwość używania skryptów Testy bezpieczeństwa Symulacja usług sieciowych Wbudowane statystyki Testy obciążeniowe Automatyzacja Nagrywanie HTTP Sprawdzanie zgodności ze standardami Wsparcie dla SSL Wsparcie społecznośc

description

 

Transcript of Testwarez 2013 - Warsztat SoapUI

Page 1: Testwarez 2013 - Warsztat SoapUI

Wsparcie dla popularnych protokołów

Testy funkcjonalne

Tworzenie testów metodą Drag and Drop

Możliwość używania skryptów

Testy bezpieczeństwa

Symulacja usług sieciowych

Wbudowane statystyki

Testy obciążeniowe

Automatyzacja

Nagrywanie HTTP

Sprawdzanie zgodnościze standardami

Wsparcie dla SSL

Wsparcie społeczności

Page 2: Testwarez 2013 - Warsztat SoapUI

FEATURE:IN ORDER to manage contacts from various applicationsAS an international corporationI WANT a service with REST API

Agenda• Acceptance Test-Driven Development

• Some examples of soapUI usage• Some examples of Groovy scripts

Resources: http://bit.ly/16FdgyK

Page 3: Testwarez 2013 - Warsztat SoapUI

GET http://localhost:8080/testwarez/contacts?q=Steve

REQUEST METHOD GET RESOURCE BASE http://localhost:8080/testwarezRESOURCE PATH /contactsQUERY STRING q=SteveCONTENT-TYPE ...HEADER...

REST

Page 4: Testwarez 2013 - Warsztat SoapUI

GIVEN service available at base urlAND database containing 5 contactsWHEN I send GET request for /contacts resourceTHEN I should receive response with code 200AND 5 entity tags containing contact details

Scenario 1: Fetching all contacts

Page 5: Testwarez 2013 - Warsztat SoapUI

// Static textlog.info "Displaying text in soapUI script log"

// Dynamic textdef query = "q=Jacek"log.info "Parameter query: ${query}"log.info "Parameter query: " + query

// soapUI related variableslog.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}"

Displaying information in soapUI

Page 6: Testwarez 2013 - Warsztat SoapUI

GIVEN service available at base urlAND database provisioned according to the exampleWHEN I send GET request for /contacts?q=<query>THEN I should receive response containing <#> contacts

Example:| query |# || rysiek |1 || Steve |2 || XNAS |0 |

Scenario 2: Fetching filtered contacts

Page 7: Testwarez 2013 - Warsztat SoapUI

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 )

}

Returning file content in response

Page 8: Testwarez 2013 - Warsztat SoapUI

// Let's define sample variablesdef testedString = "q=Steve&updated=2013-10-14"def pattern = /q=([^&]*.*)/

// ==~ tests, if String matches the pattern assert testedString ==~ pattern assert !("holla" ==~ pattern)

// =~ return MatchersqParams = ( testedString =~ pattern )assert qParams[0] =-[q=Steve, Steve] assert qParams[0][1] == 'Steve'

Regular expressions

Page 9: Testwarez 2013 - Warsztat SoapUI

GIVEN service available at base urlWHEN I send GET request for /contacts/<contactId>THEN I should receive response with <code>AND content of message should contain <details>

Example:| contactId | code | details || 103fbd | 200 | Bill Gates || 000000 | 500 | Fault |

Scenario 3: Fetching contact by contactId

Page 10: Testwarez 2013 - Warsztat SoapUI

// Getting reference to project objectdef tc = testRunner.testCasedef testStep = tc.testSteps["TestStep name"]

// Setting or getting propertiestc.setPropertyValue("contactId", "103fbd" )testStep.getPropertyValue("ResponseAsXml")

// Executing test stepdef result = testStep.run( testRunner, context )//if( result.status == TestStepStatus.OK ){}

// Running in load contextif( context.LoadTestContext != null ) no = context.RunCount as Integer

soapUI APIhttp://www.soapui.org/apidocs

Page 11: Testwarez 2013 - Warsztat SoapUI

// Defining lists def queries = ['rysiek', 'Steve', 'none']def queriesAndNo = [['rysiek','1'], ['Steve', '2'], ['none', '0']]

// Accessing list elementslog.info queries[0]log.info "${queriesAndNo [0][0]}: ${queriesAndNo [0][1]}"log.info "${queriesAndNo [-1][0]}: ${queriesAndNo [-1][1]}"

// Iterating over collection elementsqueriesAndNo.each { log.info "${it[0]}: ${it[1]}" }tc.metaClass.properties*.name

Groovy lists

Page 12: Testwarez 2013 - Warsztat SoapUI

// Parsing textdef rootNode = new XmlSlurper().parseText( '<root><one a1="uno!"/><two>Some text!</two></root>' )

// Reading elementsassert rootNode.name() == 'root' assert rootNode.one[0].@a1 == 'uno!' assert rootNode.two.text() == 'Some text!' rootNode.children().each { assert it.name() in ['one','two'] }

Groovy and XML

Page 13: Testwarez 2013 - Warsztat SoapUI

GIVEN service available at base urlAND having contactId 103fbd in the databaseWHEN 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 | status code || 103fbf | 200 || 103fbd | 403 |

Scenario 4: Adding contact

Page 14: Testwarez 2013 - Warsztat SoapUI

// Opening file def file = new File("tmp")

//Writing content of request to filefile << mockRequest.httpRequest.inputStream

// Reading from filefile.readLines()

// Other methodsfile.exists()file.renameTo("newFIleName")

Groovy and files

Page 15: Testwarez 2013 - Warsztat SoapUI

// Opening xml filedef entry = new XmlSlurper().parse(file)

// Reading elementsdef id = entry.id.text()def category = entry.category as Stringdet titleType = [email protected]()

Groovy and XML <entry> <id>103fbd60efd5725</id> <category>CEO</category> <title type="text">Bill Gates</title> <firstname>Bill</firstname> <lastname>Gates</lastname> </entry>