How to execute basic Java code in Katalon Studio

2020-04-19 07:10发布

I am trying to execute this basic program in Katalon Studio and Java but the O/P shows

if (i < 12)

Can you help me out on how to execute or use Java in Katalon Studio just like IntelliJ or Eclipse?

int i = 10;
if (i == 10) 
{ 
    // First if statement 
    if (i < 15) 
        System.out.println("i is smaller than 15"); 

    // Nested - if statement 
    // Will only be executed if statement above 
    // it is true 
    if (i < 12) 
        System.out.println("i is smaller than 12 too"); 
    else
        System.out.println("i is greater than 15"); 
}

1条回答
闹够了就滚
2楼-- · 2020-04-19 07:34

Simple:

  1. Open Katalon Studio
  2. Add a new Test Case that you can call as you wish
  3. Switch to </> Script tab near the bottom of your work window
  4. Now you have an eclipse-like workspace, you just paste the above code (no need for main(), this is a Groovy editor)
  5. Press the Run button at the top and you will get the following (or similar) output:
SLF4J: The requested version 1.7.16 by your slf4j binding is not compatible with [1.6]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
2019-04-26 14:00:02.294 [34mINFO [0;39m [36mc.k.katalon.core.main.TestCaseExecutor   -[0;39m [39m--------------------[0;39m
2019-04-26 14:00:02.297 [34mINFO [0;39m [36mc.k.katalon.core.main.TestCaseExecutor   -[0;39m [39mSTART Test Cases/test so[0;39m
2019-04-26 14:00:02.864 [39mDEBUG[0;39m [36mtestcase.test so                         -[0;39m [39m1: i = 10[0;39m
2019-04-26 14:00:02.866 [39mDEBUG[0;39m [36mtestcase.test so                         -[0;39m [39m2: if (i == 10)[0;39m
2019-04-26 14:00:02.868 [39mDEBUG[0;39m [36mtestcase.test so                         -[0;39m [39m1: if (i < 15)[0;39m
i is smaller than 15
2019-04-26 14:00:02.883 [39mDEBUG[0;39m [36mtestcase.test so                         -[0;39m [39m2: if (i < 12)[0;39m
i is smaller than 12 too
2019-04-26 14:00:02.886 [34mINFO [0;39m [36mc.k.katalon.core.main.TestCaseExecutor   -[0;39m [39mEND Test Cases/test so

Note: In Katalon Studio, you have to import Java libraries manually. This tool is not able to import automatically as eclipse can. For example, if you have to format data then need to import the libraries below:

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.UUID;

 public class TestData {
 private static final SimpleDateFormat sdf = new 
 SimpleDateFormat("yyyyMMdd_HHmmss");
 public static String getTimeStamp() {
    Timestamp tm = new Timestamp(System.currentTimeMillis());
    String timestamp=sdf.format(tm);
    return timestamp;
    }
 }
查看更多
登录 后发表回答