Pinscher Testing

“How can I best get up the mountain?” – Just climb upwards, and don’t think about it! Friedrich Nietzsche

Month: November 2016

Relish – Living documentation

Relish helps your team get the most from Behaviour Driven Development (BDD). Publish, browse, search, and organize your Cucumber features on the web.

Relish’s benefits are:

  • Documentation that works – Gorgeous, trustworthy, living documentation from your executable Cucumber or Specflow features.
  • Find anything fast – Fast, comprehensive search index of all your projects’ documentation.
  • Safe and sound – Private projects, SSL as standard.
  • Read it how you like – Print it, create a beautiful PDF* or browse on the web.
  • See the bigger picture – Organize your acceptance tests to read like a traditional specification document. Customise navigation. Add markdown pages.
  • Stay up to date – Track progress with RSS or email summaries of changes*.

*coming soon

Relish Site

Relish Pro – plans and pricing

 

Relish Quick Start Guide
Publishing is done from the command-line, using the relish gem.
Install the gem:
gem install relish

Create a project:
relish projects:add my-best-project

or, if you want a private project:
relish projects:add my-secret-project:private

Write some documentation, by adding some markdown or Cucumber feature files in the features directory.
Push the documentation to Relish:
relish push my-best-project

Go and admire your features at http://relishapp.com/`username`/my-best-project

 

Available Commands
relish

collab # list the collaborators for a project

collab:add : # add a collaborator to a project – example: relish

collab:add rspec/rspec-core:justin

collab:remove : # remove a collaborator from a project – example: relish
collab:remove rspec/rspec-core:justin

config # display the contents of your options file

config:add

help # show this usage

projects # list your projects

projects:add / # add a project – append :private to make the project private – example: relish projects:add rspec/rspec-core:private

projects:remove # remove a project

projects:visibility : # set the status of a project – example: relish projects:visibility rspec/rspec-core:private

projects:rename : # rename a project’s handle – example: relish projects:rename rspec/rspec-core:rspec-corez

push : [path ] # push features to a project – is optional – is optional (defaults to ./features) – example: relish push rspec/rspec-core – example: relish push rspec/rspec-core:2.0

push:publisher # push markdown files to a publisher – example: relish push:publisher rspec

versions # list the versions for a project

versions:add : # add a version to a project – example: relish versions:add rspec/rspec-core:2.0

versions:remove : # remove a version from a project – example: relish versions:remove rspec/rspec-core:2.0
 

SoapUI and Groovy Scripting (second part)

The first part is here: SoapUI and Groovy Scripting (first part)

Modify an item for obtain for example an Error from Response

import groovy.json.JsonSlurper
import groovy.json.JsonOutput

def response = testRunner.testCase.getTestStepByName("/cart/{id}").getPropertyValue("response")
jsonSlurperResponse = new JsonSlurper().parseText(response)

if(jsonSlurperResponse.cartItems[1] != null) {
	
	def idDevice = jsonSlurperResponse.cartItems[1].id
	def request = '''
	{
	   	"context":    {
	     	"cartid": null,
	      	"flowid": null,
	      	"id": "defaultSessionContextId",
	      	"userid": "pinscherTesting"
		},
		"cartItems":
		[
			{"cartItemId":"","quantity":"6"}
		]
	} '''
	
	def jsonSlurperRequest = new JsonSlurper().parseText(request)
	jsonSlurperRequest.cartItems[0].cartItemId = idDevice
	def conv = JsonOutput.toJson(jsonSlurperRequest)
	def restRequest = testRunner.testCase.getTestStepByName('/cart/{id}/modify');
	restRequest.setPropertyValue('Request',conv);
} 

Insert a new item at the end of a json Response

def slurperNewDevice = new JsonSlurper().parseText(newDevice)
def slurperNewDeviceToKeep = new JsonSlurper().parseText(newDeviceToKeep)
def slurperResponse = new JsonSlurper().parseText(takeResponse)

slurperResponse << slurperNewDevice //add new device to list of device
slurperResponse << slurperNewDeviceToKeep
def map = ["devices":slurperResponse]
def deviceList  = JsonOutput.toJson(map)

def restRequest = testRunner.testCase.getTestStepByName("Create New Device")
restRequest.setPropertyValue('Request', deviceList)

Takes code from Response and set it like parameter in next Request

def String pinTmp = testRunner.testCase.getTestStepByName("/login").httpRequest.response.responseHeaders["pinscher-variable"]
def String[] pinSplit = pinTmp.split('\\[')
def String[] pinSplit2 = pinSplit[1].split('\\]')
def String pin = pinSplit2[0]

