如何在Selenium Java中转换Katalon脚本? [英] How to convert Katalon Script in Selenium Java?

查看:51
本文介绍了如何在Selenium Java中转换Katalon脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道Katalon现在已经成为一种付费工具,因此我的Katalon脚本需要转换为Selenium和Java脚本.Katalon脚本位于Groovy中,并且是使用Katalon内置库编写的,对象保存在对象存储库中的.rs(.xml)fie中,而用户定义的关键字也位于Groovy中.因此,请提出将脚本转换为硒的最佳方法(节省时间).

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.

推荐答案

最后,能够将Katalon脚本转换为Selenium.请参考下面的内容,制作自己的Katalon Studio:

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

第1步.创建一个接口并存储全局变量

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";

}

第2步:创建一个元素类并存储WebElement(使用页面Factory概念)

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']"));
}

第3步:创建Web驱动程序单例类如何将Webdriver实例获取到在所有类文件中使用相同的实例

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

第4步:在WebUI类中将Katalon方法实现为静态.

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);
}
}

第5步:使用TestNG批注编写脚本

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();
  }
}

使用上述方法,您可以重复使用Katalon脚本.希望对您有帮助!

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

这篇关于如何在Selenium Java中转换Katalon脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