Skip to content

Iptv Assist

Learn More from us

Menu
  • HOW TO
  • Firestick
  • Chromecast
  • PC Apps
  • Lg Smart TV
  • IPTV Services
  • Automation Testing
  • Smart TV
  • Software Testing Tools
  • Contact Us
Menu

Learn Advanced SoapUI Groovy Scripting Concepts – SoapUI Tutorial #9

Posted on March 19, 2023

Best Iptv Service Provider 2023 With 40k+ Channels And 100k+ VOD . 24/7 Suppport . Paypal Supported

The previous SoapUI tutorials have been an introduction into SoapUI and its programming concepts. We will from now on move into more advanced Groovy scripting concepts. Let us being this with Conditional flow statements – both Boolean and iterative statements. Then we will move on to arrays collection.

Best Iptv Service Provider 2023 With 40k+ Channels And 150k+ VOD . Hurry Up

This is the 9th tutorial in our SoapUI tutorial series.

Recommended IPTV Service Providers

  1. IPTVGREAT – Rating 4.8/5 ( 600+ Reviews )
  2. IPTVRESALE – Rating 5/5 ( 200+ Reviews )
  3. IPTVGANG – Rating 4.7/5 ( 1200+ Reviews )
  4. IPTVUNLOCK – Rating 5/5 ( 65 Reviews )
  5. IPTVFOLLOW -Rating 5/5 ( 48 Reviews )
  6. IPTVTOPS – Rating 5/5 ( 43 Reviews )

 

Conditional statements are used to control the flow of the execution. Here are different types of conditional statements in Groovy. 

SoapUI Groovy Scripting concepts

What You Will Learn:

  • #1. Control or logical statements:
  • #2. Looping or Iterative Statements:
  • #3. Arrays Collection:
  • Conclusion

#1. Control or logical statements:

These statements result in true or false based on the logical conditions. They are AND, OR and NOT. The symbols used are ‘&& (and)’, ‘|’| and ‘! (Exclamation)’ respectively. The behavior is as mentioned in the truth table:

“And” Operator truth table:

CONDITIONAL STATEMENTS IN GROOVY 1

“OR” operator truth table:

CONDITIONAL STATEMENTS IN GROOVY 2

“NOT” operator for negation purpose

Conditional statement: programming languages support the following conditional statements:

  • If…else statement
  • If…else if…else statement
  • Ternary operator
  • Switch statement

A) if…else block syntax: 

if <condition>
{
<Statements to be executed>
}
Else
{
<default statements>
}

In this syntax, when <condition> meets true the given statement will get executed. We need to enclose the statements by curly braces if the block contains more than one line. This instructs the entire block should execute based on the condition.

Look at the example code snippet.

int a=100
int b=200
if (a>b)
{
                log.info('B is greater than A');
                <To Do>
}
else
{
                log.info('A is greater or both are equal');
<To Do>
}

An if…else… statement should contain only one ELSE block.

B) Multiple conditional blocks: if…else if…else syntax

if <condition1>
{
                <Statements to be executed>
}
Else if <condition2….n>
{
                <Statements to be executed>
}
Else
{
                <default statements>
}

If…else if…else statement is little different than if…else… statement- in terms that it has else if block. This block is used for adding multiple conditions. Look at the following example.

int a=100
int b=200
int c=300
if (a>b && a>c)
{
                log.info('A is greater than B and C');
}
else if  (b>a && b>c)
{
                log.info('B is greater than A and C');
}
else
{
                log.info('C is greater than A and B or All are equal numbers');
}

And look at the output screenshot for the above script: Also, please use this as a reference for the boolen operator example too:

CONDITIONAL STATEMENTS IN GROOVY 3

C) Ternary operator:

This operator works similar to if…else statement. It has two operands such as question mark (TRUE) and colon for FALSE / default statements.

def A = 100
def B = (A > 100) ? “PASS” : “FAIL”
log.info(B)

Here’s the screenshot for the above script.

CONDITIONAL STATEMENTS IN GROOVY 4

D) Switch case: This statement allows multiple conditional branches with different values. Also it supports comparison of class object references, regular expressions, collections such as arrays, lists etc.

Switch <value>
{
case <match1>:
                <execute block>;
                break;
case <match1…match (n)>:
                <execute block>;
                break;

default:
<execute default block>;
}

The case statements compare the values with the switch case value. If it’s a match, then the corresponding case block gets executed. Once the block is executed then it should be stopped by the “break” keyword. If we missed “break” keyword at end of the case statement, execution will be moved to next case statement- and that might not be necessary.  In case none of the cases are true, default block will be executed. Please note that Groovy supports all the major operators and keywords as it is incorporated with the java libraries.

