简体   繁体   English

如何使用 Selenium 和 Java 针对我的输出断言正则表达式?

[英]How to assert the regular expression against my output using Selenium and Java?

This is my regex:这是我的正则表达式:

/(\u20AC|\u00A3)[\d,]*/?(week|wk|month|mth|year|yr)?/

How can I verify this regular expression against my output using Selenium?如何使用 Selenium 针对我的输出验证此正则表达式?

I will consider that your selenium output is a variable named "seleniumOut".我会认为您的硒输出是一个名为“seleniumOut”的变量。

The assert in a test with regex can be writted this way:正则表达式测试中的断言可以这样写:

Pattern p = Pattern.compile("(\u20AC|\u00A3)[\d,]*/?(week|wk|month|mth|year|yr)?");
Matcher m = p.matcher(seleniumOut);

assertTrue("regex needs match the selenium output", m.matches());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM