Author: ymartel Date: 2012-06-18 14:44:50 +0200 (Mon, 18 Jun 2012) New Revision: 3514 Url: http://chorem.org/repositories/revision/pollen/3514 Log: refs #606 : add ITs for text restricted poll Added: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateRestrictedTextPollSIT.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/PollenBaseWebDriverIT.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 11:38:22 UTC (rev 3513) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenFixtures.java 2012-06-18 12:44:50 UTC (rev 3514) @@ -162,4 +162,5 @@ 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/CreateRestrictedTextPollSIT.java =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateRestrictedTextPollSIT.java (rev 0) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/CreateRestrictedTextPollSIT.java 2012-06-18 12:44:50 UTC (rev 3514) @@ -0,0 +1,320 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $Id: CreateFreeTextPollSIT.java 3507 2012-06-18 09:45:47Z 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 text poll creation page with a restricted list of participant. + * <p/> + * Tested cases : + * <ul> + * <li>Creation without participant (KO)</li> + * <li>Creation with two participants with same name (KO)</li> + * <li>Creation with two participants with same email (KO)</li> + * <li>Creation with a participant without email (KO)</li> + * <li>Creation with a participant with only an email (no name) (KO)</li> + * </ul> + * + * @author ymartel <martel@codelutin.com> + * @since 1.4 + */ +public class CreateRestrictedTextPollSIT extends PollenBaseWebDriverIT { + + public CreateRestrictedTextPollSIT(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 createRestrictedTextPollWithoutParticipant() throws Exception { + + // Prepare the poll + preparePoll(); + + // Go to option panel : click on it + WebElement optionsClick = findElement(By.xpath("//a[@href=\"#toptions\"]")); + optionsClick.click(); + + // Switch to restricted type + List<WebElement> pollTypesElement = findElements(By.name("poll.pollType")); + Assert.assertEquals(3, pollTypesElement.size()); + WebElement restrictedTypeElement = pollTypesElement.get(1); + Assert.assertEquals("input", restrictedTypeElement.getTagName()); + Assert.assertEquals("RESTRICTED", restrictedTypeElement.getAttribute("value")); + Assert.assertTrue(restrictedTypeElement.isDisplayed()); + restrictedTypeElement.click(); + + // Check that the participant form is displayed + WebElement participantOneNameElement = findElement(By.id("votingListRESTRICTED_0PersonToList_0.votingId")); + Assert.assertEquals("input", participantOneNameElement.getTagName()); + Assert.assertTrue(participantOneNameElement.isDisplayed()); + + // Submit form + WebElement submit = findElement(By.name("action:create")); + submit.click(); + + // All good, should be on summary page ! + checkCurrentUrl(fixtures.createPollURL(), false); + // Check an error message has been displayed + WebElement errorMessage = findElement(By.className("errorMessage")); + Assert.assertNotNull(errorMessage); + // Check we are in good table + participantOneNameElement = findElement(By.id("votingListRESTRICTED_0PersonToList_0.votingId")); + Assert.assertEquals("input", participantOneNameElement.getTagName()); + Assert.assertTrue(participantOneNameElement.isDisplayed()); + } + + /** + * This test create a restricted text poll, with two participant with same name. + * At the end, should stay on create poll page, cause the name should be unique. + * + * @throws Exception + */ + @Test + public void createRestrictedTextPollWithParticipantsWithSameName() throws Exception { + + // Prepare the poll + preparePoll(); + + // Go to option panel : click on it + WebElement optionsClick = findElement(By.xpath("//a[@href=\"#toptions\"]")); + optionsClick.click(); + + // Switch to restricted type + List<WebElement> pollTypesElement = findElements(By.name("poll.pollType")); + Assert.assertEquals(3, pollTypesElement.size()); + WebElement restrictedTypeElement = pollTypesElement.get(1); + Assert.assertEquals("input", restrictedTypeElement.getTagName()); + Assert.assertEquals("RESTRICTED", restrictedTypeElement.getAttribute("value")); + Assert.assertTrue(restrictedTypeElement.isDisplayed()); + restrictedTypeElement.click(); + + // Set first participant + // send name + String participantOneName = "toto"; + sendKeysById("votingListRESTRICTED_0PersonToList_0.votingId", participantOneName); + // send email + String participantOneEmail = "toto@codelutin.com"; + sendKeysById("votingListRESTRICTED_0PersonToList_0.email", participantOneEmail); + // Set second participant + // send name + sendKeysById("votingListRESTRICTED_0PersonToList_1.votingId", participantOneName); + // send email + String participantTwoEmail = "toto2@codelutin.com"; + sendKeysById("votingListRESTRICTED_0PersonToList_1.email", participantTwoEmail); + + // Submit form + WebElement submit = findElement(By.name("action:create")); + submit.click(); + + // All good, should be on summary page ! + checkCurrentUrl(fixtures.createPollURL(), false); + // Check an error message has been displayed + WebElement errorMessage = findElement(By.className("errorMessage")); + Assert.assertNotNull(errorMessage); + // Check we are in good table + checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_0.votingId"), participantOneName); + checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_0.email"), participantOneEmail); + checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_1.votingId"), participantOneName); + checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_1.email"), participantTwoEmail); + } + + /** + * This test create a restricted text poll, with two participant with same email. + * At the end, should stay on create poll page, cause the email should be unique. + * + * @throws Exception + */ + @Test + public void createRestrictedTextPollWithParticipantsWithSameEmail() throws Exception { + + // Prepare the poll + preparePoll(); + + // Go to option panel : click on it + WebElement optionsClick = findElement(By.xpath("//a[@href=\"#toptions\"]")); + optionsClick.click(); + + // Switch to restricted type + List<WebElement> pollTypesElement = findElements(By.name("poll.pollType")); + Assert.assertEquals(3, pollTypesElement.size()); + WebElement restrictedTypeElement = pollTypesElement.get(1); + Assert.assertEquals("input", restrictedTypeElement.getTagName()); + Assert.assertEquals("RESTRICTED", restrictedTypeElement.getAttribute("value")); + Assert.assertTrue(restrictedTypeElement.isDisplayed()); + restrictedTypeElement.click(); + + // Set first participant + // send name + String participantOneName = "toto"; + sendKeysById("votingListRESTRICTED_0PersonToList_0.votingId", participantOneName); + // send email + String participantOneEmail = "toto@codelutin.com"; + sendKeysById("votingListRESTRICTED_0PersonToList_0.email", participantOneEmail); + // Set second participant + // send name + String participantTwoName = "toto2"; + sendKeysById("votingListRESTRICTED_0PersonToList_1.votingId", participantTwoName); + // send email + sendKeysById("votingListRESTRICTED_0PersonToList_1.email", participantOneEmail); + + // Submit form + WebElement submit = findElement(By.name("action:create")); + submit.click(); + + // All good, should be on summary page ! + checkCurrentUrl(fixtures.createPollURL(), false); + // Check an error message has been displayed + WebElement errorMessage = findElement(By.className("errorMessage")); + Assert.assertNotNull(errorMessage); + // Check we are in good table + checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_0.votingId"), participantOneName); + checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_0.email"), participantOneEmail); + checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_1.votingId"), participantTwoName); + checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_1.email"), participantOneEmail); + } + + /** + * This test create a restricted text poll, with one participant without email. + * At the end, should stay on create poll page, cause the mail is mandatory. + * + * @throws Exception + */ + @Test + public void createRestrictedTextPollWithParticipantWithoutMail() throws Exception { + + // Prepare the poll + preparePoll(); + + // Go to option panel : click on it + WebElement optionsClick = findElement(By.xpath("//a[@href=\"#toptions\"]")); + optionsClick.click(); + + // Switch to restricted type + List<WebElement> pollTypesElement = findElements(By.name("poll.pollType")); + Assert.assertEquals(3, pollTypesElement.size()); + WebElement restrictedTypeElement = pollTypesElement.get(1); + Assert.assertEquals("input", restrictedTypeElement.getTagName()); + Assert.assertEquals("RESTRICTED", restrictedTypeElement.getAttribute("value")); + Assert.assertTrue(restrictedTypeElement.isDisplayed()); + restrictedTypeElement.click(); + + // Set first participant + // send name + String participantOneName = "toto"; + sendKeysById("votingListRESTRICTED_0PersonToList_0.votingId", participantOneName); + // send email + String participantOneEmail = " "; + sendKeysById("votingListRESTRICTED_0PersonToList_0.email", participantOneEmail); + + // Submit form + WebElement submit = findElement(By.name("action:create")); + submit.click(); + + // All good, should be on summary page ! + checkCurrentUrl(fixtures.createPollURL(), false); + // Check an error message has been displayed + WebElement errorMessage = findElement(By.className("errorMessage")); + Assert.assertNotNull(errorMessage); + // Check we are in good table + checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_0.votingId"), participantOneName); + checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_0.email"), participantOneEmail); + } + + /** + * This test create a restricted text poll, with one participant without email. + * At the end, should stay on create poll page, cause the mail is mandatory. + * + * @throws Exception + */ + @Test + public void createRestrictedTextPollWithParticipantWithoutName() throws Exception { + + // Prepare the poll + preparePoll(); + + // Go to option panel : click on it + WebElement optionsClick = findElement(By.xpath("//a[@href=\"#toptions\"]")); + optionsClick.click(); + + // Switch to restricted type + List<WebElement> pollTypesElement = findElements(By.name("poll.pollType")); + Assert.assertEquals(3, pollTypesElement.size()); + WebElement restrictedTypeElement = pollTypesElement.get(1); + Assert.assertEquals("input", restrictedTypeElement.getTagName()); + Assert.assertEquals("RESTRICTED", restrictedTypeElement.getAttribute("value")); + Assert.assertTrue(restrictedTypeElement.isDisplayed()); + restrictedTypeElement.click(); + + // Set first participant + // send name + String participantOneName = ""; + sendKeysById("votingListRESTRICTED_0PersonToList_0.votingId", participantOneName); + // send email + String participantOneEmail = "toto@codelutin.com"; + sendKeysById("votingListRESTRICTED_0PersonToList_0.email", participantOneEmail); + + // Submit form + WebElement submit = findElement(By.name("action:create")); + submit.click(); + + // All good, should be on summary page ! + checkCurrentUrl(fixtures.createPollURL(), false); + // Check an error message has been displayed + WebElement errorMessage = findElement(By.className("errorMessage")); + Assert.assertNotNull(errorMessage); + // Check we are in good table + checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_0.votingId"), participantOneName); + checkWebElementValue(By.id("votingListRESTRICTED_0PersonToList_0.email"), participantOneEmail); + } + + /** + * Prepare the poll with general data : one title and two choices + */ + void preparePoll() { + // Go on home page + gotoUrl(fixtures.createPollURL()); + + // Set title + sendKeysByName("poll.title", "My Poll"); + + // Set first choice + sendKeysByName("textChoice_0.name", "Choix numero un"); + + // Set second choice + sendKeysByName("textChoice_1.name", "Choix numero deux"); + } + +} 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-18 11:38:22 UTC (rev 3513) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/PollenBaseWebDriverIT.java 2012-06-18 12:44:50 UTC (rev 3514) @@ -161,6 +161,67 @@ } /** + * Set a value for a WebElement. + * This operations does 3 steps : + * <ul> + * <li>Get the WebElement thanks to its id (given in parameter)</li> + * <li>check the element is an input</li> + * <li>check the element is displayed</li> + * <li>clear the element</li> + * <li>send the wanted keys</li> + * </ul> + */ + protected void sendKeysById(String webElementId, String value) { + sendKeysBy(By.id(webElementId), value); + } + + /** + * Set a value for a WebElement. + * This operations does 3 steps : + * <ul> + * <li>Get the WebElement thanks to its name (given in parameter)</li> + * <li>check the element is an input</li> + * <li>check the element is displayed</li> + * <li>clear the element</li> + * <li>send the wanted keys</li> + * </ul> + */ + protected void sendKeysByName(String webElementName, String value) { + By byName = By.name(webElementName); + sendKeysBy(byName, value); + } + + /** + * Set a value for a WebElement. + * This operations does 3 steps : + * <ul> + * <li>Get the WebElement thanks to a {@link By} locator</li> + * <li>check the element is an input</li> + * <li>check the element is displayed</li> + * <li>clear the element</li> + * <li>send the wanted keys</li> + * </ul> + */ + protected void sendKeysBy(By by, String value) { + WebElement webElement = findElement(by); + Assert.assertEquals("input", webElement.getTagName()); + Assert.assertTrue(webElement.isDisplayed()); + webElement.sendKeys(value); + Assert.assertEquals(value, webElement.getAttribute("value")); + } + + /** + * Get a WebElement with a {@link By} locator, and check it is an input and that is value is the one expected. + * + */ + protected void checkWebElementValue(By by, String expectedValue) { + WebElement webElement = findElement(by); + Assert.assertEquals("input", webElement.getTagName()); + Assert.assertTrue(webElement.isDisplayed()); + Assert.assertEquals(expectedValue, webElement.getAttribute("value")); + } + + /** * Web driver resource. * * @author tchemit <chemit@codelutin.com> @@ -179,7 +240,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);