r3507 - in trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui: . its
Author: ymartel Date: 2012-06-18 11:45:47 +0200 (Mon, 18 Jun 2012) New Revision: 3507 Url: http://chorem.org/repositories/revision/pollen/3507 Log: refs #606 : add ITs for free Date poll create Added: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeDatePollSIT.java 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/its/CreateFreeTextPollSIT.java 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-18 08:22:04 UTC (rev 3506) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenFixtures.java 2012-06-18 09:45:47 UTC (rev 3507) @@ -26,7 +26,11 @@ import org.apache.commons.logging.LogFactory; import org.chorem.pollen.PollenConfiguration; import org.chorem.pollen.bean.PollUri; +import org.nuiton.util.DateUtil; +import java.util.Calendar; +import java.util.Date; + /** * Some fixtures for tests. * @@ -79,6 +83,10 @@ return "b9b434acd58d42fca083d473ee021fce"; } + public String datePattern() { + return "dd/MM/yyyy HH:mm"; + } + public String homeURL() { return baseUrl() + "home"; } @@ -139,11 +147,19 @@ return baseUrl() + "poll/create"; } - public String editPollURL() { - return baseUrl() + "poll/edit"; - } - public String summaryURL() { return baseUrl() + "poll/summary"; } + + public String date(int year, int month, int day, int hour, int minute) { + Calendar instance = Calendar.getInstance(); + instance.set(year, month, day, hour, minute); + Date date = instance.getTime(); + String dateString = DateUtil.formatDate(date, datePattern()); + return dateString; + } + + public String date(int year, int month, int day) { + return date(year, month, day, 0, 0); + } } Added: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeDatePollSIT.java =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeDatePollSIT.java (rev 0) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeDatePollSIT.java 2012-06-18 09:45:47 UTC (rev 3507) @@ -0,0 +1,312 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $Id: CreateFreeTextPollSIT.java 3481 2012-06-15 15:12:06Z ymartel $ + * $HeadURL: http://svn.chorem.org/svn/pollen/trunk/pollen-ui-struts2/src/test/java/org/c... $ + * %% + * Copyright (C) 2009 - 2012 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +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; + +import java.util.List; + +/** + * Test the well work of a Free Date poll creation page. + * + * Tested cases : + * <ul> + * <li>Classic creation with filled mandatory fields (a title and at least 2 choices(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 invalid date format for one of the choices (KO)</li> + * </ul> + * + * @author ymartel <martel@codelutin.com> + * + * @since 1.4 + */ +public class CreateFreeDatePollSIT extends PollenBaseWebDriverIT { + + public CreateFreeDatePollSIT(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 createSimpleFreeDatePoll() throws Exception { + + // Go on home page + gotoUrl(fixtures.createPollURL()); + + // Set title + WebElement titleElement = findElement(By.name("poll.title")); + Assert.assertEquals("input", titleElement.getTagName()); + Assert.assertTrue(titleElement.isDisplayed()); + titleElement.sendKeys("My Date Poll"); + + // Switch to Date choices + List<WebElement> choiceTypesElement = findElements(By.name("poll.choiceType")); + Assert.assertEquals(3, choiceTypesElement.size()); + WebElement dateChoiceTypeElement = choiceTypesElement.get(1); + Assert.assertEquals("input", dateChoiceTypeElement.getTagName()); + Assert.assertEquals("DATE", dateChoiceTypeElement.getAttribute("value")); + Assert.assertTrue(dateChoiceTypeElement.isDisplayed()); + dateChoiceTypeElement.click(); + + // Set first choice + WebElement choiceOneElement = findElement(By.name("dateChoice_0.name")); + Assert.assertEquals("input", choiceOneElement.getTagName()); + Assert.assertTrue(choiceOneElement.isDisplayed()); + choiceOneElement.sendKeys(fixtures.date(1431, 05, 30)); + + // Set second choice + WebElement choiceTwoElement = findElement(By.name("dateChoice_1.name")); + Assert.assertEquals("input", choiceTwoElement.getTagName()); + Assert.assertTrue(choiceTwoElement.isDisplayed()); + choiceTwoElement.sendKeys(fixtures.date(1789, 8, 26)); + + // Submit form + WebElement submit = findElement(By.name("action:create")); + submit.click(); + + // All good, should be on summary page ! + checkCurrentUrl(fixtures.summaryURL(), false); + } + + /** + * This test create a free date poll with two choices but no title. + * At the end, should be still on create page, with an error message. + */ + @Test + public void createSimpleFreeDatePollWithoutTitle() throws Exception { + + // Go on home page + gotoUrl(fixtures.createPollURL()); + + // Switch to Date choices + List<WebElement> choiceTypesElement = findElements(By.name("poll.choiceType")); + Assert.assertEquals(3, choiceTypesElement.size()); + WebElement dateChoiceTypeElement = choiceTypesElement.get(1); + Assert.assertEquals("input", dateChoiceTypeElement.getTagName()); + Assert.assertEquals("DATE", dateChoiceTypeElement.getAttribute("value")); + Assert.assertTrue(dateChoiceTypeElement.isDisplayed()); + dateChoiceTypeElement.click(); + + // Set first choice + WebElement choiceOneElement = findElement(By.name("dateChoice_0.name")); + Assert.assertEquals("input", choiceOneElement.getTagName()); + Assert.assertTrue(choiceOneElement.isDisplayed()); + String choiceOneValue = fixtures.date(1431, 05, 30); + choiceOneElement.sendKeys(choiceOneValue); + + // Set second choice + WebElement choiceTwoElement = findElement(By.name("dateChoice_1.name")); + Assert.assertEquals("input", choiceTwoElement.getTagName()); + Assert.assertTrue(choiceTwoElement.isDisplayed()); + String choiceTwoValue = fixtures.date(1789, 8, 26); + choiceTwoElement.sendKeys(choiceTwoValue); + + // Submit form + WebElement submit = findElement(By.name("action:create")); + submit.click(); + + // Title is missing, should stay on create poll page + checkCurrentUrl(fixtures.createPollURL(), false); + + // Check an error message has been displayed + WebElement titleError = findElement(By.className("errorMessage")); + Assert.assertNotNull(titleError); + + // Check that choice fields are not lost + choiceOneElement = findElement(By.name("dateChoice_0.name")); + Assert.assertEquals("input", choiceOneElement.getTagName()); + Assert.assertTrue(choiceOneElement.isDisplayed()); + Assert.assertEquals(choiceOneValue, choiceOneElement.getAttribute("value")); + choiceTwoElement = findElement(By.name("dateChoice_1.name")); + Assert.assertEquals("input", choiceTwoElement.getTagName()); + Assert.assertTrue(choiceTwoElement.isDisplayed()); + Assert.assertEquals(choiceTwoValue, choiceTwoElement.getAttribute("value")); + + } + + /** + * This test create a free date poll without choices. + * At the end, should be still on create page, with an error message. + */ + @Test + public void createSimpleFreeDatePollWithoutChoice() throws Exception { + + // Go on home page + gotoUrl(fixtures.createPollURL()); + + // Set title + WebElement titleElement = findElement(By.name("poll.title")); + Assert.assertEquals("input", titleElement.getTagName()); + Assert.assertTrue(titleElement.isDisplayed()); + String pollTitle = "My Date Poll"; + titleElement.sendKeys(pollTitle); + + // Switch to Date choices + List<WebElement> choiceTypesElement = findElements(By.name("poll.choiceType")); + Assert.assertEquals(3, choiceTypesElement.size()); + WebElement dateChoiceTypeElement = choiceTypesElement.get(1); + Assert.assertEquals("input", dateChoiceTypeElement.getTagName()); + Assert.assertEquals("DATE", dateChoiceTypeElement.getAttribute("value")); + Assert.assertTrue(dateChoiceTypeElement.isDisplayed()); + dateChoiceTypeElement.click(); + + // Submit form + WebElement submit = findElement(By.name("action:create")); + submit.click(); + + // No choices, should stay on create poll page + checkCurrentUrl(fixtures.createPollURL(), false); + + // Check that title field is not lost + titleElement = 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 = findElement(By.id("poll_choices_error")); + Assert.assertNotNull(choicesError); + + // Check that we are still on Date choices + choiceTypesElement = findElements(By.name("poll.choiceType")); + Assert.assertEquals(3, choiceTypesElement.size()); + dateChoiceTypeElement = choiceTypesElement.get(1); + Assert.assertEquals("input", dateChoiceTypeElement.getTagName()); + Assert.assertEquals("DATE", dateChoiceTypeElement.getAttribute("value")); + Assert.assertEquals("true", dateChoiceTypeElement.getAttribute("checked")); + + } + + /** + * This test create a free date poll with a same value for two choices. + * At the end, should be still on create page, with an error message. + * + */ + @Test + public void createSimpleFreeDatePollWithTwoSameDate() throws Exception { + + // Go on home page + gotoUrl(fixtures.createPollURL()); + + // Set title + WebElement titleElement = findElement(By.name("poll.title")); + Assert.assertEquals("input", titleElement.getTagName()); + Assert.assertTrue(titleElement.isDisplayed()); + titleElement.sendKeys("My Date Poll"); + + // Switch to Date choices + List<WebElement> choiceTypesElement = findElements(By.name("poll.choiceType")); + Assert.assertEquals(3, choiceTypesElement.size()); + WebElement dateChoiceTypeElement = choiceTypesElement.get(1); + Assert.assertEquals("input", dateChoiceTypeElement.getTagName()); + Assert.assertEquals("DATE", dateChoiceTypeElement.getAttribute("value")); + Assert.assertTrue(dateChoiceTypeElement.isDisplayed()); + dateChoiceTypeElement.click(); + + // Set first choice + WebElement choiceOneElement = findElement(By.name("dateChoice_0.name")); + Assert.assertEquals("input", choiceOneElement.getTagName()); + Assert.assertTrue(choiceOneElement.isDisplayed()); + String date = fixtures.date(1431, 05, 30); + choiceOneElement.sendKeys(date); + + // Set second choice + WebElement choiceTwoElement = findElement(By.name("dateChoice_1.name")); + Assert.assertEquals("input", choiceTwoElement.getTagName()); + Assert.assertTrue(choiceTwoElement.isDisplayed()); + choiceTwoElement.sendKeys(date); + + // Submit form + WebElement submit = findElement(By.name("action:create")); + submit.click(); + + // An error, should stay on create page + checkCurrentUrl(fixtures.createPollURL(), false); + + // Check an error message has been displayed for choices + WebElement choicesError = findElement(By.className("errorMessage")); + Assert.assertNotNull(choicesError); + } + + /** + * This test create a free date poll with a bas format for one of the choices. + * At the end, should be still on create page, with an error message. + * + */ + @Test + public void createSimpleFreeDatePollWithBadFormatDate() throws Exception { + + // Go on home page + gotoUrl(fixtures.createPollURL()); + + // Set title + WebElement titleElement = findElement(By.name("poll.title")); + Assert.assertEquals("input", titleElement.getTagName()); + Assert.assertTrue(titleElement.isDisplayed()); + titleElement.sendKeys("My Date Poll"); + + // Switch to Date choices + List<WebElement> choiceTypesElement = findElements(By.name("poll.choiceType")); + Assert.assertEquals(3, choiceTypesElement.size()); + WebElement dateChoiceTypeElement = choiceTypesElement.get(1); + Assert.assertEquals("input", dateChoiceTypeElement.getTagName()); + Assert.assertEquals("DATE", dateChoiceTypeElement.getAttribute("value")); + Assert.assertTrue(dateChoiceTypeElement.isDisplayed()); + dateChoiceTypeElement.click(); + + // Set first choice + WebElement choiceOneElement = findElement(By.name("dateChoice_0.name")); + Assert.assertEquals("input", choiceOneElement.getTagName()); + Assert.assertTrue(choiceOneElement.isDisplayed()); + choiceOneElement.sendKeys(fixtures.date(1431, 05, 30)); + + // Set second choice + WebElement choiceTwoElement = findElement(By.name("dateChoice_1.name")); + Assert.assertEquals("input", choiceTwoElement.getTagName()); + Assert.assertTrue(choiceTwoElement.isDisplayed()); + choiceTwoElement.sendKeys("28 08 1789"); + + // Submit form + WebElement submit = findElement(By.name("action:create")); + submit.click(); + + // An error, should stay on create page + checkCurrentUrl(fixtures.createPollURL(), false); + + // Check an error message has been displayed for choices + WebElement choicesError = findElement(By.className("errorMessage")); + Assert.assertNotNull(choicesError); + } + +} Modified: 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 2012-06-18 08:22:04 UTC (rev 3506) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeTextPollSIT.java 2012-06-18 09:45:47 UTC (rev 3507) @@ -286,7 +286,7 @@ WebElement startDateElement = findElement(By.name("poll.endDate")); Assert.assertEquals("input", startDateElement.getTagName()); Assert.assertTrue(startDateElement.isDisplayed()); - //FIXME ymartel 2012/06/14 : review way to get DAte ? + //FIXME ymartel 2012/06/14 : review way to get Date ? Date twoMonthsAgo = DateUtils.addMonths(new Date(), -2); String formatTwoMonthsAgo = DateUtil.formatDate(twoMonthsAgo, "dd/MM/yyyy HH:mm"); startDateElement.sendKeys(formatTwoMonthsAgo); @@ -438,8 +438,8 @@ checkCurrentUrl(fixtures.createPollURL(), false); // Check an error message has been displayed - WebElement dateError = findElement(By.className("errorMessage")); - Assert.assertNotNull(dateError); + WebElement maxChoicesError = findElement(By.className("errorMessage")); + Assert.assertNotNull(maxChoicesError); // Go on general tab and check that Title and and choice fields values are not lost WebElement generalClick = findElement(By.xpath("//a[@href=\"#tgeneral\"]")); @@ -472,6 +472,9 @@ // No choices, should stay on create poll page checkCurrentUrl(fixtures.createPollURL(), false); + // Check an error message has been displayed + maxChoicesError = findElement(By.className("errorMessage")); + Assert.assertNotNull(maxChoicesError); }
participants (1)
-
ymartel@users.chorem.org