Bug 762632 - Add an assertMatches method to BaseTest for better failure diagnostics [r=kats]

--HG--
extra : rebase_source : cb02e7ffd4f9d7655b315b28e21433fcb8a3c764
This commit is contained in:
Matt Brubeck 2012-06-08 11:43:23 -07:00
parent 19d46d4ac7
commit a7f3dcfb3e
2 changed files with 12 additions and 2 deletions

View File

@ -98,6 +98,14 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
super.tearDown();
}
public void assertMatches(String value, String regex, String name) {
if (value == null) {
mAsserter.ok(false, name, "Expected /" + regex + "/, got null");
return;
}
mAsserter.ok(value.matches(regex), name, "Expected /" + regex +"/, got \"" + value + "\"");
}
/**
* Click on the specified element and return the resulting activity.
* @return The created activity, or null if the element cannot be clicked.

View File

@ -15,7 +15,8 @@ public class testAboutPage extends BaseTest {
loadUrl(url);
Element awesomebar = mDriver.findElement(getActivity(), "awesome_bar");
mAsserter.ok(awesomebar != null && awesomebar.getText() != null && awesomebar.getText().matches("About (Fennec|Nightly|Aurora|Firefox|Firefox Beta)"), "page title match", "about: page title is correct");
mAsserter.isnot(awesomebar, null, "Got the awesomebar");
assertMatches(awesomebar.getText(), "About (Fennec|Nightly|Aurora|Firefox|Firefox Beta)", "page title match");
// Open a new page to remove the about: page from the current tab
url = getAbsoluteUrl("/robocop/robocop_blank_01.html");
@ -46,6 +47,7 @@ public class testAboutPage extends BaseTest {
// Grab the title to make sure the about: page was loaded
awesomebar = mDriver.findElement(getActivity(), "awesome_bar");
mAsserter.ok(awesomebar != null && awesomebar.getText() != null && awesomebar.getText().matches("About (Fennec|Nightly|Aurora|Firefox|Firefox Beta)"), "page title match", "about: page title is correct");
mAsserter.isnot(awesomebar, null, "Got the awesomebar");
assertMatches(awesomebar.getText(), "About (Fennec|Nightly|Aurora|Firefox|Firefox Beta)", "page title match");
}
}