SoapUI
tool is developed by Smartbear and is used to test web services.
· Can do Functional,
Load & Performance testings
· SoapUI
tool automatically generates SOAP message after interpreting WSDL file.
Below are the different properties of asserting in SOAPUI
ASSERTION: Is nothing but check points.
We add assertions
for each step of the Test Case by clicking Add Assertion button
XPATH MATCH: Uses
XPATH expression to select target nodes & its values. XPATH is an XML query
language for selecting nodes from an XML document.
Under XPATH window we have to declare namespace which is done by
clicking Declare button, below is
the namespace which will be automatically added
declare namespace
soap='http://schemas.xmlsoap.org/soap/envelope/';
declare namespace ns1='http://tempuri.org/';
1st Namespace is schema URL and
2nd corresponds to actual Web
Service URL
Below these namespace, we need to add our
XPATH which we are validating.
It
has count()
exists()
match(xpath/text(), tr)
content – xpath/text()
XQUERY ASSERTION:
It helps us to validate group of XML
response which are repetitive in nature.
By XPATH we can only validate one occurrence
of XML element but by using XQUERY we can validate group of XML responses.
CONTAINS:
searches for the existence of the specified string. It supports regular
expression
NOT CONTAINS:
NOT
CONTAINS:Searches for non-existence of the specified string. It also supports
regular expression
PROPERTIES:
Are
nothing but variable declaration at different levels (Project level, TestSuite
level, TestCase level). These properties can be defined under custom properties
tab.
Project
Level properties can be accessible to all the test suites & test cases
which is nothing but global availability.
TestSuite
Level properties are available to all the test cases which are defined under
that test suite.
TestCase
Level properties are available to only that particular test case.
Syntax:
{#level#propertyName}
Eg: {#project#fromCurrency}
Sample
NameSpace declaration inside assertion
declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/';
declare namespace ns1='http://tempuri.org/';
//ns1:AddResponse/ns1:AddResult
Property Transfer are used to transfer properties from testStep
and their containing testCase, testSuite & project.
Conditional GoTo is used when we want to move to next step only
when condition passes, otherwise fail it.
Groovy
Scripting:
Groovy
scripting is a dynamic language for Java Virtual Machine
Groovy
scripting is also known as loosely coupled language.
We
can write groovy script under SoapUI Project à TestSuite à
TestCase à Add
Test Step à
Groovy Script à
To
comment we use double slash “//”
To
print output to console log.info “your
message to print to console”
To
declare variable def Name = “Kareem”
Note:
here def indicates any data type, Name indicates variable and its value
inside “”
We
can print variable while printing ur message as follows
Log.info
“your name is:” + Name
(Or)
Log.info
“your name is$ Name”
Loops
in Groovy
If(Name==
”kareem”){
Log.info
“he is good boy”
}
Else
{
Log.info
“he is bad boy”
}
Assert
Command
Assert
command will check if the condition is true or not, if true it proceeds further
step execution, if false it halts/terminates the execution
Syntax : assert
variableName == “khan”
For
Loop
We
can also use def in place of int
for(def
i=0; i<=0;i++){
log.info
i
}
While
Loop
def
j=1
while(j<=5){
log.info
j
j++
}
Arrays
def
abc = new string[5]
abc[0]=”a”
abc[1]=”b”
abc[2]=”c”
abc[3]=”d”
abc[4]=”e”
for(def
a=0; a<5;a++){
log.info
abc[a];
}
We
can get size of an array as abc.size()
We
can also declare & initialize array as follows
def
terms = [“first0”, “first1”, “first2”, “first3”, “first4”, “first5”]
Exceptions
Which
is nothing but abnormal condition which will occur during normal execution?
Have
try/catch block
Try{
//
add statements which will produce abnormal condition
}
Catch(Exception
e){
//
printstackTrace of exception logs
}
Data Structures
ArrayList --Index
starts from 0
ArrayList
ar = new ArrayList();
ar.add(“a”);
//to add values to ArrayList
ar.get(0);
// to retrieve values from ArrayList
ar.size()//to
get size of ArrayList
HashTable
Is a
key-value pair
HashTable
ht = new HashTable();
ht.put(“Name”,”kareem”);
ht.put(“age”,”27”);
ht.get(“age”);
HashMap
Is a
key-value pair
def names
= [“Name” : “kareem”, “age”:”27”];
log.info
names[“Name”] // key should be passed as argument for hashMap
List
Index
starts from 0
def
course = [ 1,2,3,”abcString”, 90, “secondString”]
log.info
course[3] // will print abcString as output.
When
we launch Groovy Script window, we have context
& testRunner variable
Scope
of context Variable lies in the test
case level only.
Context.setProperty(“VariableToStore”,”valueAssignedToVariable”);//to
set/add property
Context.getProperty(“VariableName”);//to
get property by passing variableName
We
can also get custom property values into Groovy Script by using the expand() method as
By
using expand() we can get request/response
Log.info
Context.expand(‘${#TestCase#Age}’)
#TestCase#Age
à 1st
need to specify level from where you are getting value, 2nd is
attribute from which value is read
This
Context variable can be used within the TestCase, but not outside the TestCase.
Either
it can be request or response.
Eg:
log.info
context.expand('${GetSupplierByCity#response}')
GetSupplierByCity
– is response output
Response
is what we want to print as ouput.
If
you want to get only the tagName value from entire response, then we can get as
follows.
To do
so, we have to import the xml package and then do the operations
import com.eviware.soapui.support.XmlHolder
def response =
context.expand('${Add#response}')
log.info response
def xml = new XmlHolder(response)
def desiredValue =
xml.getNodeValue("//AddResult")
log.info desiredValue
To
set value for any node then we have method inside XmlHolder as follows
Xml.setNodeValue(“//NodeName”,”valueToSet”);
TestRunner scope is in the
entire project.
Either
we can set/get the property values throughout the Project (May be under
different TestSuites/TestCases). This operation we cannot do using Context
variable.
If we
have global property defined under TestSuite level we can get that under any
test case step by using TestRunner as follows under Groovy Script
PreCondition:
Create a global property under test suite level “place:Bangalore”
To
access the global property under test case step
testRunner.testCase.testSuite.getPropertyValue(“place”)
Above
command displays “Bangalore” as value which is assigned to place property
Have
to import package
import
com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext
def
desiredTestStep =
testRunner.testCase.testSteps(“DeleteEmployee”).setPropertyValue(“Request”,
dxml)
desiredStep.run(testRunner,
context) // if you want to run the above step we have to use run() method
1st
arg – is testRunner
2nd
arg- is context
Accessing
other property values which are located in different testSuite level
myProject=testRunner.testCase.testSuite.project
myProject.testSuites[“Test
Suite 2”].testCases[“Test Case 1”].testSteps[“AddEmployee”]
OR
testRunner.testCase.testSuite.project.
testSuites[“Test Suite 2”].testCases[“Test Case 1”].testSteps[“AddEmployee”]
If you have to choose one among the multiple
testSuites or testCases then we have to select as above within square brackets.
myProject=testRunner.testCase.testSuite.project
desiredTestStep=
myProject.testSuites[“Test Suite 2”].testCases[“Test Case
1”].testSteps[“AddEmployee”]
desiredContext=new
WsdlTestRunContext(desiredTestStep)
desiredTestStep.run(testRunner,
desiredContext)
Assignment:
Execute
the Add employee from other test suite and take the same name from request xml
Pass
it into get employee details and run the request.
From
the response Get employee details take again the name and pass it into delete
employee request and run it
SOAPUI PRO Options:
1.
To read data/properties from any external
sources (excel or xml) pro version has test step called DataSource &
DataSourceLoop
DataSource is linked to DataSourceLoop.
For ex: if you want to add employees which are
declared inside any external file into database, then we can make use of single
script (business logic) and DataSourceLoop so that one by one employee will be
added into db taking values from DataSource.
Here DataSourceLoop is nothing but looping operation
of DataSource properties
DataSource can be of any one of the following
i.
Grid
ii.
Excel (Should save excel in .xls format, not
in .xlsx format as it wont support)
iii.
JDBC
iv.
XML
v.
Groovy
vi.
File
vii.
Directory
1. Grid – first Add properties like Name, Age,
Dept, ID, Verification by clicking + icon, then provide values in right pane as
in screenshot. Then click on Execute button
File
– first add all properties, then provide values in excel sheet and save it with
.xls format as SaopUI supports only this format.
Select
DataSource as Excel à
provide excel source à
worksheetName & starting Cell
Then click on Execute button
2. Data Sink
If you want to update external file with
response results, then we have to go for DataSink.
To write back value of the response into
Output property, we have to create Property Transfer request from request as
follows
Now export result to external excel file as
follows
Same scenario using notepad files as follows
3. Conditional Go to
Is nothing but a condition or if else loop,
If particular property/element is present,
then only execute Target Step, if not terminate the execution
4. Delay
To sleep for so many particular of milli
seconds before executing further step.
5. DataGen
If you want to generate/pick random numbers then
go for this Data Generator.
Data
Gen using “Number” type – you can use this for random number generation
Data Gen using “Template” type – you can use
this for concatenation
This is not much useful
6. TestCase
Debugging – to debug test cases by having breakpoints as in screenshot
Asterisk
here indicates change in the value when compares with previous run.
7. Test Case Coverage – will tell you how much
coverage are we covering in out testScripts from WSDL file
To get coverage, we have to Enable Coverage
and run
8. Test On Demand – by using this we can run our
webService from different global location with condition that no files are kept
locally. Result of script which ran in Chicago Illinois environment is as below
Happie Learning...!!!