def country="India"
switch(country)
{
	case "Japan":
		log.info('Country matched with 1st case statement');
		break;
	case "Australia":
		log.info('Country matched with 2st case statement');
		break;
	case "India":
		log.info('Country matched with 3st case statement');
		break;
	default:
		log.info('None of the matches available :(');
}
Here’s the output screenshot for the above script.

CONDITIONAL STATEMENTS IN GROOVY 5

#2. Looping or Iterative Statements:

These enable repetition whenever we need and are especially useful for data driven testing.

For instance, let us assume we have a few zip codes in an excel file. To retrieve all the zip codes one by one from the excel file, and pass it to service i.e. GetSuppliersZipcode, we can use iterative statements. SoapUI also provides an alternative feature called data source and data source loop test steps.(Available only in SoapUI Pro trial and licensed versions.)

We can use these following iterative statements in the groovy script:

  • For loop
  • While loop

For loop: 

for (<initialization>; <condition>; <increment /decrement>)
{
                <Execute Statements>;
}

In the above syntax, initialization denotes starting point of the loop and based on the condition loop will continue or stop the execution.

See the below script

for(int i=1; i<=10; i++)
{
                log.info(‘Loop Iterated ‘ + i + ‘ times’);
}

Above script will produce the results as shown in the following screenshot.

CONDITIONAL STATEMENTS IN GROOVY 6

Now let us use control statement and iterative statement in our real testing world. Follow the below steps:

  • Add Testcase with your desired name. I have created as “T9_GetSupplierByZipCode_TestCase”.
  • Then add a property named “Property_Zipcode”
  • Add Test Request step for “GetSupplierByZipCode” service and put the property name in the request as shown in the screenshot.

CONDITIONAL STATEMENTS IN GROOVY 7

Add groovy script test step as shown in the following screenshot.

CONDITIONAL STATEMENTS IN GROOVY 8

In the groovy script editor, write the following script.

for (int zipCode=1; zipCode<10; zipCode++)
{
	testRunner.testCase.testSteps['Properties'].
setPropertyValue('Property_Zipcode', '3000' + zipCode )
	def testStep = testRunner.testCase.testSteps['GetSupplierByZipCode'];

	if (zipCode>5)
	{
		log.info('**************Stopped Execution*************');
		break;
	}
	testStep.run(testRunner,context);
	log.info('Executed ' + zipCode + ' times')
}

The following result is received in the log as well as in the service response screen.
(Click image for enlarged view)

CONDITIONAL STATEMENTS IN GROOVY 9

“while” loop: 

Syntax:

while <condition>
{
                <Execute Statements>;
}

The above logic can be implemented using the “while” loop too.

Hence, the gist is that iterative statement can be used to:

  1. Execute the test cases or test steps repeatedly
  2. Control the flow of the execution through the control statements.

#3. Arrays Collection:

Array collection helps store multiple values in a single variable or object. Array index starts at zero by default and we need to use that index with array name to access the corresponding value stored in the array. Syntax to declare arrays in groovy script:

arrayName = new Object[5] or,
arrayName = new Object[10][] or,
arrayName = new Object[10][10][]

Note: While declaring arrays we must specify the initial size otherwise it will throw a compile error. Here’s the simple example for the single dimensional array.

ArrayObj = new Object [5];
ArrayObj[0] = “Testcase1”;
ArrayObj[1] = “Testcase2”;
ArrayObj[2] = “Testcase3”;
ArrayObj[3] = “Testcase4”;
ArrayObj[4] = “Testcase5”;

Now let us implement this in our regular test steps. So add property, test request and script test step under the project test suite as shown in the following screenshot.

CONDITIONAL STATEMENTS IN GROOVY 10

And then double click on the script test step and write the following script.

def MAX_LIMIT = 5
def zipCodes = new Object[MAX_LIMIT]

zipCodes[0] = "92704"
zipCodes[1] = "99362"
zipCodes[2] = "31401"
zipCodes[3] = "90247"
zipCodes[4] = "87102"

int i=0;
while (i<5)
{
	if (i<5)
	{
		testRunner.testCase.testSteps['Properties'].
setPropertyValue('Property_Zipcode',zipCodes[i]);
		def testStep = testRunner.testCase.testSteps['GetSupplierByZipCode'];
		testStep.run(testRunner,context);
		log.info('Loop executed ' + i + ' times');
	}
	i++;
}
log.info("Testcase execution is completed....");
In this script, we initialized array object as 5 and assigned five zip codes in each array location respectively. Next part of the script is iterative block. Here we iterate the loop up to 5 times. Each time array value will be assigned to the property and then move to GetSupplierByZipCode web service to pass this array value in the request. After that, service step will be executed with the zip code. 

