Testing 测试中动态文本的验证
我正在尝试验证我的应用程序中的pin码。我正在使用Katalon,但我还没有找到答案 我需要验证的pin码长度相同,但每次运行测试时都不同,在我的页面上看起来是这样的:pin码:4938475948 如何解释每次运行测试时更改的数字 我尝试了以下正则表达式:Testing 测试中动态文本的验证,testing,katalon-studio,regression-testing,Testing,Katalon Studio,Regression Testing,我正在尝试验证我的应用程序中的pin码。我正在使用Katalon,但我还没有找到答案 我需要验证的pin码长度相同,但每次运行测试时都不同,在我的页面上看起来是这样的:pin码:4938475948 如何解释每次运行测试时更改的数字 我尝试了以下正则表达式: assertEquals( "PIN Code: [^a-z ]*([.0-9])*\\d", selenium.getText("//*[@id='RegItemContent0']/div/table/tbody/tr
assertEquals(
"PIN Code: [^a-z ]*([.0-9])*\\d",
selenium.getText("//*[@id='RegItemContent0']/div/table/tbody/tr/td[2]/table/tbody/tr[2]/td/div[1]/div[3]/ul/li[2]/span")
);
注意:这是用Selenium编码并转换为Katalon。在Katalon中,使用
WebUI.getText()
和WebUI.verifyMatch()
的组合来执行相同的操作
例如
如果需要,还可以使用
toInteger()
或toString()
groovy方法来转换类型。编辑上面的示例,但要使其正常工作
TestObject object = new TestObject().addProperty('xpath', ConditionType.EQUALS, '//*[@id='RegItemContent0']/div/table/tbody/tr/td[2]/table/tbody/tr[2]/td/div[1]/div[3]/ul/li[2]/span')
def actualText = WebUI.getText(object)
def expectedText = '4938475948'
WebUI.verifyMatch(actualText, expectedText, true)
这可以作为变量完成,但在您的情况下,我建议使用一些java
import java.util.Random;
Random rand = new Random();
int n = rand.nextInt(9000000000) + 1000000000;
// this will also cover the bad PIN (above limit)
我会稍微调整一下你的正则表达式,因为你的pin码每次都是相同的长度:你可以限制正则表达式查找的位数,并确保下面的字符是空白(即不是数字或其他杂散字符)。最后,使用“true”标志让WebUI.verifyMatch()知道它应该从第二个字符串中得到正则表达式(regex必须是第二个参数)
希望有帮助 请分享网页的相关html
import java.util.Random;
Random rand = new Random();
int n = rand.nextInt(9000000000) + 1000000000;
// this will also cover the bad PIN (above limit)
def regexExpectedText = "PIN Code: ([0-9]){10}\\s"
TestObject pinCodeTO = new TestObject().addProperty('xpath', ConditionType.EQUALS, '//*[@id='RegItemContent0']/div/table/tbody/tr/td[2]/table/tbody/tr[2]/td/div[1]/div[3]/ul/li[2]/span')
def actualText = WebUI.getText(pinCodeTO)
WebUI.verifyMatch(actualText, expectedText, true)