testRunner.testCase.testSteps["/verify"].setPropertyValue("pinscher-variable", pin)

Replace an element and send it

def String pinErrato = pin.replaceAll("J9fQ","X8hW")
testRunner.testCase.testSteps["/verify-wrong"].setPropertyValue("pinscher-variable", pinErrato)

Takes value of variables from Data Source (and DataSource Loop after Request)

import groovy.json.*
import java.lang.Object

def cvv = context.expand( '${DataSource#cvv}' )
def emailOwner = context.expand( '${DataSource#emailOwner}' )
def expirationDate = context.expand( '${DataSource#expirationDate}' )
def firstName = context.expand( '${DataSource#firstName}' )
def lastName = context.expand( '${DataSource#lastName}' )
def pan = context.expand( '${DataSource#pan}' )

slurperNewCreditCard.creditCardData.cvv = cvv
slurperNewCreditCard.creditCardData.emailOwner = emailOwner
slurperNewCreditCard.creditCardData.expirationDate = expirationDate.toLong()
slurperNewCreditCard.creditCardData.firstName = firstName
slurperNewCreditCard.creditCardData.lastName = lastName
slurperNewCreditCard.creditCardData.pan = pan

def jsonObject = JsonOutput.toJson(slurperNewCreditCard)
log.info(jsonObject)

def restRequest = testRunner.testCase.getTestStepByName("POST")
restRequest.setPropertyValue("Request", jsonObject)
testRunner.runTestStepByName("POST")

Function get time

def timestamp = new java.util.Date().getTime()

Replace function and conversion to BigDecimal

"price":priceDevice[i].replace(",",".").toBigDecimal()

Conversion to Integer

"quantity":quantityDevice[i].toInteger()

Create a map – A map is a collection of (key, value) pairs

def map = ["id":null, "products":slurperPinscherProducts]
def listPinscherProducts  = JsonOutput.toJson(map)

Forced Assert True and False

if ( buyerName_beforePatch != buyerName_afterPatch ) {
	log.info "Different values -> test OK."
	assert true
} else {
	log.info "Same values -> test KO."
	assert false
}

Conversions date to timestamp

def date = new Date()
lastUpdateBefore_value = date.parse('dd/MM/yyyy mm:ss', '04/10/2016 02:00')
log.info( "date read: ${lastUpdateBefore_value}" )
def lastUpdateBefore_valueTimestamp = lastUpdateBefore_value.time.toString()
log.info( "timestamp: ${lastUpdateBefore_valueTimestamp}" )

Checks values in Response

import groovy.json.JsonSlurper

def values = context.expand( '${Request the list of items of the catalogue#Response#$[\'values\']}' )
def slurperProducts = new JsonSlurper().parseText(products)
def Integer i
def String[] productTypeArray = ["",""]

Integer values_number = slurperValues.size()
log.info(values_number)

for(i=0; i<values_number; i++){
	def valueType = context.expand( '${Request the list of items of the catalogue#Response#$[\'values\']['+i+'][\'valueType\']}' )
	valueTypeArray[i] = valueType
	log.info(valueTypeArray[i])
	if(valueTypeArray[i]!="pinscher" && valueTypeArray[i]!="testing"){
		assert false
	}else{
		assert true
	}	
}

 

Pinscher Testing is on Tea-time with Testers

Tea-time with Testers, is the largest-circulated software testing monthly in the world. As the wave of change sweeps business, testing field and community of testers like never before, Tea-time with Testers has ensured that its readers have all the necessary upgrades to challenge tomorrow. It takes its readers deeper to give a complete understanding of the world of software testing.

Ever since its inception in 2011, it has set one benchmark after another in testing publication circle. It was the first to do serious reporting on software testing theories and thoughts. And then again, it is the first to bring a whole new genre of technical/corporate journalism more upclose and more incisive. It is the only monthly magazine in global testing community known for quality of its content, authors and unique way of presenting the information.Today, Tea-time with Testers commands the highest circulation and readership among all English language testing magazines in the world.

Tea-time with Testers Site
 

You can click on cover to download the PDF with my article, The Test Tower by Giuseppe Cilia.

PDF of last edition with my article

Happy testing with Tea-time with Testers, thank you very much!:)
 

SoapUI and Groovy Scripting (first part)

Groovy is an object-oriented programming language for the Java platform alternative to the Java language. Can be seen as the scripting language for the Java Platform, has characteristics similar to those of Python, Ruby, Perl, and Smalltalk.

