Groovy is a superset of
Java which means
Java program will run in
Groovy environment but vice-versa may or may not be possible. Whereas
Java is strongly and statically typed programming language.
Difference between Groovy and Java.
| Java | Groovy |
|---|
| It is used as programming and object oriented Language | It is used as both programming and scripting Language |
How to Write a Basic Groovy Script
- Open your text editor and create the Groovy script: // Basic Groovy Script Console console=System. console(); def name=console.
- Save your file as BasicScript. groovy .
- Open a command prompt and navigate to the directory containing your new Groovy program. Then type in the command to interpret and run your script:
Groovy can be used as a scripting language for the Java platform. It is almost like a super version of Java which offers Java's enterprise capabilities. It also offers many productivity features like DSL support, closures, and dynamic typing.
context - a TestCaseRunContext object holding context-related properties. The main usage for this is to store values that can be used in subsequent TestSteps or related scripts. For example. context.myProperty = "Hello" will create a property named "myProperty" in the context and assign it the string value "Hello".
Below are the three steps to quickly set up a test and integrate it with automation frameworks.
- Step 1: Create an API Test through the intuitive 'New Test' item in the SoapUI menu or on the dashboard.
- Step 2: Once you have created the API test, run it to ensure that the test is configured correctly.
For each API request, the test would need to take the following actions:
- Verify correct HTTP status code.
- Verify response payload.
- Verify response headers.
- Verify correct application state.
- Verify basic performance sanity.
Assertions allow you to specify expected data in the response to a request made in a test run. Assertions can be made against response header values, status code, response time/size, and content (like JSON or XML).
This section provides information on various assertion types available in ReadyAPI.
- Property Content Assertions. Property Content assertions validate XML, XPath, XQuery, and JSON content of a message.
- Compliance Assertions.
- Script Assertion.
- Response SLA Assertion.
- JMS Assertions.
- JDBC Assertions.
- Security Assertions.
Assertion means act of affirming or stating something. It can also be interpreted as check point or a validation point. Once a request is sent to a web server a response is received. We need to validate if the response contains the data that we expect. In order to validate the response, we need to use assertions.
XPath is an XML query language for selecting nodes from an XML. Step 1 − After clicking Add Assertion, select Assertion Category – Property Content. Step 2 − Then, select Assertion Type – XPath Match and click Add. XPath Match Configuration wizard opens.
35. An assertion is similar to an if, it verifies the expression you provide: if the expression is true it continues the execution to the next statement (and prints nothing), if the expression is false, it raises an AssertionError.
Assertions are validation rules applied to test results that check how your target web service performs. In SoapUI tests, you use assertions to verify response codes, response headers, individual values in response bodies, request execution time and to do other checks.
For SOAP Request TestSteps the following assertions are available (see Validating SOAP Messages for more details): Schema Compliance - validates the response message against the definition in the WSDL and contained XML Schema. SOAP Response - checks that the response is a valid SOAP Response.
assert() macro is used to test the conditions or assumptions that should not occur in a program. For example, the array index should always be > 0. Another assumption can be 2+2 == 3+1. So using assert () we can test such assumptions and as long as they evaluate to true, our program runs normally.
When you have an URL that contains parameters, SoapUI can extract them as you create the TestStep.
- Enter the URL into the URL field.
- Click Extract Parameters.
If we want to parse and get the tag values in the request and response XML, we can with the help of a class called XmlHolder. This is a class in the Groovy API which is used to parse the request and response XML.
Groovy Script test steps run as part of the functional test. Setup and TearDown
scripts run when you start or stop the related test item.
Common scripting tasks
- Create Groovy Script test steps to add various enhancements to a functional test case.
- Create script assertions for REST, GraphQL, or SOAP responses.
testRunner - a TestCaseRunner object (javadoc), which is the entry-point to the SoapUI API for accessing project items, results, etc. The TestRunner is the object that is actually executing the TestCase by cycling through the TestSteps in the TestCase and executing them.
Groovy Script test step is included for custom automation test script creation in SoapUI / Pro. It can be used for functional/ load/regression. Groovy is a scripting language which internally includes all the Java libraries, therefore all java related keywords and functions can be used in the groovy script directly.
Test suite properties appear when click on the respective test suite name under the project. To add custom properties as needed, click on custom properties tab and click on the '+' sign under it. Test case properties are accessible within the test case.
testRunner – Provides a scripting interface to the test runner object that is executing the current test case and test step. It exposes methods related to test execution and the underlying object model (via the testCase property). See the common usage scenarios below.
To get a value of a property in a groovy script, use the following syntax: def foo = context.expand( 'Property expansion' ) For example, the following code snippet assigns the value of the Username test case property to the foo variable: def foo = context.expand( '${#TestCase#Username}' )
1 Answer
- provide directory location as input to this step.
- read a file as text.
- set text as request for soap request step.
- run the soap request step.
- read the response and save the result.
- repeat till the file list lasts and exist (do not allow to the soap step one more time)