【问题标题】:Can we generate random unique alphabets for a textfield in katalon studio?我们可以为katalon studio中的文本字段生成随机的唯一字母吗?
【发布时间】:2020-03-31 08:14:50
【问题描述】:

有人知道如何在每次新运行时在 Katalon 工作室中为文本字段生成唯一的字母吗?这是使用自定义关键字完成的还是代码写在脚本部分下? 我尝试创建一个自定义关键字并将以下代码保留在关键字中,但不知道如何在我的测试用例中调用该函数。请帮忙

我的自定义关键字下的代码:

public class testkeyword {

    @Keyword

    def testkeyword() {
        String chars = "abcdefghijklmnopqrstuvwxyz"
        println randomString(chars, 10)
    }

    public static String randomString(String chars, int length) {
        Random rand = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i=0; i<length; i++) {
            sb.append(chars.charAt(rand.nextInt(chars.length())));
        }
        return sb.toString();
    }
}

【问题讨论】:

    标签: katalon-studio


    【解决方案1】:

    您的“testkeyword”类可能在一个包内(我称之为“testpackage”),您可以在左侧的测试资源管理器中看到:

    Keywords
      + 'testpackage'
          +'testkeyword.groovy'
    

    为了在另一个测试用例中使用它,您需要导入上述包。在测试用例文件的顶部添加以下导入语句:

    import testpackage.testkeyword
    

    然后调用函数

    testkeyword.testkeyword()
    

    在测试用例内部。

    【讨论】:

    • 非常感谢您的回答。我按照您的建议做了相应的操作,但现在我收到以下错误:groovy.lang.MissingMethodException:没有方法签名:静态 package1.customfunctions.testkeyword() 适用于参数类型:() 值:[] 可能的解决方案: testkeyword()
    • 你改过类名了吗?因为在原始帖子中,该类被称为“testkeyword”,而在该消息中,该类是“customfunctions”......
    • 是的,我将类名更改为 customfunctions 并在需要的地方重命名。但除此之外,没有进行任何其他更改。您能否建议我为什么会收到此错误:groovy.lang.MissingMethodException:没有方法签名:静态 package1.customfunctions.testkeyword() 适用于参数类型:() 值:[] 可能的解决方案:testkeyword()跨度>
    • 您能分享一下您调用该方法的代码部分吗?
    • 是的,当然! WebUI.setText(findTestObject('Object Repository/group create/Page_FoneCreditAdmin/input_Name_form-control ng-untouched ng-pri_24ff78'), CustomKeywords.'package1.customfunctions.testkeyword'())
    猜你喜欢
    • 2011-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-05
    • 1970-01-01
    • 2015-07-29
    • 2011-02-17
    相关资源
    最近更新 更多