Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Katalon Script in Selenium Java?

As we know Katalon has now become a paid tool so my Katalon scripts need to be converted into Selenium and Java script. Katalon scripts are in Groovy, and it's written using Katalon Built-in libraries, objects are saved in .rs(.xml) fie on Object repository and user-defined Keywords are also in Groovy. So please suggest the best way(time-saving) to convert scripts into selenium.

like image 593
Ajeet Yadawa Avatar asked Aug 22 '26 07:08

Ajeet Yadawa


2 Answers

I don't think there is a simple way to convert all of your scripts to Selenium.

Katalon keywords are a wrapper around various Selenium commands (or code snippets) so a one-to-one Katalon-Selenium relationship is not always present. Therefore, one simple way of translating one to another does not exist.

like image 53
Mate Mrše Avatar answered Aug 24 '26 20:08

Mate Mrše


Finally, able to convert Katalon script into Selenium. Refer below to make your own Katalon Studio:

Step 1. Create an interface and store Global variable

public interface RunnerConstants {
readByExcel rd=  new readByExcel("Login.xls","LoginData");
public static final String url= rd.getexcelCellData(2, 0);
public static final  String userName= rd.getexcelCellData(2, 1);
public static final  String password = rd.getexcelCellData(2, 2);
public static final  String subscriberid = rd.getexcelCellData(2, 3);
public static final  String browserName = "Chrome-Headless";

}

Step 2: Make an element class and store WebElement( use page Factory concept)

public class takeElement {

static WebDriver driver= webD.getInstance();

@FindBy
public static WebElement inputLogin = 
 driver.findElement(By.xpath("//input[@id='loginID']"));
@FindBy
public static WebElement inputSubscriberId  = 
driver.findElement(By.xpath("//input[@id='subscriberID']"));


@FindBy
public static WebElement submitbtn= 
driver.findElement(By.xpath("//input[@id='submitLogin']"));
}

Step 3: Create a web driver singleton class How to get webdriver instance to use same instance across all class files

Step 4: Implement Katalon methods as static in WebUI class.

 public  class  WebUI {

 static WebDriver driver = webD.getInstance();
 public static void setDriver(WebDriver driver) {
    WebUI.driver = driver;
 }  
 public static void openBrowser(String url) {
    driver.get(url);
 }
public static void navigateToUrl(String url) {
    driver.navigate().to(url);
}
}

Step 5: Write your script using TestNG annotations

 public class test {


 @Test
 public void testA() {
 WebUI.openBrowser(RunnerConstants.url);
  WebUI.setText(takeElement.inputLogin, RunnerConstants.userName);
 WebUI.setText(takeElement.inputPassword, RunnerConstants.password);
 WebUI.setText(takeElement.inputSubscriberId, RunnerConstants.subscriberid);
 WebUI.click(takeElement.submitbtn);
 WebUI.closeBrowser();
  }
}

Using the above ways, you can reuse your Katalon script. I hope it helps!!

like image 45
Ajeet Yadawa Avatar answered Aug 24 '26 22:08

Ajeet Yadawa