Code Monkey home page Code Monkey logo

api-test-automation-with-soapui's Introduction

SoapUI

See LinkedIn course API Test Automation with SoapUI

First project

https://api.carbonintensity.org.uk/

SoapUI can do Groovy scripting. To get today’s date into some fields that require a date:

${=def now = new Date();now.format("yyyy-MM-dd")}

${= new Date().format("yyyy-MM-dd")}

${= new Date().plus(365).format("yyyy-MM-dd")}

To extract value for deck_id from JSON

{
   "shuffled": true,
   "remaining": 52,
   "success": true,
   "deck_id": "qdsfmvpz4hau"
}

${<TestStepName>#Response#$deck_id>}

To extract value for code from JSON

{
   "remaining": 51,
   "cards": [   {
      "image": "https://deckofcardsapi.com/static/img/JS.png",
      "images":       {
         "svg": "https://deckofcardsapi.com/static/img/JS.svg",
         "png": "https://deckofcardsapi.com/static/img/JS.png"
      },
      "value": "JACK",
      "suit": "SPADES",
      "code": "JS"
   }],
   "success": true,
   "deck_id": "i2uawfwsc6kk"
}

${<TestStepName>#Response#$cards[0].code}

To read data from csv file

def inputFilePath = testRunner.testCase.testSuite.getPropertyValue('inputFile')
File file = new File(inputFilePath.toString()).eachLine{
	 testRunner.testCase.testSuite.setPropertyValue('inArea', it.split(",")[0])
	 testRunner.testCase.testSuite.setPropertyValue('inLocation', it.split(",")[1])
	 
	 def testCase = testRunner.testCase.testSuite.testCases['TestCase 1']
	 def runner = testCase.run(null, false)

}

Test suite setup and teardown

Add to 'Setup Script' of the 'TestStep'

def inputFilePath = testRunner.testCase.testSuite.getPropertyValue('inputFile')

def myFile = new File(inputFilePath)

def lines = myFile.readLines()
context.mylines = lines
assert lines.size() == 4

Change script of reading file to:

context.mylines.each{
	testRunner.testCase.testSuite.setPropertyValue('inArea', it.split(",")[0])
     testRunner.testCase.testSuite.setPropertyValue('inLocation', it.split(",")[1])
     def testCase = testRunner.testCase.testSuite.testCases['TestCase 1']
     def runner = testCase.run(null, false)
     sleep 500
}

Script Assertions

def response_message = messageExchange.responseContent
def response_json = new groovy.json.JsonSlurper().parseText(response_message)

if (1 <= response_json.day_of_year & response_json.day_of_year < 366) {
	assert true	
} else {
	log.info("wrong day of year: ${response_json.day_of_year}")
	assert false
}

Global properties

inputFile from the examples above can be used only in the test case where it was defined. To define it somewhere more global SoapUI lets us do that with Global Properties. Go to File -> Preferences -> Global Properties.

def inputFilePath = context.expand('${#Global#inputFile}')

#Global# - global variables #Env# - environment variables

MacOS: run test cases from command line

$ cd /Applications/SoapUI-5.5.0.app/Contents/java/app/bin/.

$ sudo ./testrunner.sh <path_to_project_xml> -r

$ sudo ./testrunner.sh <path_to_project_xml> -r -f <path_to_file_report_to_save> -a

where r - to generate report, -f store it to the file, -a - store all results, by default it stores results only for failed cases

Run test cases inside docker container

$ service docker status

$ docker run --name soaprunner -d -p 3000:3000 ddavison/soapui

$ curl --form "project=@downloads/deckofcardsapi-soapui-project.xml" --form "suite=TestSuite 1 - deck" --form "option=-r" http://192.168.1.85:3000/

After container was started go to http://192.168.1.85:3000/, where 192.168.1.85 is a server where my container was started

Useful links

api-test-automation-with-soapui's People

Contributors

kotavi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.