r3470 - in trunk/pollen-ui-struts2/src: main/webapp/WEB-INF/jsp/poll test/java/org/chorem/pollen/ui test/java/org/chorem/pollen/ui/its test/resources
Author: ymartel Date: 2012-06-13 18:30:41 +0200 (Wed, 13 Jun 2012) New Revision: 3470 Url: http://chorem.org/repositories/revision/pollen/3470 Log: refs #606 : add tests for free text poll creation with no options Added: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeTextPollSIT.java Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll_choices.jsp trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenFixtures.java trunk/pollen-ui-struts2/src/test/resources/pollendb.h2.db Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll_choices.jsp =================================================================== --- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll_choices.jsp 2012-06-13 15:59:38 UTC (rev 3469) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/createPoll_choices.jsp 2012-06-13 16:30:41 UTC (rev 3470) @@ -29,7 +29,7 @@ <s:radio key='poll.choiceType' list="choiceTypes" label='' theme="simple" disabled="%{voteStarted}"/> <hr/> -<s:fielderror fieldName="poll.choices"/> +<s:fielderror fieldName="poll.choices" id="poll_choices_error" /> <s:set id='deleteTitle'><s:text name="pollen.action.pollChoiceDelete"/></s:set> @@ -43,7 +43,7 @@ value="%{#choiceNumber}"/></s:set> <div id='choicesTEXT_<s:property value="choiceNumber"/>'> <s:hidden key='%{#prefix}.topiaId' value='%{#choice.topiaId}' label=''/> - <sp:fielderror fieldName="%{#prefix}"/> + <sp:fielderror fieldName="%{#prefix}" id="%{#prefix}_error"/> <div class="fleft choiceName"> <s:label for="%{#prefix}.name" id="choicesTEXT_label_%{#choiceNumber}" theme="simple" value=''/> @@ -97,7 +97,7 @@ <div id='choicesDATE_<s:property value="choiceNumber"/>'> <s:hidden key='%{#prefix}.topiaId' id='%{#prefix}.topiaId' value='%{#choice.topiaId}' label='' theme="simple"/> - <sp:fielderror fieldName="%{#prefix}"/> + <sp:fielderror fieldName="%{#prefix}" id="%{#prefix}_error"/> <div class="fleft choiceName"> <s:label for="%{#prefix}.name" id="choicesDATE_label_%{choiceNumber}" theme="simple" value=''/> @@ -152,7 +152,7 @@ value="%{#choiceNumber}"/></s:set> <div id='choicesIMAGE_<s:property value="choiceNumber"/>'> <s:hidden key='%{#prefix}.topiaId' value='%{#choice.topiaId}' label=''/> - <sp:fielderror fieldName="%{#prefix}"/> + <sp:fielderror fieldName="%{#prefix}" id="%{#prefix}_error"/> <div class="fleft choiceName"> <s:label for="%{#prefix}.name" id="choicesIMAGE_label_%{choiceNumber}" theme="simple" value=''/> Modified: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenFixtures.java =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenFixtures.java 2012-06-13 15:59:38 UTC (rev 3469) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenFixtures.java 2012-06-13 16:30:41 UTC (rev 3470) @@ -142,4 +142,12 @@ public String poll_creator_requiredURL() { return baseUrl() + "security/poll_creator_required"; } + + public String createPollURL() { + return baseUrl() + "poll/create"; + } + + public String summaryURL() { + return baseUrl() + "poll/summary"; + } } Added: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeTextPollSIT.java =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeTextPollSIT.java (rev 0) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeTextPollSIT.java 2012-06-13 16:30:41 UTC (rev 3470) @@ -0,0 +1,164 @@ +package org.chorem.pollen.ui.its; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +/** + * Test the well work of a Free text poll creation page. + * + * Tested cases : + * <ul> + * <li>Classic creation with filled mandatory fields (OK)</li> + * <li>Classic creation with no title (KO)</li> + * <li>Classic creation with no choice (KO)</li> + * <li>Classic creation with two same choices (KO)</li> + * <li>Classic creation with ending date before starting date (KO)</li> + * <li>Classic creation with ending date before now (KO)</li> + * <li>Classic creation with invalid email (KO)</li> + * <li>Classic creation with an authorized number of choice per vote < 1 (KO)</li> + * <li>Classic creation with choice adding ending date before starting date (KO)</li> + * <li>Classic creation with choice adding starting date after poll ending date (KO)</li> + * <li>Classic creation with choice adding ending date after poll ending date (KO)</li> + * </ul> + * + * @author ymartel <martel@codelutin.com> + * + * @since 1.4 + */ +public class CreateFreeTextPollSIT extends PollenBaseWebDriverIT { + + public CreateFreeTextPollSIT(Class<? extends WebDriver> driverType) { + super(driverType); + } + + /** + * This test create a simple free text poll. + * At the end, should be on summary page. + * + * @throws Exception + */ + @Test + public void createSimpleFreeTextPoll() throws Exception { + + // Go on home page + gotoUrl(fixtures.createPollURL()); + + // Set title + WebElement titleElement = driver.findElement(By.name("poll.title")); + Assert.assertEquals("input", titleElement.getTagName()); + Assert.assertTrue(titleElement.isDisplayed()); + titleElement.sendKeys("My Poll"); + + // Set first choice + WebElement choiceOneElement = driver.findElement(By.name("textChoice_0.name")); + Assert.assertEquals("input", choiceOneElement.getTagName()); + Assert.assertTrue(choiceOneElement.isDisplayed()); + choiceOneElement.sendKeys("Choix numero un"); + + // Set second choice + WebElement choiceTwoElement = driver.findElement(By.name("textChoice_1.name")); + Assert.assertEquals("input", choiceTwoElement.getTagName()); + Assert.assertTrue(choiceTwoElement.isDisplayed()); + choiceTwoElement.sendKeys("Choix numero deux"); + + // Submit form + WebElement submit = driver.findElement(By.name("action:save")); + submit.click(); + + // All good, should be on summary page ! + String currentUrl = driver.getCurrentUrl(); + Assert.assertTrue(currentUrl.startsWith(fixtures.summaryURL())); + } + + /** + * This test create a simple free text poll without a title. + * When submit, an error text should be displayed : title is mandatory + * + * @throws Exception + */ + @Test + public void createSimpleFreeTextPollWithoutTitle() throws Exception { + + // Go on home page + gotoUrl(fixtures.createPollURL()); + + // Set first choice + WebElement choiceOneElement = driver.findElement(By.name("textChoice_0.name")); + Assert.assertEquals("input", choiceOneElement.getTagName()); + Assert.assertTrue(choiceOneElement.isDisplayed()); + String choiceOneValue = "Choix numero un"; + choiceOneElement.sendKeys(choiceOneValue); + + // Set second choice + WebElement choiceTwoElement = driver.findElement(By.name("textChoice_1.name")); + Assert.assertEquals("input", choiceTwoElement.getTagName()); + Assert.assertTrue(choiceTwoElement.isDisplayed()); + String choiceTwoValue = "Choix numero deux"; + choiceTwoElement.sendKeys(choiceTwoValue); + + // Submit form + WebElement submit = driver.findElement(By.name("action:save")); + submit.click(); + + // Title is missing, should stay on create poll page + Assert.assertTrue(driver.getCurrentUrl().startsWith(fixtures.createPollURL())); + + // Check an error message has been displayed + WebElement titleError = driver.findElement(By.className("errorMessage")); + Assert.assertNotNull(titleError); + + // Check that choice fields are not lost + choiceOneElement = driver.findElement(By.name("textChoice_0.name")); + Assert.assertEquals("input", choiceOneElement.getTagName()); + Assert.assertTrue(choiceOneElement.isDisplayed()); + Assert.assertEquals(choiceOneValue, choiceOneElement.getAttribute("value")); + choiceTwoElement = driver.findElement(By.name("textChoice_1.name")); + Assert.assertEquals("input", choiceTwoElement.getTagName()); + Assert.assertTrue(choiceTwoElement.isDisplayed()); + Assert.assertEquals(choiceTwoValue, choiceTwoElement.getAttribute("value")); + + } + + /** + * This test create a simple free text poll with no choice. + * When submit, an error text should be displayed : at least one choice must be given + * + * @throws Exception + */ + @Test + public void createSimpleFreeTextPollWithoutChoice() throws Exception { + + // Go on home page + gotoUrl(fixtures.createPollURL()); + + // Set title + WebElement titleElement = driver.findElement(By.name("poll.title")); + Assert.assertEquals("input", titleElement.getTagName()); + Assert.assertTrue(titleElement.isDisplayed()); + String pollTitle = "My Poll"; + titleElement.sendKeys(pollTitle); + + // Submit form + WebElement submit = driver.findElement(By.name("action:save")); + submit.click(); + + // No choices, should stay on create poll page + Assert.assertTrue(driver.getCurrentUrl().startsWith(fixtures.createPollURL())); + + // Check that choice fields are not lost + titleElement = driver.findElement(By.name("poll.title")); + Assert.assertEquals("input", titleElement.getTagName()); + Assert.assertTrue(titleElement.isDisplayed()); + Assert.assertEquals(pollTitle, titleElement.getAttribute("value")); + + // Check an error message has been displayed for choices + WebElement choicesError = driver.findElement(By.id("poll_choices_error")); + Assert.assertNotNull(choicesError); + + + } + +} Modified: trunk/pollen-ui-struts2/src/test/resources/pollendb.h2.db =================================================================== (Binary files differ)
participants (1)
-
ymartel@users.chorem.org