Features:
Groovy uses a syntax similar to that of Java, based on braces, dynamically compiles bytecode for the Java Virtual Machine, and interacts seamlessly with other Java code and existing libraries. The Groovy compiler can be used to generate standard Java bytecode which can be used by any Java project. Groovy can also be used as a dynamic scripting language.

  • Dynamic Typing
  • Native syntax for lists, maps and regular expressions
  • Closures
  • Overloading operators

Another Groovy feature that is worth emphasizing is its native support for various markup languages like XML and HTML. This feature allows to define and manipulate many types of disparate data with a syntax and a methodology of uniform programming.

Standard Java (Java 5+):

for (String item : new String [] {"Pinscher", "Testing", "Blog"}) {
     if (item.length() <= 4) System.out.println(item);
}

Groovy:

["Pinscher", "Testing", "Blog"].findAll{it.size() <= 4}.each{println it}

 
Groovy Site
 

To test better services SoapUI we can use Groovy.
Between a request and the next we can insert a groovy script, renamed properly, it generates something between the two step or create an assert “more complex” than those provided by SoapUI.

Follow four rows generates a random string

import org.apache.commons.lang.RandomStringUtils
String charset = (('a'..'z')).join() //+ ('0'..'9')).join()
Integer length = 9
String randomStringName = RandomStringUtils.random(length, charset.toCharArray())

Print value of a variable on SoapUI console

log.info "randomStringName: ${randomStringName}"

Define of a json array

def body = '''[{
         "OrderId": "1",
         "buyerEmail": "pinschertesting@gmail.com",
         "buyerName": "'''+"${randomStringName}"+'''",
         "earliestDeliveryDate": null,
         "earliestShipDate": null,
         "isPremium": null,
         "isPrime": null,
         "lastUpdateDate": 1462113597000,
         "latestDeliveryDate": null,
         "latestShipDate": null,
         "numOfItemsShipped": null,
         "numberOfItemsUnshipped": null,
         "orderCurrency": null,
         "orderItems": [],
         "orderStatus": "A",
         "orderTotal": null,
         "purchaseDate": 1462113597000,
         "shipServiceLevel": null,
         "shipmentServiceLevelCategory": null,
         "shippingAddress": null
}]'''

Sends a json object to a request

def restRequest = testRunner.testCase.getTestStepByName("Request updates the list of orders")
restRequest.setPropertyValue('Request', body)

Defines a variable that contains a value takes from a specific xpath value of Response; after that, compares value stored in variables

def buyerName_beforePatch = context.expand( '${#[Order TestSuite#/orders TestCase#Request All Orders]#Response#$.orders[4].buyerName}' )
log.info "buyerName_beforePatch: ${buyerName_beforePatch}"

def buyerName_afterPatch = context.expand( '${#[Order TestSuite#/orders TestCase#Copy of Request All Orders]#Response#$.orders[4].buyerName}' )
log.info "buyerName_afterPatch: ${buyerName_afterPatch}"

if ( buyerName_beforePatch != buyerName_afterPatch ) {
	log.info "Different values -> OK."
} else {
	log.info "Same values -> KO."
	return false
}

Takes the value of a Response and saves in a variable; JSON slurper parses text or reader content into a data structure of lists and maps

import groovy.json.JsonSlurper
import org.apache.commons.lang.math.RandomUtils
import java.util.Random

def orders = context.expand( '${#[Order TestSuite#/orders TestCase#Request All Orders]#Response#$.orders}' )
def slurperOrders = new JsonSlurper().parseText(orders)
log.info "slurperOrders: ${slurperOrders}"

Generates a random number between a range values

Integer randomInteger = RandomUtils.nextInt(new Random(),slurperOrders.size())
log.info "randomInteger: ${randomInteger}"

def aOrderId = slurperOrders[randomInteger].aOrderId
log.info "aOrderId: ${aOrderId}"

Defines a json object

def context = '''{
   "context":    {
      "cartid": null,
      "flowid": null,
      "id": "defaultSessionContextId",
      "userid": "pinscherTesting"
   },
   "cartItems":[]
}'''

Settings of a global property value

testRunner.testCase.testSuite.setPropertyValue("cartId", cartID)

Defines and takes property value

def cartID = testStep.getPropertyValue("id")

Conversion text in Json

import groovy.json.JsonOutput
def conv = JsonOutput.toJson(jsonSlurperRequest)

 

Powered by WordPress & Theme by Anders Norén