SlideShare una empresa de Scribd logo
1 de 15
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
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
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...
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
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}"
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

|
|
|
|
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 )
}
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'
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
|
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
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
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'] }
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

|
|
|
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")
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()

Más contenido relacionado

La actualidad más candente

node.js practical guide to serverside javascript
node.js practical guide to serverside javascriptnode.js practical guide to serverside javascript
node.js practical guide to serverside javascript
Eldar Djafarov
 

La actualidad más candente (19)

Anay - Fluent interfaces in testing
Anay - Fluent interfaces in testingAnay - Fluent interfaces in testing
Anay - Fluent interfaces in testing
 
node.js practical guide to serverside javascript
node.js practical guide to serverside javascriptnode.js practical guide to serverside javascript
node.js practical guide to serverside javascript
 
Unit Testing Express Middleware
Unit Testing Express MiddlewareUnit Testing Express Middleware
Unit Testing Express Middleware
 
Dropwizard Introduction
Dropwizard IntroductionDropwizard Introduction
Dropwizard Introduction
 
Amazon Web Service - Basics
Amazon Web Service - BasicsAmazon Web Service - Basics
Amazon Web Service - Basics
 
Python tools for testing web services over HTTP
Python tools for testing web services over HTTPPython tools for testing web services over HTTP
Python tools for testing web services over HTTP
 
RSpec 3.0: Under the Covers
RSpec 3.0: Under the CoversRSpec 3.0: Under the Covers
RSpec 3.0: Under the Covers
 
Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to MissJava Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss
 
Wonderful csom sps barcelona
Wonderful csom sps barcelonaWonderful csom sps barcelona
Wonderful csom sps barcelona
 
Making the Most of Your Gradle Build
Making the Most of Your Gradle BuildMaking the Most of Your Gradle Build
Making the Most of Your Gradle Build
 
Swift LA Meetup at eHarmony- What's New in Swift 2.0
Swift LA Meetup at eHarmony- What's New in Swift 2.0Swift LA Meetup at eHarmony- What's New in Swift 2.0
Swift LA Meetup at eHarmony- What's New in Swift 2.0
 
Take Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainersTake Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainers
 
Connecting to Web Services on Android
Connecting to Web Services on AndroidConnecting to Web Services on Android
Connecting to Web Services on Android
 
Making the Most of Your Gradle Build
Making the Most of Your Gradle BuildMaking the Most of Your Gradle Build
Making the Most of Your Gradle Build
 
Evolution of the REST API
Evolution of the REST APIEvolution of the REST API
Evolution of the REST API
 
Testing the Grails Spring Security Plugins
Testing the Grails Spring Security PluginsTesting the Grails Spring Security Plugins
Testing the Grails Spring Security Plugins
 
Building domain-specific testing tools : lessons learned from the Apache Slin...
Building domain-specific testing tools : lessons learned from the Apache Slin...Building domain-specific testing tools : lessons learned from the Apache Slin...
Building domain-specific testing tools : lessons learned from the Apache Slin...
 
Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss
 
The JavaFX Ecosystem
The JavaFX EcosystemThe JavaFX Ecosystem
The JavaFX Ecosystem
 

Destacado

Testing hardware
Testing hardwareTesting hardware

Destacado (8)

Testing hardware
Testing hardwareTesting hardware
Testing hardware
 
Testowanie w parach - Testwarez 2016
Testowanie w parach - Testwarez 2016Testowanie w parach - Testwarez 2016
Testowanie w parach - Testwarez 2016
 
Tester.pl - Numer 6
Tester.pl - Numer 6Tester.pl - Numer 6
Tester.pl - Numer 6
 
Mistrzostwa w testowaniu oprogramowania - prezentacja z TestWarez 2012
Mistrzostwa w testowaniu oprogramowania - prezentacja z TestWarez 2012Mistrzostwa w testowaniu oprogramowania - prezentacja z TestWarez 2012
Mistrzostwa w testowaniu oprogramowania - prezentacja z TestWarez 2012
 
Tester.pl - Numer 1
Tester.pl - Numer 1Tester.pl - Numer 1
Tester.pl - Numer 1
 
Google Testing Testwarez
Google Testing TestwarezGoogle Testing Testwarez
Google Testing Testwarez
 
Testowanie eksploracyjne - warsztat testerzy.pl na TestWarez 2011
Testowanie eksploracyjne - warsztat testerzy.pl na TestWarez 2011Testowanie eksploracyjne - warsztat testerzy.pl na TestWarez 2011
Testowanie eksploracyjne - warsztat testerzy.pl na TestWarez 2011
 
