The HTML formatter for cucumber-jvm was working for me yesterday. Today, when I run the tests, I get the following content in the index.html that gets produced. All of the other supporting files (style.css, formatter.js, etc.) are there:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Cucumber Features</title>
<link href="style.css" rel="stylesheet">
<script src="jquery-1.6.4.min.js"></script>
<script src="formatter.js"></script>
<script src="report.js"></script>
</head>
<body>
<div class="cucumber-report"></div>
</body>
</html>
The report.js file contains the correct content for the tests I just ran but the browser renders a blank page when I bring up the index.html file. I am running just a simple test just to get everything wired up. My test class looks like this:
import org.junit.runner.RunWith;
import cucumber.junit.Cucumber;
@RunWith(Cucumber.class)
@Cucumber.Options(format = {"html:build/reports/tests/cucumber"})
public class BasicUITest {
}
As I said, my tests run fine. I can see the junit xml output and it is correct (aside from the fact that it doesn't actually register failing tests as failing - but that's another issue).
What could I have done to my configuration so that it no longer puts content into the html file?
For completeness, here is my step definitions file:
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestBase;
import cucumber.annotation.After;
import cucumber.annotation.Before;
import cucumber.annotation.en.Given;
import cucumber.annotation.en.Then;
public class StepDefinitions extends SeleneseTestBase {
@Before
public void initSelenium() throws Exception {
selenium = new DefaultSelenium("localhost", 5555, "*firefox", "http://localhost:8080/");
selenium.start();
}
@After
public void stopSelenium() throws Exception {
selenium.stop();
}
@Given("^I login as \"([^\"]*)\" with password \"([^\"]*)\"$")
public void login(String user, String password) {
selenium.open("/web/guest/real-login?p_p_state=maximized&p_p_mode=view&saveLastPath=0&_58_struts_action=%2Flogin%2Flogin&p_p_id=58&p_p_lifecycle=0&_58_redirect=http%3A%2F%2Flocalhost%3A8080%2Fc");
selenium.waitForPageToLoad("30000");
selenium.type("id=_58_login", user);
selenium.type("id=_58_password", password);
selenium.click("css=input.small");
selenium.waitForPageToLoad("30000");
selenium.click("css=input.highlight");
selenium.waitForPageToLoad("30000");
}
@Given("^I login as the \"([^\"]*)\" user$")
public void loginAsUser(String user) {
if (user.equalsIgnoreCase("msv admin")) {
login(TestData.getAdminUserEmail(), TestData.getSharedPassword());
} else if (user.equalsIgnoreCase("msv regular")) {
login(TestData.getRegularUserEmail(), TestData.getSharedPassword());
} else if (user.equalsIgnoreCase("msv executer")) {
login(TestData.getExecuterUserEmail(), TestData.getSharedPassword());
}
}
@Then("^I go to the MSV App page$")
public void gotoMSVPage() {
selenium.click("link=" + TestData.getCommunityPageName());
selenium.waitForPageToLoad("30000");
}
@Then("^I logout$")
public void logout() {
selenium.click("link=Sign Out");
selenium.waitForPageToLoad("30000");
}
@Then("^I should see \"([^\"]*)\"$")
public void shouldSee(String value) {
verifyTrue(selenium.isTextPresent(value));
checkForVerificationErrors();
}
@Then("^I should not see \"([^\"]*)\"$")
public void shouldNotSee(String value) {
verifyFalse(selenium.isTextPresent(value));
checkForVerificationErrors();
}
}
I am running it through gradle 1.0, if that makes a difference (I don't think so since it was working yesterday).
Any help is appreciated.
Ok, I discovered what was wrong thanks to firebug.
Cucumber-jvm automatically finds the feature files that are the same name as the corresponding java file. For me this was something like:
com.nowhere.myapp.uat.BasicUITest
with a corresponding feature file in:
/src/test/resources/com/nowhere/myapp/uat/BasicUITest.feature
When cucumber generates the report.js file, it points to the feature file with a call like:
formatter.uri('com\nowhere\myapp\uat\BasicUITest.feature');
The feature file location string is not a valid URI, so it causes a browser error which showed up in the firebug console. The error is that "\u" is an escape sequence in URIs. Lesson to be learned:
Don't use a package name that has any component starting with the letter "u" as this will cause a malformed URI exception in the browser.