Katalon Studio中的Java脚本
我编写了几个java测试,并用它们与Eclipse一起运行 我想将它们导入katalon并运行它们 例如,我在这里有一个登录脚本:Katalon Studio中的Java脚本,java,katalon-studio,Java,Katalon Studio,我编写了几个java测试,并用它们与Eclipse一起运行 我想将它们导入katalon并运行它们 例如,我在这里有一个登录脚本: import java.io.IOException; import java.util.concurrent.TimeUnit; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.*; public class Login { public static
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.*;
public class Login {
public static void main(String args[]) throws IOException {
IOException ioe = new IOException();
//Initializing server
System.setProperty("webdriver.chrome.driver", "C:/selenium/chromedriver.exe");
ChromeDriver wd = new ChromeDriver();
wd.manage().window().maximize();
wd.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//login
System.out.println("*** login ***");
wd.get("<URL>");
wd.findElement(By.xpath("//form[@id='form']/div[1]/paper-input/paper-input-container/div[2]/div/input")).click();
wd.findElement(By.xpath("//form[@id='form']/div[1]/paper-input/paper-input-container/div[2]/div/input")).clear();
wd.findElement(By.xpath("//form[@id='form']/div[1]/paper-input/paper-input-container/div[2]/div/input")).sendKeys("<USERNAME>");
wd.findElement(By.xpath("//form[@id='form']/div[2]/paper-input/paper-input-container/div[2]/div/input")).click();
wd.findElement(By.xpath("//form[@id='form']/div[2]/paper-input/paper-input-container/div[2]/div/input")).clear();
wd.findElement(By.xpath("//form[@id='form']/div[2]/paper-input/paper-input-container/div[2]/div/input")).sendKeys("<PASSWORD>");
wd.findElement(By.xpath("//form[@id='form']//paper-button[.='login']")).click();
try { Thread.sleep(3000l); } catch (Exception e) { throw new RuntimeException(e); }
if(wd.findElement(By.tagName("html")).getText().contains("please login")){
System.out.println("Login failed");
throw ioe;
}//End of login
System.out.println("Login was executed successfully!");
System.out.println("Testcase finished successfully!");
wd.quit();
}
}
import java.io.IOException;
导入java.util.concurrent.TimeUnit;
导入org.openqa.selenium.chrome.ChromeDriver;
导入org.openqa.selenium.*;
公共类登录{
公共静态void main(字符串args[])引发IOException{
IOException ioe=新IOException();
//初始化服务器
System.setProperty(“webdriver.chrome.driver”,“C:/selenium/chromedriver.exe”);
ChromeDriver wd=新ChromeDriver();
wd.manage().window().maximize();
wd.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
//登录
System.out.println(“***登录***”);
wd.get(“”);
wd.findElement(By.xpath(“//form[@id='form']/div[1]/paper-input/paper-input-container/div[2]/div/input”)。单击();
wd.findElement(By.xpath(“//form[@id='form']/div[1]/paper-input/paper-input-container/div[2]/div/input”)).clear();
wd.findelelement(By.xpath(“//form[@id='form']/div[1]/paper-input/paper-input-container/div[2]/div/input”)).sendKeys(“”);
wd.findElement(By.xpath(“//form[@id='form']/div[2]/paper-input/paper-input-container/div[2]/div/input”)。单击();
wd.findElement(By.xpath(“//form[@id='form']/div[2]/paper-input/paper-input-container/div[2]/div/input”)).clear();
wd.findelelement(By.xpath(“//form[@id='form']/div[2]/paper-input/paper-input-container/div[2]/div/input”)).sendKeys(“”);
wd.findElement(By.xpath(“//form[@id='form']//纸张按钮[.='login']))。单击();
尝试{Thread.sleep(3000l);}catch(异常e){throw new RuntimeException(e);}
如果(wd.findElement(By.tagName(“html”)).getText()包含(“请登录”)){
System.out.println(“登录失败”);
扔ioe;
}//登录结束
System.out.println(“登录已成功执行!”);
System.out.println(“Testcase已成功完成!”);
wd.quit();
}
}
我想像在卡塔隆一样运行它,但我不确定如何运行
谢谢 我尝试在不声明类和main方法的情况下添加现有的java脚本,它可以正常工作。 在您的示例中,请删除:import org.openqa.selenium.*,将其替换为:导入org.openqa.selenium.By,然后粘贴保留的脚本,而不粘贴
public class Login {
public static void main(String args[]) throws IOException {
}}
因此,您在Katalon中的自定义测试用例是:
import java.io.IOException;
导入java.util.concurrent.TimeUnit;
导入org.openqa.selenium.chrome.ChromeDriver;
导入org.openqa.selenium.By;
IOException ioe=新IOException();
//初始化服务器
System.setProperty(“webdriver.chrome.driver”,“C:/selenium/chromedriver.exe”);
ChromeDriver wd=新ChromeDriver();
wd.manage().window().maximize();
wd.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
//登录
System.out.println(“***登录***”);
wd.get(“”);
wd.findElement(By.xpath(“//form[@id='form']/div[1]/paper-input/paper-input-container/div[2]/div/input”)。单击();
wd.findElement(By.xpath(“//form[@id='form']/div[1]/paper-input/paper-input-container/div[2]/div/input”)).clear();
wd.findelelement(By.xpath(“//form[@id='form']/div[1]/paper-input/paper-input-container/div[2]/div/input”)).sendKeys(“”);
wd.findElement(By.xpath(“//form[@id='form']/div[2]/paper-input/paper-input-container/div[2]/div/input”)。单击();
wd.findElement(By.xpath(“//form[@id='form']/div[2]/paper-input/paper-input-container/div[2]/div/input”)).clear();
wd.findelelement(By.xpath(“//form[@id='form']/div[2]/paper-input/paper-input-container/div[2]/div/input”)).sendKeys(“”);
wd.findElement(By.xpath(“//form[@id='form']//纸张按钮[.='login']))。单击();
尝试{Thread.sleep(3000l);}catch(异常e){throw new RuntimeException(e);}
如果(wd.findElement(By.tagName(“html”)).getText()包含(“请登录”)){
System.out.println(“登录失败”);
扔ioe;
}//登录结束
System.out.println(“登录已成功执行!”);
System.out.println(“Testcase已成功完成!”);
wd.quit()代码>您不确定如何运行main方法,或者将Selenium添加到类路径以便它可以运行?我已经添加了必要的JAR以便它能够识别类和方法。我只是不知道如何使用katalon运行它。我需要在哪里粘贴脚本?我需要在脚本中进行哪些修改才能运行?文档中说有一个运行按钮。谈到脚本视图是的,我尝试过使用脚本模式,但不起作用。我的脚本包含调用chrome驱动程序的命令,而katalon groovey脚本中不需要这些命令,所以我不知道应该做哪些修改才能使其运行