Testwarez 2013 - Warsztat SoapUI
-
Upload
jacek-okrojek -
Category
Technology
-
view
583 -
download
6
description
Transcript of 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
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
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
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
// 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
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
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
// 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
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
// 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
// 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
// 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
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
// 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
// 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>