As you perform testing with Katalon Studio, you can write or edit test automation scripts in the Script mode using Groovy programming language. This tutorial will help you run your Groovy script in Katalon with LambdaTest Selenium Grid.
Step 1: Open your Katalon Studio instance & go to Test explorer from the left side-bar.
Step 2: Right click on Test Listener folder & click on new listener.
Step 3: Name the new listener & paste the below code in the new listener.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
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.model.FailureHandling as FailureHandling import com.kms.katalon.core.testcase.TestCase as TestCase import com.kms.katalon.core.testdata.TestData as TestData import com.kms.katalon.core.testobject.TestObject as TestObject import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile import com.kms.katalon.core.annotation.BeforeTestCase import com.kms.katalon.core.annotation.BeforeTestSuite import com.kms.katalon.core.annotation.TearDown import com.kms.katalon.core.annotation.AfterTestCase import com.kms.katalon.core.annotation.AfterTestSuite import com.kms.katalon.core.context.TestCaseContext import com.kms.katalon.core.context.TestSuiteContext import com.kms.katalon.core.webui.driver.ExistingRemoteWebDriver import com.kms.katalon.core.configuration.RunConfiguration class LambdaListener { TestSuiteContext suiteContext; /** * Executes before every test case starts. * @param testCaseContext related information of the executed test case. */ @BeforeTestCase def sampleBeforeTestCase(TestCaseContext testCaseContext) { //To set the test name at LambdaTest. RunConfiguration.setDriverPreferencesProperty("Remote", "name", testCaseContext.getTestCaseId()); if (suiteContext != null){ RunConfiguration.setDriverPreferencesProperty("Remote","build", suiteContext.getTestSuiteId()); } println testCaseContext.getTestCaseId(); println RunConfiguration.getDriverPreferencesProperties(); } /** * Executes after every test case ends. * @param testCaseContext related information of the executed test case. */ @com.kms.katalon.core.annotation.TearDown @AfterTestCase def sampleAfterTestCase(TestCaseContext testCaseContext) { //To set the status of test at LambdaTest. String result="failed"; if(testCaseContext.getTestCaseStatus().equalsIgnoreCase("PASSED")){ result="passed" } try{ WebUI.executeJavaScript("lambda-status="+result,null) }catch (Exception e) { println e.toString() } finally { WebUI.closeBrowser() } println testCaseContext.getTestCaseId() println testCaseContext.getTestCaseStatus() } /** * Executes before every test suite starts. * @param testSuiteContext: related information of the executed test suite. */ @BeforeTestSuite def sampleBeforeTestSuite(TestSuiteContext testSuiteContext) { suiteContext=testSuiteContext //To Set the build Name at LambdaTest. RunConfiguration.setDriverPreferencesProperty("Remote","build", suiteContext.getTestSuiteId()); println testSuiteContext.getTestSuiteId() } /** * Executes after every test suite ends. * @param testSuiteContext: related information of the executed test suite. */ @AfterTestSuite def sampleAfterTestSuite(TestSuiteContext testSuiteContext) { println testSuiteContext.getTestSuiteId() } } |
That is all. Now, you can effortlessly run Groovy Scripts in Katalon for triggering your tests over LambdaTest cloud based cross browser testing platform. Happy testing! 🙂