# Introduction to Groovy Scripting in SoapUI
## Overview
**SoapUI** is a tool for web service testing. With SoapUI you are able to mock, inspect and develop code. **Groovy** is a programming language which is compatible with Java syntax. A perfect pair?
### Prerequisites
Installed SoapUI
I created a simple project which you can see below (you can use a wsdl example from the Internet)
Test suite is generated and Groovy Script added
# Hello Jlabs
Traditional Hello World. In Groovy Script window line add:
```java
log.info "Hello Jlabs"
```
Press Play button and say hello:

## Properties
By Groovy you can get and set properties for objects. We can use two methods `getPropertyValue` and `setPropertyValue`. Below you can find a few examples:
Get a test case property:
```java
def testCaseProperty = testRunner.testCase.getPropertyValue("PropertyName")
```
Get a test suite property:
```java
def testSuiteProperty = testRunner.testCase.testSuite.getPropertyValue( "PropertyName" )
```
Get a project property:
```java
def projectProperty = testRunner.testCase.testSuite.project.getPropertyValue( "PropertyName" )
```
Set a test case property:
```java
def projectProperty = testRunner.testCase.setPropertyValue( "PropertyName", Value )
```
Set a test suite property:
```java
testRunner.testCase.testSuite.setPropertyValue( "PropertyName", Value )
```
Set a project property:
```java
testRunner.testCase.testSuite.project.setPropertyValue( "PropertyName", Value )
```
## Check system username
Now something cooler than a simple hello. We will check the system's username:
```java
def name = context.expand('${#System#user.home}')
log.info ("System user name is: " + name);
```
I`m Marcin, and you?

## Groovy and Java together?
**Yes,** In Groovy you can add java packages.
Let's try to divide something:
```java
import java.io.*;
int x = 49 ;
int y = 7 ;
int z = x/y ;
log.info ("Result: "+z) ;
```
## Assertions in Groovy
Positive Assert:
```java
def name = "Marcin"
assert name == "Marcin"
```
Negative Assert:
```java
def name = "Marcin"
assert name == "Maciek"
```
When an error occurs:

You can define your own message for a negative assertion:
```java
def name = "Marcin"
assert name == "Maciek":"Maciek and Marcin are not the same person"
```
and another error occurs:

# Summary
**Groovy** is a scripting language that includes Java libraries.
Groovy increases the possibilities for functional, load and regression testing in SoapUI. You can maintain SOAP and REST tests better and easier. You can generate reports and run SoapUI tests on Jenkins.
## Summary
[http://groovy-lang.org/](http://groovy-lang.org/)
[https://www.soapui.org/](https://www.soapui.org/)
Marcin Łącki
Did you like this article?
0,0 / 0