如何在Katalon Studio中执行基本的Java代码 [英] How to execute basic Java code in Katalon Studio

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

问题描述

我正在尝试在Katalon Studio和Java中执行此基本程序,但O/P会显示

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

if (i < 12)

您能否像IntelliJ或Eclipse一样帮助我了解如何在Katalon Studio中执行或使用Java?

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. 打开Katalon Studio
  2. 添加一个新的测试用例,您可以根据需要调用它
  3. 切换到工作窗口底部附近的</> Script标签
  4. 现在您有了一个类似Eclipse的工作区,只需粘贴上面的代码(不需要main(),这是一个Groovy编辑器)
  5. 按下顶部的Run按钮,您将获得以下(或类似的)输出:
  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

注意:在Katalon Studio中,您必须手动导入Java库.此工具无法像Eclipse一样自动导入. 例如,如果您必须格式化数据,则需要导入以下库:

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

这篇关于如何在Katalon Studio中执行基本的Java代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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