문제

I'm having problems with using regexp in my assertEquals() statement. This is the statement.

Assert.assertEquals("regexp:*TST-*[0-9]{5}", driver.getTitle());

But I get this error:

org.junit.ComparisonFailure: expected:<[regexp:*TST-*[0-9]{5}]> but was:<[[#TST-23570] This is the new summary]>

It looks like the regexp is just a string that is being compared. What am I missing?

도움이 되었습니까?

해결책

It doesn't look like you're actually using the regex. It seems like maybe this is what you're trying to do?

Assert.assertTrue(driver.getTitle().matches("*TST-*[0-9]{5}"));

EDIT #1:

It also seems like your regex might not be quite right, try:

Assert.assertTrue(driver.getTitle().matches(".*TST-\\d{5}.*"));

다른 팁

You're asserting the two Strings are the same. In your case you're trying to check that your title is equal to "regexp:TST-[0-9]{5}", and not the regexp.

You maybe want to do this:

assert_true(driver.getTitle().matches("*TST-*[0-9]{5}"));

http://cupi2.uniandes.edu.co/javadoc/j2se/1.5.0/docs/api/java/lang/String.html#matches(java.lang.String)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top