ONTOLOGIES – HOW TO AVOID MESS AND TRULY DESIGN YOUR CUCUMBER SCENARIOS
ONTOLOGIES – HOW TO AVOID MESS AND TRULY DESIGN YOUR CUCUMBER SCENARIOSONTOLOGIES – HOW TO AVOID MESS AND TRULY DESIGN YOUR CUCUMBER SCENARIOS
ONTOLOGIES – HOW TO AVOID MESS AND TRULY DESIGN YOUR CUCUMBER SCENARIOS
 

Similar a Testwarez 2013 - Warsztat SoapUI

Taking Advantage of the SharePoint 2013 REST API
Taking Advantage of the SharePoint 2013 REST APITaking Advantage of the SharePoint 2013 REST API
Taking Advantage of the SharePoint 2013 REST API
Eric Shupps
 
Lets have some fun with twilio open tok
Lets have some fun with   twilio open tokLets have some fun with   twilio open tok
Lets have some fun with twilio open tok
mirahman
 
RESTful services
RESTful servicesRESTful services
RESTful services
gouthamrv
 
TechDays 2013 Jari Kallonen: What's New WebForms 4.5
TechDays 2013 Jari Kallonen: What's New WebForms 4.5TechDays 2013 Jari Kallonen: What's New WebForms 4.5
TechDays 2013 Jari Kallonen: What's New WebForms 4.5
Tieturi Oy
 
Pentesting web applications
Pentesting web applicationsPentesting web applications
Pentesting web applications
Satish b
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
Gavin Roy
 

Similar a Testwarez 2013 - Warsztat SoapUI (20)

API Days Paris - Automatic Testing of (RESTful) API Documentation
API Days Paris - Automatic Testing of (RESTful) API DocumentationAPI Days Paris - Automatic Testing of (RESTful) API Documentation
API Days Paris - Automatic Testing of (RESTful) API Documentation
 
Automating Cloud Operations: Everything You Wanted to Know about cURL and REST
Automating Cloud Operations: Everything You Wanted to Know about cURL and RESTAutomating Cloud Operations: Everything You Wanted to Know about cURL and REST
Automating Cloud Operations: Everything You Wanted to Know about cURL and REST
 
Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.
 
API Days Australia - Automatic Testing of (RESTful) API Documentation
API Days Australia  - Automatic Testing of (RESTful) API DocumentationAPI Days Australia  - Automatic Testing of (RESTful) API Documentation
API Days Australia - Automatic Testing of (RESTful) API Documentation
 
Taking Advantage of the SharePoint 2013 REST API
Taking Advantage of the SharePoint 2013 REST APITaking Advantage of the SharePoint 2013 REST API
Taking Advantage of the SharePoint 2013 REST API
 
Lets have some fun with twilio open tok
Lets have some fun with   twilio open tokLets have some fun with   twilio open tok
Lets have some fun with twilio open tok
 
Security enforcement of Java Microservices with Apiman & Keycloak
Security enforcement of Java Microservices with Apiman & KeycloakSecurity enforcement of Java Microservices with Apiman & Keycloak
Security enforcement of Java Microservices with Apiman & Keycloak
 
Web api
Web apiWeb api
Web api
 
RESTful services
RESTful servicesRESTful services
RESTful services
 
TechDays 2013 Jari Kallonen: What's New WebForms 4.5
TechDays 2013 Jari Kallonen: What's New WebForms 4.5TechDays 2013 Jari Kallonen: What's New WebForms 4.5
TechDays 2013 Jari Kallonen: What's New WebForms 4.5
 
Pentesting web applications
Pentesting web applicationsPentesting web applications
Pentesting web applications
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
 
Web Services Automated Testing via SoapUI Tool
Web Services Automated Testing via SoapUI ToolWeb Services Automated Testing via SoapUI Tool
Web Services Automated Testing via SoapUI Tool
 
Web Services Security
Web Services SecurityWeb Services Security
Web Services Security
 
Palestra VCR
Palestra VCRPalestra VCR
Palestra VCR
 
Infrastructure as Code: Manage your Architecture with Git
Infrastructure as Code: Manage your Architecture with GitInfrastructure as Code: Manage your Architecture with Git
Infrastructure as Code: Manage your Architecture with Git
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
 
Django Tastypie 101
Django Tastypie 101Django Tastypie 101
Django Tastypie 101
 
Introduction to the SharePoint Client Object Model and REST API
Introduction to the SharePoint Client Object Model and REST APIIntroduction to the SharePoint Client Object Model and REST API
Introduction to the SharePoint Client Object Model and REST API
 
REST APIs in the context of single-page applications
REST APIs in the context of single-page applicationsREST APIs in the context of single-page applications
REST APIs in the context of single-page applications
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 

Testwarez 2013 - Warsztat SoapUI

  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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()

Notas del editor

  1. 103fbd60