This sample test case logs into ‘CURA Healthcare Service’ using Katalon compatible TestObjects created in memory. Copy and paste into any Katalon Studio test case and execute.
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
WebUI.openBrowser('http://demoaut.katalon.com/')
WebDriver driver = DriverFactory.getWebDriver()
def MakeAppointmentXpath = '//*[@id="btn-make-appointment"]'
TestObject MakeAppointment = WebUI.convertWebElementToTestObject(driver.findElement(By.xpath(MakeAppointmentXpath)))
WebUI.click(MakeAppointment)
WebUI.waitForJQueryLoad(20)
def UserNameXpath = '//*[@id="txt-username"]'
TestObject UserName = WebUI.convertWebElementToTestObject(driver.findElement(By.xpath(UserNameXpath)))
WebUI.setText(UserName, 'John Doe')
WebUI.waitForJQueryLoad(20)
def PasswordxPath = '//*[@id="txt-password"]'
TestObject Password = WebUI.convertWebElementToTestObject(driver.findElement(By.xpath(PasswordxPath)))
WebUI.setText(Password, 'ThisIsNotAPassword')
WebUI.waitForJQueryLoad(20)
def LoginxPath = '//*[@id="btn-login"]'
TestObject Login = WebUI.convertWebElementToTestObject(driver.findElement(By.xpath(LoginxPath)))
WebUI.click(Login)
WebUI.waitForJQueryLoad(20)
//Uses by.xpath
def CommentFieldxPath = '//*[@id="txt_comment"]'
TestObject CommentField = WebUI.convertWebElementToTestObject(driver.findElement(By.xpath(CommentFieldxPath)))
WebUI.setText(CommentField, 'Xpath Comment')
WebUI.waitForJQueryLoad(20)
//Uses by.cssSelector
def CommentFieldCss = '#txt_comment'
TestObject CommentField2 = WebUI.convertWebElementToTestObject(driver.findElement(By.cssSelector(CommentFieldCss)))
WebUI.setText(CommentField2, 'CSS Comment')
WebUI.waitForJQueryLoad(20)
//Uses by.id
def CommentFieldId = 'txt_comment'
TestObject CommentField3 = WebUI.convertWebElementToTestObject(driver.findElement(By.id(CommentFieldId)))
WebUI.setText(CommentField3, 'ID Comment')
WebUI.waitForJQueryLoad(20)