Control Statements in katalon studio || loops and if else.

Control statements in katalon studio or decision making statements in katalon studio. Katalon studio providing very handy way to use statements like if, else, switch, loops etc. Control statements is very common if you have basic programming knowledge. Here I am not going to explain to you what is Control statements statement. We will focus on how to use Control statements in katalon studio.

Control statement in katalon studio. 

  • Decision-making statements
  • Looping statements
  • Branching statements
  • Exception handling block

Decision-making statements in katalon studio.

 Katalon studio provides manual and script both way to write your test cases. You can use manual way but if you have some basic knowledge about programming script will be easy for you.

For manual mode:

 

If else statement in katalon studio                                                

If(Condition){

//write your statements…………

}else{

//write your statements…………



}

Operators used in an IF statement are as follows:

== equal

!= different (or not equal)

< less than

<= less than or equal

> greater than

>= greater than or equal

Switch statement in katalon studio

 

switch(varA){

case 1:

//statement..............

break;



case 2:

//statement..............

break;



case 3:

//statement..............

break;

default:

//statement..............

break;



}

Complete script using if, else and switch in katalon studio.

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint

import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase

import static com.kms.katalon.core.testdata.TestDataFactory.findTestData

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint

import com.kms.katalon.core.checkpoint.CheckpointFactory as CheckpointFactory

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as MobileBuiltInKeywords

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

import com.kms.katalon.core.model.FailureHandling as FailureHandling

import com.kms.katalon.core.testcase.TestCase as TestCase

import com.kms.katalon.core.testcase.TestCaseFactory as TestCaseFactory

import com.kms.katalon.core.testdata.TestData as TestData

import com.kms.katalon.core.testdata.TestDataFactory as TestDataFactory

import com.kms.katalon.core.testobject.ObjectRepository as ObjectRepository

import com.kms.katalon.core.testobject.TestObject as TestObject

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSBuiltInKeywords

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUiBuiltInKeywords

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import internal.GlobalVariable as GlobalVariable

import org.openqa.selenium.Keys as Keys



String realTittle = "CURA Healthcare Service"



// actual page tittle.....



WebUI.openBrowser('')



WebUI.navigateToUrl('http://demoaut.katalon.com/')



WebUI.click(findTestObject('Page_CURA Healthcare Service/a_Make Appointment'))



String pageTittle = WebUI.getWindowTitle()

// page tittle geting at run time...



// Use if else...............

if(pageTittle.equalsIgnoreCase(realTittle))

{

WebUI.setText(findTestObject('Page_CURA Healthcare Service/input_username'), 'John Doe')



WebUI.setText(findTestObject('Page_CURA Healthcare Service/input_password'), 'ThisIsNotAPassword')



WebUI.click(findTestObject('Page_CURA Healthcare Service/button_Login'))

}else{

  System.out.println("Page tittle is not matched")

}

int a = 2;

switch(a){

     case 1:

     System.out.println("Case 1 will execute")

     break

    

     case 2:

     System.out.println("Case 2 will execute")

     break

    

     default:

     System.out.println("Default Case will execute")

     break

}

WebUI.closeBrowser()

Looping statements in katalon studio

 

For loop:

 for (statement 1; statement 2; statement 3) {

    code block to be executed

}

Statement 1 is executed before the loop (the code block) starts.

Statement 2 defines the condition for running the loop (the code block).

Statement 3 is executed each time after the loop (the code block) has been executed.

While loop: 

while (condition) {

    code block to be executed

}

Complete script using for loop in katalon studio.

WebUI.openBrowser('')



for(int i=0;i<3;i++){

    

//same testcase will execute three time.

          

WebUI.navigateToUrl('http://demoaut.katalon.com/')



WebUI.click(findTestObject('Page_CURA Healthcare Service/a_Make Appointment'))



WebUI.setText(findTestObject('Page_CURA Healthcare Service/input_username'), 'John Doe')



WebUI.setText(findTestObject('Page_CURA Healthcare Service/input_password'), 'ThisIsNotAPassword')



WebUI.click(findTestObject('Page_CURA Healthcare Service/button_Login'))



}



WebUI.closeBrowser()

 

Add a Comment

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

5 × 1 =