Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using regexp in assertEquals() does not work

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?

like image 785
John Avatar asked Dec 01 '10 23:12

John


1 Answers

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}.*"));
like image 125
javamonkey79 Avatar answered Oct 21 '22 12:10

javamonkey79