最近开始学习Katalon Studio。观看了一些关于主要功能和如何使用的视频。为了测试注册表单,我需要使某种随机生成器自定义关键字的电子邮件和密码在Katalon。
主要的问题是--我还不知道怎么写这样的代码(没有经验)。如果能帮上忙我会很高兴。
这是一个自动化的网络测试。
在更改此代码之前,我需要创建自定义关键字:
WebUI.openBrowser('')
WebUI.navigateToUrl('http://flyshot.phoenixfw.net/login')
WebUI.click(findTestObject('Object Repository/Sign Up/Page_Flyshot Admin Panel/a_Sign Up'))
WebUI.setText(findTestObject('Object Repository/Sign Up/Page_Flyshot Admin Panel/input_Sign up with your work email address_sign_upemail'),
'transformer@gmail.com')
WebUI.setText(findTestObject('Object Repository/Sign Up/Page_Flyshot Admin Panel/input_Sign up with your work email address_sign_upcustomertitle'),
'ZXC')
WebUI.setEncryptedText(findTestObject('Object Repository/Sign Up/Page_Flyshot Admin Panel/input_Sign up with your work email address_sign_upplainPasswordfirst'),
'MhX+xzZUIsF4+4Abaxd7eg==')
WebUI.setEncryptedText(findTestObject('Object Repository/Sign Up/Page_Flyshot Admin Panel/input_Sign up with your work email address_sign_upplainPasswordsecond'),
'MhX+xzZUIsF4+4Abaxd7eg==')
WebUI.click(findTestObject('Object Repository/Sign Up/Page_Flyshot Admin Panel/span'))
WebUI.click(findTestObject('Object Repository/Sign Up/Page_Flyshot Admin Panel/button_Create New Account'))
not_run: WebUI.closeBrowser()我只需要做几个自动化测试。
发布于 2019-08-30 13:48:42
您可以在关键字部分中创建代码并调用它。
将以下代码作为关键字编写:
import com.kms.katalon.core.annotation.Keyword
class help_keyword_RandomEmail {
//random mail generator
@Keyword
public String getEmail(String suffix,String prefix){
int randomNo = (int)(Math.random() * 100000);
return suffix + randomNo + "@" + prefix;
}
}在您的测试用例中:
String mail = CustomKeywords.'mubasher.help_keyword_RandomEmail.getEmail'('opps'(suffix is here), 'mailinator.com' (prefix is here))
WebUI.sendKeys(findTestObject('Sign Up/email'), mail)发布于 2019-08-30 23:43:05
如果您需要保存这些数据并使用它们(例如,用于登录或稍后删除它们),每次都使用新的随机数据是不明智的(除非您无法在之后清理),您可以使用测试数据(在Excel表格中指定帐户)
如果您只需要一个帐户,您可以只使用一个GlobalVariable,它存储初始化过程中的随机值,以备将来使用。检查另一个答案。
https://stackoverflow.com/questions/57709338
复制相似问题