r3476 - in trunk/pollen-ui-struts2: . src/test/java/org/chorem/pollen/ui/its src/test/resources
Author: ymartel Date: 2012-06-14 18:16:34 +0200 (Thu, 14 Jun 2012) New Revision: 3476 Url: http://chorem.org/repositories/revision/pollen/3476 Log: refs #606 : add tests for free text poll creation with some invalid options \& add a profile to start a server to run ITs Modified: trunk/pollen-ui-struts2/pom.xml 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/PollenBaseWebDriverIT.java trunk/pollen-ui-struts2/src/test/resources/pollendb.h2.db Modified: trunk/pollen-ui-struts2/pom.xml =================================================================== --- trunk/pollen-ui-struts2/pom.xml 2012-06-13 17:50:09 UTC (rev 3475) +++ trunk/pollen-ui-struts2/pom.xml 2012-06-14 16:16:34 UTC (rev 3476) @@ -623,6 +623,56 @@ </build> </profile> + <profile> + <id>selenium-server</id> + <properties> + <pollenTestServerPort>8765</pollenTestServerPort> + <pollenTestUrl>http://localhost:${pollenTestServerPort}/${defaultWebContextPath}</pollenTestUrl> + <maven.test.skip>true</maven.test.skip> + </properties> + + <build> + <defaultGoal>pre-integration-test</defaultGoal> + <plugins> + <plugin> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty-maven-plugin</artifactId> + <executions> + + <execution> + <id>start-pollen</id> + <phase>pre-integration-test</phase> + <goals> + <goal>start</goal> + </goals> + <configuration> + <daemon>false</daemon> + <webAppConfig> + <descriptor>${basedir}/src/test/resources/web-test.xml</descriptor> + <contextPath>/${defaultWebContextPath}</contextPath> + + </webAppConfig> + <useTestClasspath>true</useTestClasspath> + <systemProperties> + <systemProperty> + <name>siteUrl</name> + <value>${pollenTestUrl}</value> + </systemProperty> + <systemProperty> + <name>jetty.port</name> + <value>${pollenTestServerPort}</value> + </systemProperty> + </systemProperties> + </configuration> + </execution> + + </executions> + </plugin> + + </plugins> + </build> + </profile> + </profiles> </project> 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-13 17:50:09 UTC (rev 3475) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateFreeTextPollSIT.java 2012-06-14 16:16:34 UTC (rev 3476) @@ -22,12 +22,16 @@ */ package org.chorem.pollen.ui.its; +import org.apache.commons.lang3.time.DateUtils; import org.junit.Assert; import org.junit.Test; +import org.nuiton.util.DateUtil; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; +import java.util.Date; + /** * Test the well work of a Free text poll creation page. * @@ -69,25 +73,25 @@ gotoUrl(fixtures.createPollURL()); // Set title - WebElement titleElement = driver.findElement(By.name("poll.title")); + WebElement titleElement = 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")); + WebElement choiceOneElement = 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")); + WebElement choiceTwoElement = 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")); + WebElement submit = findElement(By.name("action:save")); submit.click(); // All good, should be on summary page ! @@ -108,36 +112,36 @@ gotoUrl(fixtures.createPollURL()); // Set first choice - WebElement choiceOneElement = driver.findElement(By.name("textChoice_0.name")); + WebElement choiceOneElement = 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")); + WebElement choiceTwoElement = 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")); + WebElement submit = 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")); + WebElement titleError = findElement(By.className("errorMessage")); Assert.assertNotNull(titleError); // Check that choice fields are not lost - choiceOneElement = driver.findElement(By.name("textChoice_0.name")); + choiceOneElement = 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")); + choiceTwoElement = findElement(By.name("textChoice_1.name")); Assert.assertEquals("input", choiceTwoElement.getTagName()); Assert.assertTrue(choiceTwoElement.isDisplayed()); Assert.assertEquals(choiceTwoValue, choiceTwoElement.getAttribute("value")); @@ -157,30 +161,230 @@ gotoUrl(fixtures.createPollURL()); // Set title - WebElement titleElement = driver.findElement(By.name("poll.title")); + WebElement titleElement = 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")); + WebElement submit = 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")); + // 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 = driver.findElement(By.id("poll_choices_error")); + WebElement choicesError = findElement(By.id("poll_choices_error")); Assert.assertNotNull(choicesError); + } + /** + * This test create a free text poll with a ending date in the past. + * When submit, an error text should be displayed : the poll cannot end before starting ! + * + * @throws Exception + */ + @Test + public void createFreeTextPollWithAnteriorEndingDateThanToday() throws Exception { + + // Go on create poll 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 Poll"; + titleElement.sendKeys(pollTitle); + + // Set first choice + WebElement choiceOneElement = findElement(By.name("textChoice_0.name")); + Assert.assertEquals("input", choiceOneElement.getTagName()); + Assert.assertTrue(choiceOneElement.isDisplayed()); + String choiceOne = "Choix numero un"; + choiceOneElement.sendKeys(choiceOne); + + // Go to option panel : click on it + WebElement optionsClick = findElement(By.xpath("//a[@href=\"#toptions\"]")); + optionsClick.click(); + + // Set end date + WebElement endDateElement = findElement(By.name("poll.endDate")); + Assert.assertEquals("input", endDateElement.getTagName()); + Assert.assertTrue(endDateElement.isDisplayed()); + //FIXME ymartel 2012/06/14 : review way to get DAte ? + Date aMonthAgo = DateUtils.addMonths(new Date(), -1); + String formatMonthAgo = DateUtil.formatDate(aMonthAgo, "dd/MM/yyyy HH:mm"); + endDateElement.sendKeys(formatMonthAgo); + + // Submit form + WebElement submit = findElement(By.name("action:save")); + submit.click(); + + // No choices, should stay on create poll page + Assert.assertTrue(driver.getCurrentUrl().startsWith(fixtures.createPollURL())); + + // Check an error message has been displayed + WebElement dateError = findElement(By.className("errorMessage")); + Assert.assertNotNull(dateError); + + // Check that title is not displayed cause not in the tab in error + titleElement = findElement(By.name("poll.title")); + Assert.assertFalse(titleElement.isDisplayed()); + + // Go on general tab and check that Title and and choice fields values are not lost + WebElement generalClick = findElement(By.xpath("//a[@href=\"#tgeneral\"]")); + generalClick.click(); + + titleElement = findElement(By.name("poll.title")); + Assert.assertTrue(titleElement.isDisplayed()); + Assert.assertEquals(pollTitle, titleElement.getAttribute("value")); + + choiceOneElement = findElement(By.name("textChoice_0.name")); + Assert.assertTrue(choiceOneElement.isDisplayed()); + Assert.assertEquals(choiceOne, choiceOneElement.getAttribute("value")); + } + /** + * This test create a free text poll with a ending date before the starting date. + * When submit, an error text should be displayed : the poll cannot end before starting ! + * + * @throws Exception + */ + @Test + public void createFreeTextPollWithAnteriorEndDateThanStartDate() throws Exception { + + // Go on create poll 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 Poll"; + titleElement.sendKeys(pollTitle); + + // Set first choice + WebElement choiceOneElement = findElement(By.name("textChoice_0.name")); + Assert.assertEquals("input", choiceOneElement.getTagName()); + Assert.assertTrue(choiceOneElement.isDisplayed()); + String choiceOne = "Choix numero un"; + choiceOneElement.sendKeys(choiceOne); + + // Go to option panel : click on it + WebElement optionsClick = findElement(By.xpath("//a[@href=\"#toptions\"]")); + optionsClick.click(); + + // Set start date to two month ago + 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 ? + Date twoMonthsAgo = DateUtils.addMonths(new Date(), -2); + String formatTwoMonthsAgo = DateUtil.formatDate(twoMonthsAgo, "dd/MM/yyyy HH:mm"); + startDateElement.sendKeys(formatTwoMonthsAgo); + + // Set end date to one months ago + WebElement endDateElement = findElement(By.name("poll.endDate")); + Assert.assertEquals("input", endDateElement.getTagName()); + Assert.assertTrue(endDateElement.isDisplayed()); + //FIXME ymartel 2012/06/14 : review way to get DAte ? + Date oneMonthAgo = DateUtils.addMonths(new Date(), -1); + String formatOneMonthAgo = DateUtil.formatDate(oneMonthAgo, "dd/MM/yyyy HH:mm"); + endDateElement.sendKeys(formatOneMonthAgo); + + // Submit form + WebElement submit = findElement(By.name("action:save")); + submit.click(); + + // No choices, should stay on create poll page + Assert.assertTrue(driver.getCurrentUrl().startsWith(fixtures.createPollURL())); + + // Check an error message has been displayed + WebElement dateError = findElement(By.className("errorMessage")); + Assert.assertNotNull(dateError); + + // Go on general tab and check that Title and and choice fields values are not lost + WebElement generalClick = findElement(By.xpath("//a[@href=\"#tgeneral\"]")); + generalClick.click(); + + titleElement = findElement(By.name("poll.title")); + Assert.assertTrue(titleElement.isDisplayed()); + Assert.assertEquals(pollTitle, titleElement.getAttribute("value")); + + choiceOneElement = findElement(By.name("textChoice_0.name")); + Assert.assertTrue(choiceOneElement.isDisplayed()); + Assert.assertEquals(choiceOne, choiceOneElement.getAttribute("value")); + + } + + /** + * This test create a free text poll with an invalid email. + * When submit, an error text should be displayed : email should be valid + * + * @throws Exception + */ + @Test + public void createFreeTextPollWithInvalidEmail() throws Exception { + + // Go on create poll 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 Poll"; + titleElement.sendKeys(pollTitle); + + // Set first choice + WebElement choiceOneElement = findElement(By.name("textChoice_0.name")); + Assert.assertEquals("input", choiceOneElement.getTagName()); + Assert.assertTrue(choiceOneElement.isDisplayed()); + String choiceOne = "Choix numero un"; + choiceOneElement.sendKeys(choiceOne); + + // Go to option panel : click on it + WebElement optionsClick = findElement(By.xpath("//a[@href=\"#toptions\"]")); + optionsClick.click(); + + WebElement emailElement = findElement(By.name("poll.creator.email")); + Assert.assertEquals("input", emailElement.getTagName()); + Assert.assertTrue(emailElement.isDisplayed()); + emailElement.sendKeys("i@minvalid"); + + // Submit form + WebElement submit = findElement(By.name("action:save")); + submit.click(); + + // No choices, should stay on create poll page + Assert.assertTrue(driver.getCurrentUrl().startsWith(fixtures.createPollURL())); + + // Check an error message has been displayed + WebElement dateError = findElement(By.className("errorMessage")); + Assert.assertNotNull(dateError); + + // Go on general tab and check that Title and and choice fields values are not lost + WebElement generalClick = findElement(By.xpath("//a[@href=\"#tgeneral\"]")); + generalClick.click(); + + titleElement = findElement(By.name("poll.title")); + Assert.assertTrue(titleElement.isDisplayed()); + Assert.assertEquals(pollTitle, titleElement.getAttribute("value")); + + choiceOneElement = findElement(By.name("textChoice_0.name")); + Assert.assertTrue(choiceOneElement.isDisplayed()); + Assert.assertEquals(choiceOne, choiceOneElement.getAttribute("value")); + + } + } Modified: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/PollenBaseWebDriverIT.java =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/PollenBaseWebDriverIT.java 2012-06-13 17:50:09 UTC (rev 3475) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/PollenBaseWebDriverIT.java 2012-06-14 16:16:34 UTC (rev 3476) @@ -171,7 +171,7 @@ if (safeDrivers == null) { List<Class<? extends WebDriver>> allDrivers = Lists.newArrayList(); - allDrivers.add(HtmlUnitDriver.class); +// allDrivers.add(HtmlUnitDriver.class); allDrivers.add(FirefoxDriver.class); // allDrivers.add(ChromeDriver.class); // allDrivers.add(InternetExplorerDriver.class); @@ -289,6 +289,11 @@ } } + + if (HtmlUnitDriver.class == driverType) { + result = new HtmlUnitDriver(); + ((HtmlUnitDriver) result).setJavascriptEnabled(true); + } return result; } } Modified: trunk/pollen-ui-struts2/src/test/resources/pollendb.h2.db =================================================================== (Binary files differ)
participants (1)
-
ymartel@users.chorem.org