Author: cjdelisle
Date: 2010-04-27 08:45:23 +0200 (Tue, 27 Apr 2010)
New Revision: 28628
Added:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/RegisterTest.java
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/RegisterTestAdminAddUser.java
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/RegisterTestNoLiveValidation.java
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/AdminSectionPage.java
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/FormPage.java
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/LightBoxRegisterPage.java
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/UsersPage.java
Modified:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/AdministrationPage.java
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/BasePage.java
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/RegisterPage.java
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/ViewPage.java
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/framework/AbstractTest.java
Log:
XAADMINISTRATION-134: Users->add new user not using XWiki.Registration
with field validation.Added testing. Also duplicated selenium1.0 tests
for registeration.
Maybe we should delete original selenium 1.0 test when they are replaced. This way we know
how much migration remains to do.
WDYT ?
Jerome.
Also added some testing infrastructure.
Added:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/RegisterTest.java
===================================================================
---
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/RegisterTest.java
(rev 0)
+++
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/RegisterTest.java
2010-04-27 06:45:23 UTC (rev 28628)
@@ -0,0 +1,175 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.xwiki.it.ui;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriverException;
+
+import org.xwiki.it.ui.elements.RegisterPage;
+import org.xwiki.it.ui.elements.ViewPage;
+import org.xwiki.it.ui.elements.HomePage;
+import org.xwiki.it.ui.elements.LoginPage;
+import org.xwiki.it.ui.elements.AdministrationPage;
+import org.xwiki.it.ui.elements.AdminSectionPage;
+import org.xwiki.it.ui.framework.AbstractTest;
+import org.xwiki.it.ui.framework.TestUtils;
+
+/**
+ * Test the user registration feature.
+ *
+ * @version $Id$
+ * @since 2.3M1
+ */
+public class RegisterTest extends AbstractTest
+{
+ protected RegisterPage registerPage;
+
+ @Before
+ public void setUp()
+ {
+ registerPage = getRegisterPage();
+
+ deleteUser("JohnSmith");
+ registerPage.gotoRegisterPage();
+
+ // Switch LiveValidation on or off as needed.
+ int x = 0;
+ while (registerPage.liveValidationEnabled() !=
useLiveValidation()) {
+ HomePage homePage = new HomePage(getDriver());
+ homePage.gotoHomePage();
+ homePage.loginAsAdmin();
+ AdministrationPage adminPage =
homePage.administorWiki();
+ AdminSectionPage registrationAdminSection =
adminPage.clickRegistrationSection();
+
registrationAdminSection.getForm().setFieldValue(By.name("XWiki.Registration_1_liveValidation_enabled"),
+
Boolean.valueOf(useLiveValidation()).toString());
+ registrationAdminSection.clickSave();
+ if (x > 2) {
+ throw new WebDriverException("Unable to set
useLiveValidation to " + useLiveValidation());
+ }
+ x++;
+ registerPage.gotoRegisterPage();
+ }
+ registerPage.fillInJohnSmithValues();
+ }
+
+ /** To put the registration page someplace else, subclass this
class and change this method. */
+ protected RegisterPage getRegisterPage()
+ {
+ return new RegisterPage(getDriver());
+ }
+
+ /** To test without javascript validation, subclass this class
and change this method. */
+ protected boolean useLiveValidation()
+ {
+ return true;
+ }
+
+ @Test
+ public void testRegisterJohnSmith()
+ {
+ Assert.assertTrue(validateAndRegister());
+ tryToLogin("JohnSmith", "WeakPassword");
+ }
+
+ @Test
+ public void testRegisterExistingUser()
+ {
+ registerPage.fillRegisterForm(null, null, "Admin", null,
null, null);
+ // Can't use validateAndRegister here because user existance
is not checked by LiveValidation.
+ Assert.assertFalse(registerPage.register());
+
Assert.assertTrue(registerPage.validationFailureMessagesInclude("User
already exists."));
+ }
+
+ @Test
+ public void testRegisterPasswordTooShort()
+ {
+ registerPage.fillRegisterForm(null, null, null, "short",
"short", null);
+ Assert.assertFalse(validateAndRegister());
+
Assert.assertTrue(registerPage.validationFailureMessagesInclude("Please
use a longer password."));
+ }
+
+ @Test
+ public void testRegisterDifferentPasswords()
+ {
+ registerPage.fillRegisterForm(null, null, null, null,
"DifferentPassword", null);
+ Assert.assertFalse(validateAndRegister());
+
Assert.assertTrue(registerPage.validationFailureMessagesInclude("Your
passwords aren't the same."));
+ }
+
+ @Test
+ public void testRegisterEmptyPassword()
+ {
+ registerPage.fillRegisterForm(null, null, null, "", "",
null);
+ Assert.assertFalse(validateAndRegister());
+
Assert.assertTrue(registerPage.validationFailureMessagesInclude("This
field is mandatory."));
+ }
+
+ @Test
+ public void testRegisterInvalidEmail()
+ {
+ registerPage.fillRegisterForm(null, null, null, null, null,
"not an email address");
+ Assert.assertFalse(validateAndRegister());
+
Assert.assertTrue(registerPage.validationFailureMessagesInclude("Please
give a valid email address."));
+ }
+
+ /**
+ * If LiveValidation is enabled then it will check that there are
no failures with that.
+ * If no failures then hits register button, it then asserts that
hitting thr register
+ * button did not reveal any failures not caught by
LiveValidation.
+ *
+ * If LiveValidation is disabled then just hits the register
button.
+ */
+ protected boolean validateAndRegister()
+ {
+ if (useLiveValidation()) {
+ registerPage.triggerLiveValidation();
+ if
(!registerPage.getValidationFailureMessages().isEmpty()) {
+ return false;
+ }
+ boolean result = registerPage.register();
+
Assert.assertTrue(registerPage.getValidationFailureMessages().isEmpty());
+ return result;
+ }
+ return registerPage.register();
+ }
+
+ /** Deletes specified user if it exists, leaves the driver on
undefined page. */
+ private void deleteUser(String userName)
+ {
+ ViewPage vp = new ViewPage(getDriver());
+ TestUtils.gotoPage("XWiki", userName, getDriver());
+ if (vp.exists()) {
+ vp.loginAsAdmin();
+ TestUtils.deletePage("XWiki", userName, getDriver());
+ vp.clickLogout();
+ }
+ }
+
+ protected void tryToLogin(String username, String password)
+ {
+ LoginPage loginPage = registerPage.clickLogin();
+ loginPage.loginAs(username, password);
+ Assert.assertTrue(registerPage.isAuthenticated());
+ }
+}
Property changes on:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/RegisterTest.java
___________________________________________________________________
Name: svn:keywords
+ Author Id Revision HeadURL
Name: svn:eol-style
+ native
Added:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/RegisterTestAdminAddUser.java
===================================================================
---
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/RegisterTestAdminAddUser.java
(rev 0)
+++
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/RegisterTestAdminAddUser.java
2010-04-27 06:45:23 UTC (rev 28628)
@@ -0,0 +1,54 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.xwiki.it.ui;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.xwiki.it.ui.elements.RegisterPage;
+import org.xwiki.it.ui.elements.HomePage;
+import org.xwiki.it.ui.elements.LoginPage;
+import org.xwiki.it.ui.elements.AdministrationPage;
+import org.xwiki.it.ui.elements.UsersPage;
+import org.xwiki.it.ui.elements.LightBoxRegisterPage;
+
+/**
+ * Test the Admin->Users->AddNewUser feature.
+ *
+ * @version $Id$
+ * @since 2.4M1
+ */
+public class RegisterTestAdminAddUser extends RegisterTest
+{
+ protected RegisterPage getRegisterPage()
+ {
+ return new LightBoxRegisterPage(getDriver());
+ }
+
+ protected void tryToLogin(String username, String password)
+ {
+ HomePage homePage = new HomePage(getDriver());
+ homePage.gotoHomePage();
+ homePage.clickLogout();
+ LoginPage loginPage = homePage.clickLogin();
+ loginPage.loginAs(username, password);
+ Assert.assertTrue(registerPage.isAuthenticated());
+ }
+}
Property changes on:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/RegisterTestAdminAddUser.java
___________________________________________________________________
Name: svn:keywords
+ Author Id Revision HeadURL
Name: svn:eol-style
+ native
Added:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/RegisterTestNoLiveValidation.java
===================================================================
---
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/RegisterTestNoLiveValidation.java
(rev 0)
+++
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/RegisterTestNoLiveValidation.java
2010-04-27 06:45:23 UTC (rev 28628)
@@ -0,0 +1,34 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.xwiki.it.ui;
+
+/**
+ * Test the user registration feature without javascript field
validation.
+ *
+ * @version $Id$
+ * @since 2.4M1
+ */
+public class RegisterTestNoLiveValidation extends RegisterTest
+{
+ protected boolean useLiveValidation()
+ {
+ return false;
+ }
+}
Property changes on:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/RegisterTestNoLiveValidation.java
___________________________________________________________________
Name: svn:keywords
+ Author Id Revision HeadURL
Name: svn:eol-style
+ native
Added:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/AdminSectionPage.java
===================================================================
---
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/AdminSectionPage.java
(rev 0)
+++
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/AdminSectionPage.java
2010-04-27 06:45:23 UTC (rev 28628)
@@ -0,0 +1,65 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.xwiki.it.ui.elements;
+
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.FindBy;
+import org.xwiki.it.ui.framework.TestUtils;
+
+/**
+ * Represents the actions possible on the main Administration Page.
+ *
+ * @version $Id$
+ * @since 2.3M1
+ */
+public class AdminSectionPage extends AdministrationPage
+{
+ @FindBy(xpath =
"//div[@id='admin-page-content']/div/p/span/input[@type='submit']")
+ private WebElement saveButton;
+
+ // The admin-page-content div is being treated as a form since it
may contain multiple forms and we want to be able
+ // to access elements in them all.
+ @FindBy(xpath = "//div[@id='admin-page-content']")
+ private WebElement formElement;
+
+ private FormPage form;
+
+ public AdminSectionPage(WebDriver driver)
+ {
+ super(driver);
+ this.form = new FormPage(formElement, driver);
+ }
+
+ public void gotoAdministrationPage()
+ {
+ TestUtils.gotoPage("XWiki", "XWikiPreferences",
"admin",
getDriver());
+ }
+
+ public void clickSave()
+ {
+ saveButton.click();
+ }
+
+ public FormPage getForm()
+ {
+ return form;
+ }
+}
Property changes on:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/AdminSectionPage.java
___________________________________________________________________
Name: svn:keywords
+ Author Id Revision HeadURL
Name: svn:eol-style
+ native
Modified:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/AdministrationPage.java
===================================================================
---
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/AdministrationPage.java
2010-04-26 15:17:30 UTC (rev 28627)
+++
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/AdministrationPage.java
2010-04-27 06:45:23 UTC (rev 28628)
@@ -35,6 +35,12 @@
@FindBy(xpath = "//li[@class='Import']/a/span/img")
WebElement importLink;
+ @FindBy(xpath = "//li[@class='Registration']/a/span/img")
+ WebElement registrationLink;
+
+ @FindBy(xpath = "//li[@class='Users']/a/span/img")
+ WebElement usersLink;
+
public AdministrationPage(WebDriver driver)
{
super(driver);
@@ -51,4 +57,15 @@
return new ImportPage(getDriver());
}
+ public AdminSectionPage clickRegistrationSection()
+ {
+ this.registrationLink.click();
+ return new AdminSectionPage(getDriver());
+ }
+
+ public UsersPage clickUsersSection()
+ {
+ this.usersLink.click();
+ return new UsersPage(getDriver());
+ }
}
Modified:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/BasePage.java
===================================================================
---
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/BasePage.java
2010-04-26 15:17:30 UTC (rev 28627)
+++
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/BasePage.java
2010-04-27 06:45:23 UTC (rev 28628)
@@ -70,21 +70,74 @@
{
return getDriver().findElement(By.xpath("//meta[@name='" +
metaName + "']")).getAttribute("content");
}
-
+
+ /**
+ * Wait until the element given by the locator is displayed. Give
up after 10 seconds.
+ *
+ * @param locator the locator for the element to look for.
+ */
public void waitUntilElementIsVisible(final By locator)
{
this.waitUntilElementIsVisible(locator, 10);
}
+ /**
+ * Wait until the element given by the locator is displayed.
+ *
+ * @param locator the locator for the element to look for.
+ * @param timeout how long to wait in seconds before giving up.
+ */
public void waitUntilElementIsVisible(final By locator, int
timeout)
{
+ waitUntilElementsAreVisible(new By[] {locator}, timeout,
true);
+ }
+
+ /**
+ * Wait until one or all of a array of element locators are
displayed.
+ *
+ * @param locators the array of element locators to look for.
+ * @param all if true then don't return until all elements are
found. Otherwise return after finding one.
+ */
+ public void waitUntilElementsAreVisible(final By[] locators,
final boolean all)
+ {
+ waitUntilElementsAreVisible(locators, 10, all);
+ }
+
+ /**
+ * Wait until one or all of a array of element locators are
displayed.
+ *
+ * @param locators the array of element locators to look for.
+ * @param timeout how long to wait in seconds before giving up.
+ * @param all if true then don't return until all elements are
found. Otherwise return after finding one.
+ */
+ public void waitUntilElementsAreVisible(final By[] locators, int
timeout, final boolean all)
+ {
Wait<WebDriver> wait = new WebDriverWait(driver, timeout);
wait.until(new ExpectedCondition<WebElement>()
{
public WebElement apply(WebDriver driver)
{
- RenderedWebElement element = (RenderedWebElement)
driver.findElement(locator);
- return element.isDisplayed() ? element : null;
+ RenderedWebElement element = null;
+ for (int i = 0; i < locators.length; i++) {
+ try {
+ element = (RenderedWebElement)
driver.findElement(locators[i]);
+ } catch (NotFoundException e) {
+ // This exception is caught by WebDriverWait
+ // but it returns null which is not
necessarily what we want.
+ if (all) {
+ return null;
+ }
+ continue;
+ }
+ if (element.isDisplayed()) {
+ if (!all) {
+ return element;
+ }
+ } else if (all) {
+ return null;
+ }
+ }
+ return element;
}
});
}
Added:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/FormPage.java
===================================================================
---
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/FormPage.java
(rev 0)
+++
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/FormPage.java
2010-04-27 06:45:23 UTC (rev 28628)
@@ -0,0 +1,96 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.xwiki.it.ui.elements;
+
+import java.util.Map;
+import java.util.HashMap;
+
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.NoSuchElementException;
+import org.openqa.selenium.WebDriverException;
+import org.openqa.selenium.By;
+
+/**
+ * Represents a Form.
+ *
+ * @version $Id:$
+ * @since 2.4M1
+ */
+public class FormPage extends BasePage
+{
+ private final WebElement form;
+
+ public FormPage(WebElement form, WebDriver driver)
+ {
+ super(driver);
+ this.form = form;
+ }
+
+ public void fillFieldsByName(Map<String, String> valuesByNames)
+ {
+ Map valuesByElements = new HashMap<WebElement, String>((int)
(valuesByNames.size() / 0.75));
+
+ for (String name : valuesByNames.keySet()) {
+
valuesByElements.put(this.form.findElement(By.name(name)),
valuesByNames.get(name));
+ }
+ fillFieldsByElements(valuesByElements);
+ }
+
+
+ public void fillFieldsByElements(Map<WebElement, String>
valuesByElements)
+ {
+ for (WebElement el : valuesByElements.keySet()) {
+ setFieldValue(el, valuesByElements.get(el));
+ }
+ }
+
+ public void setFieldValue(By findElementBy, String value)
+ {
+ setFieldValue(this.form.findElement(findElementBy), value);
+ }
+
+ public void setFieldValue(WebElement fieldElement, String value)
+ {
+ if (!fieldElement.getTagName().equals("input") &&
!fieldElement.getTagName().equals("textbox")) {
+ throw new WebDriverException("You can only fill in input
and textbox elements.");
+ }
+ if (fieldElement.getAttribute("type").equals("checkbox")) {
+ setCheckBox(fieldElement, value.equals("true"));
+ } else {
+ fieldElement.clear();
+ fieldElement.sendKeys(value);
+ }
+ }
+
+ public void setCheckBox(WebElement checkBoxElement, boolean
checked)
+ {
+ int x = 0;
+ while (checkBoxElement.isSelected() != checked) {
+ checkBoxElement.toggle();
+ if (x == 100) {
+ throw new WebDriverException("Unable to set checkbox
at "
+ +
checkBoxElement.getAttribute("name") + " to " + checked);
+ }
+ x++;
+ }
+
+ }
+}
Property changes on:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/FormPage.java
___________________________________________________________________
Name: svn:keywords
+ Author Id Revision HeadURL
Name: svn:eol-style
+ native
Added:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/LightBoxRegisterPage.java
===================================================================
---
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/LightBoxRegisterPage.java
(rev 0)
+++
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/LightBoxRegisterPage.java
2010-04-27 06:45:23 UTC (rev 28628)
@@ -0,0 +1,81 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.xwiki.it.ui.elements;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import org.openqa.selenium.support.FindBy;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.WebDriver;
+
+/**
+ * Represents a registertion page in a lightbox
+ *
+ * @version $Id$
+ * @since 2.3M1
+ */
+public class LightBoxRegisterPage extends RegisterPage
+{
+ @FindBy(xpath =
"//div/form[@id='register']/div/span[1]/input[@value='Save']")
+ private WebElement submitButton;
+
+ public LightBoxRegisterPage(WebDriver driver)
+ {
+ super(driver);
+ }
+
+ public void gotoRegisterPage()
+ {
+ HomePage homePage = new HomePage(getDriver());
+ homePage.gotoHomePage();
+
+ homePage.loginAsAdmin();
+ AdministrationPage adminPage = homePage.administorWiki();
+ UsersPage usersPage = adminPage.clickUsersSection();
+
+ usersPage.clickAddNewUser();
+ waitUntilElementIsVisible(By.id("register_first_name"));
+ }
+
+ /** @return true if registration is successful, false if user
couldn't be registered. */
+ public boolean register()
+ {
+ submitButton.click();
+
+ waitUntilElementsAreVisible(
+ new By[]
{By.xpath("//td[@class='username']/a[@href='/xwiki/bin/view/XWiki/JohnSmith']"),
+
By.xpath("//dd/span[@class='LV_validation_message LV_invalid']")
+ },
+ false
+ );
+
+ return !getDriver()
+ .findElements(
+
By.xpath("//td[@class='username']/a[@href='/xwiki/bin/view/XWiki/JohnSmith']"))
+ .isEmpty();
+ }
+
+ public boolean liveValidationEnabled()
+ {
+ return
!getDriver().findElements(By.xpath("//div[@id='lb']/div[@id='lb-content']/script[3]")).isEmpty();
+ }
+}
Property changes on:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/LightBoxRegisterPage.java
___________________________________________________________________
Name: svn:keywords
+ Author Id Revision HeadURL
Name: svn:eol-style
+ native
Modified:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/RegisterPage.java
===================================================================
---
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/RegisterPage.java
2010-04-26 15:17:30 UTC (rev 28627)
+++
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/RegisterPage.java
2010-04-27 06:45:23 UTC (rev 28628)
@@ -19,8 +19,18 @@
*/
package org.xwiki.it.ui.elements;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+
+import org.openqa.selenium.support.FindBy;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebDriverException;
+import org.xwiki.it.ui.framework.TestUtils;
+
/**
* Represents the actions possible on the Registration Page
*
@@ -29,8 +39,133 @@
*/
public class RegisterPage extends ViewPage
{
+ @FindBy(id = "register")
+ private WebElement registerFormElement;
+
+ @FindBy(xpath =
"//form[@id='register']/div/span/input[@type='submit']")
+ private WebElement submitButton;
+
+ private FormPage form;
+
public RegisterPage(WebDriver driver)
{
super(driver);
}
+
+ /** To put the registration page someplace else, subclass this
class and change this method. */
+ public boolean isOnRegisterPage()
+ {
+ if (registerFormElement != null &&
!getDriver().findElements(By.name("register_password")).isEmpty()) {
+ if (form == null) {
+ form = new FormPage(registerFormElement,
getDriver());
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /** To put the registration page someplace else, subclass this
class and change this method. */
+ public void gotoRegisterPage()
+ {
+ HomePage homePage = new HomePage(getDriver());
+ homePage.gotoHomePage();
+
+ if (homePage.isAuthenticated()) {
+ homePage.clickLogout();
+ }
+
+ homePage.clickRegister();
+ form = new FormPage(registerFormElement, getDriver());
+ }
+
+ public void fillInJohnSmithValues()
+ {
+ fillRegisterForm("John", "Smith", "JohnSmith",
"WeakPassword", "WeakPassword", "johnsmith(a)xwiki.org")org");
+ }
+
+ public void fillRegisterForm(final String firstName,
+ final String lastName,
+ final String username,
+ final String password,
+ final String confirmPassword,
+ final String email)
+ {
+ checkAtRegisterPage();
+ Map map = new HashMap();
+ if (firstName != null) {
+ map.put("register_first_name", firstName);
+ }
+ if (lastName != null) {
+ map.put("register_last_name", lastName);
+ }
+ if (username != null) {
+ map.put("xwikiname", username);
+ }
+ if (password != null) {
+ map.put("register_password", password);
+ }
+ if (confirmPassword != null) {
+ map.put("register2_password", confirmPassword);
+ }
+ if (email != null) {
+ map.put("register_email", email);
+ }
+ form.fillFieldsByName(map);
+ }
+
+ /** @return true if registration is successful, false if user
couldn't be registered. */
+ public boolean register()
+ {
+ checkAtRegisterPage();
+ submitButton.click();
+
+ List<WebElement> infos =
getDriver().findElements(By.className("infomessage"));
+ for (WebElement info : infos) {
+ if (info.getText().indexOf("Registration successful.") !=
-1) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /** @return a list of WebElements representing validation failure
messages. Use after calling register() */
+ public List<WebElement> getValidationFailureMessages()
+ {
+ return
getDriver().findElements(By.xpath("//dd/span[@class='LV_validation_message
LV_invalid']"));
+ }
+
+ /** @return Is the specified message included in the list of
validation failure messages. */
+ public boolean validationFailureMessagesInclude(String message)
+ {
+ for (WebElement messageElement :
getValidationFailureMessages()) {
+ if (messageElement.getText().equals(message)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean liveValidationEnabled()
+ {
+ return
!getDriver().findElements(By.xpath("/html/body/div/div/div[3]/div/div/div/div/div/script")).isEmpty();
+ }
+
+ /** Try to make LiveValidation validate the forms. Focus on an
unvalidated field (register_first_name)*/
+ public void triggerLiveValidation()
+ {
+ // Click on all of the validated fields to prevent "Passwords
don't match" sticking -> flickering test.
+ // The right solution is to have a better way to fire
LiveValidation without excessive js.
+
registerFormElement.findElement(By.name("register2_password")).click();
+
registerFormElement.findElement(By.name("register_password")).click();
+
registerFormElement.findElement(By.name("xwikiname")).click();
+
+
registerFormElement.findElement(By.name("register_first_name")).click();
+ }
+
+ private void checkAtRegisterPage()
+ {
+ if (!isOnRegisterPage()) {
+ throw new WebDriverException("Must go to the registration
page before using it's functions.");
+ }
+ }
}
Added:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/UsersPage.java
===================================================================
---
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/UsersPage.java
(rev 0)
+++
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/UsersPage.java
2010-04-27 06:45:23 UTC (rev 28628)
@@ -0,0 +1,56 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.xwiki.it.ui.elements;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.FindBy;
+
+
+import org.xwiki.it.ui.elements.RegisterPage;
+import org.xwiki.it.ui.elements.BasePage;
+import org.xwiki.it.ui.elements.AdministrationPage;
+
+/**
+ * Test the Admin->Users->AddNewUser feature.
+ *
+ * @version $Id$
+ * @since 2.4M1
+ */
+public class UsersPage extends BasePage
+{
+ @FindBy(id = "addNewUser")
+ private WebElement addNewUserButton;
+
+ public UsersPage(WebDriver driver)
+ {
+ super(driver);
+ }
+
+ public RegisterPage clickAddNewUser()
+ {
+ this.addNewUserButton.click();
+ RegisterPage rp = new LightBoxRegisterPage(getDriver());
+ return rp;
+ }
+}
Property changes on:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/UsersPage.java
___________________________________________________________________
Name: svn:keywords
+ Author Id Revision HeadURL
Name: svn:eol-style
+ native
Modified:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/ViewPage.java
===================================================================
---
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/ViewPage.java
2010-04-26 15:17:30 UTC (rev 28627)
+++
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/elements/ViewPage.java
2010-04-27 06:45:23 UTC (rev 28628)
@@ -19,6 +19,8 @@
*/
package org.xwiki.it.ui.elements;
+import java.util.List;
+
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
@@ -52,6 +54,9 @@
@FindBy(id = "tmCreateSpace")
private WebElement createSpaceMenuLink;
+ @FindBy(id= "tmAdminWiki")
+ private WebElement administorWikiMenuLink;
+
public ViewPage(WebDriver driver)
{
super(driver);
@@ -63,12 +68,16 @@
public void loginAsAdmin()
{
if (!isAuthenticated()) {
- // If there's no login link then go to the home page
+ // If there's no login link then go to the home page.
if (!hasLoginLink()) {
+ String thisPage = getPageURL();
HomePage homePage = new HomePage(getDriver());
homePage.gotoHomePage();
+ clickLogin().loginAsAdmin();
+ getDriver().get(thisPage);
+ } else {
+ clickLogin().loginAsAdmin();
}
- clickLogin().loginAsAdmin();
}
}
@@ -122,6 +131,13 @@
return new CreateSpacePage(getDriver());
}
+ public AdministrationPage administorWiki()
+ {
+ hoverOverMenu("tmWiki");
+ this.administorWikiMenuLink.click();
+ return new AdministrationPage(getDriver());
+ }
+
// TODO: I don't think we should go through the menus, it's
probably faster to to as deletePage() does
public void deleteCurrentPage()
{
@@ -142,6 +158,19 @@
return new HistoryPane(getDriver());
}
+
+ /** @return does this page exist. */
+ public boolean exists()
+ {
+ List<WebElement> messages =
getDriver().findElements(By.className("xwikimessage"));
+ for (WebElement message : messages) {
+ if (message.getText().equals("The requested document
could not be found.")
+ || message.getText().equals("The document has been
deleted.")) {
+ return false;
+ }
+ }
+ return true;
+ }
private void hoverOverMenu(String menuId)
{
Modified:
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/framework/AbstractTest.java
===================================================================
---
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/framework/AbstractTest.java
2010-04-26 15:17:30 UTC (rev 28627)
+++
enterprise/trunk/distribution-test/ui-tests/src/test/it/org/xwiki/it/ui/framework/AbstractTest.java
2010-04-27 06:45:23 UTC (rev 28628)
@@ -22,6 +22,7 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.openqa.selenium.WebDriver;
+import org.xwiki.test.XWikiExecutor;
/**
* To be extended by all Test Classes. Allows to start/stop the Web
Driver and get access to it.
@@ -31,20 +32,30 @@
*/
public class AbstractTest
{
+ private static XWikiExecutor executor;
+
@BeforeClass
- public static void init()
+ public static void init() throws Exception
{
+ if
(!Boolean.parseBoolean(System.getProperty("xwiki.alltests"))) {
+ // Start XE
+ executor = new XWikiExecutor(0);
+ executor.start();
+ }
+
if (TestUtils.getDriver() == null) {
TestUtils.initDriver();
}
}
@AfterClass
- public static void shutdown()
+ public static void shutdown() throws Exception
{
// Only close if we're not part of the AllTests test suite
if
(!Boolean.parseBoolean(System.getProperty("xwiki.alltests"))) {
TestUtils.closeDriver();
+ // Stop XE
+ executor.stop();
}
}
_______________________________________________
notifications mailing list
notifications(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/notifications