Finally we will get the following message in the log as shown in the screenshot.

CONDITIONAL STATEMENTS IN GROOVY 11

So arrays are very useful to handle multiple elements with different types. More practice will foster better understanding and ease of use.

Conclusion

That was an overall introduction with examples to conditional or logical blocks that include IF…ELSE, switch and ternary statements. These statements are controlled by the logical operators such as AND, OR, NOT. When compared to “switch” block “if” block is fast and simple. To handle multiple collections like arrays to iterate the testing process, loop statements are critical.

Next SoapUI tutorial #10: In next post we will learn “Object-Oriented Groovy Scripting in SoapUI”.

More useful concepts are coming up in the next SoapUI Groovy Script tutorials. Keep reading and please share your experiences and queries in the comments below.

Related

Best Iptv Service Provider 2023 With 40k+ Channels And 150k+ VOD . Hurry Up

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • IPTV List: Best iptv lista 2023
  • IPTV Premium: Best Premium IPTV Service Provider List And Benefits
  • Nikon IPTV Review: Over 10,000 Live Channels for $12/Month
  • Iptvwings. Com Review: +18000 Live IPTV Channels ,+70000 Movies, +40000 TV show For $15/1 month
  • IPTVUNO Review: More Than 16000 Live TV channels, 55,000 Movies & VOD For $15/Month

Recent Comments

  1. IPTV List: Play lista iptv 2022 - Iptv Assist on Best IPTV Player in 2023 for Watching Live TV
  2. Cola IPTV – Over 18,000 Live Channels for $12/Month - Iptv Assist on FileLinked – How to Install on Firestick/Fire TV and Android Devices
  3. Cola IPTV – Over 18,000 Live Channels for $12/Month - Iptv Assist on 50+ Best IPTV Service Providers for Streaming Live TV 2023
  4. XoomsTV IPTV – Over 11,000 Channels & VOD for Under $13/Month on Best VPN for IPTV in 2023 and How to Install on Firestick/Android
  5. Voodoo Streams IPTV Review – Over 12,000 Channels for $11/Month - Iptv Assist on Dynasty TV IPTV Review – Over 6,000 Channels for $10/Month

Archives

  • March 2023

Categories

  • Activate
  • Agile Testing
  • Alternatives
  • Android
  • APK
  • Apple TV
  • Automation Testing
  • Basics of Software Testing
  • Best Apps
  • Breakfast Hours
  • Bug Defect tracking
  • Career in Software Testing
  • Chromebook
  • Chromecast
  • Cross Platform
  • Database Testing
  • Delete Account
  • Discord
  • Error Code
  • Firestick
  • Gaming
  • General
  • Google TV
  • Hisense Smart TV
  • HOW TO
  • Interview Questions
  • iPhone
  • IPTV
  • IPTV Apps
  • Iptv Service SP
  • IPTV Services
  • JVC Smart TV
  • Kodi
  • Lg Smart TV
  • Manual Testing
  • MI TV
  • Mobile Testing
  • Mod APK
  • newestiptv.com
  • News
  • Nintendo Switch
  • Panasonic Smart TV
  • PC Apps
  • Performance Testing
  • Philips Smart TV
  • PS4
  • PS5
  • Python
  • QA Certifications
  • QA Leadership
  • QA Team Skills
  • Quality Assurance
  • Reddit
  • Reviews
  • Roku
  • Samsung Smart TV
  • Screenshot
  • Selenium Tutorials
  • Sharp Smart TV
  • Skyworth Smart TV
  • Smart TV
  • Soft Skills For Testers
  • Software Testing Templates
  • Software Testing Tools
  • Software Testing Training
  • Sony Smart TV
  • Sports
  • Streaming Apps
  • Streaming Devices
  • Tech News
  • Test Management Tools
  • Test Strategy
  • Testing Best Practices
  • Testing Concepts
  • Testing Methodologies
  • Testing News
  • Testing Skill Improvement
  • Testing Tips and Resources
  • Toshiba Smart TV
  • Tutorials
  • Twitch
  • Types of Testing
  • Uncategorized
  • Vizio Smart TV
  • VPN
  • Web Testing
  • What is
  • Xbox
©2023 Iptv Assist | Design: Newspaperly WordPress Theme