1

I have several java tests that I wrote and used to run them with Eclipse.

I want to import them to katalon and run them.

For example, I have a login script here:

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

I want to run it as is in katalon but I'm not sure how.

Thanks.

4

1 に答える 1

2

クラスとメインメソッドを宣言せずに既存のJavaスクリプトを追加しようとすると、機能します。あなたの例では、削除してください: import org.openqa.selenium.*; 、次のように置き換えます: import org.openqa.selenium.By次に、残りのスクリプトを貼り付けます

public class Login {
     public static void main(String args[]) throws IOException {
}}

したがって、Katalon でのカスタム テスト ケースは次のようになります。

import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.By;

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

于 2017-12-21T05:36:18.413 に答える