[kune-commits] r1396 - in trunk: . src/main/java/cc/kune/core/client/auth src/test/java/cc/kune src/test/java/cc/kune/selenium src/test/java/cc/kune/selenium/login src/test/java/cc/kune/selenium/tools

Vicente J. Ruiz Jurado vjrj_ at ourproject.org
Wed Jun 1 21:01:45 CEST 2011


Author: vjrj_
Date: 2011-06-01 21:01:44 +0200 (Wed, 01 Jun 2011)
New Revision: 1396

Added:
   trunk/src/test/java/cc/kune/selenium/
   trunk/src/test/java/cc/kune/selenium/KuneSeleniumDefaults.java
   trunk/src/test/java/cc/kune/selenium/KuneSeleniumTest.java
   trunk/src/test/java/cc/kune/selenium/PageObject.java
   trunk/src/test/java/cc/kune/selenium/login/
   trunk/src/test/java/cc/kune/selenium/login/LoginPageObject.java
   trunk/src/test/java/cc/kune/selenium/login/LoginSeleniumTests.java
   trunk/src/test/java/cc/kune/selenium/testng.xml
   trunk/src/test/java/cc/kune/selenium/tools/
   trunk/src/test/java/cc/kune/selenium/tools/AbstractWebTester.java
   trunk/src/test/java/cc/kune/selenium/tools/GenericWebTester.java
   trunk/src/test/java/cc/kune/selenium/tools/I18nHelper.java
   trunk/src/test/java/cc/kune/selenium/tools/I18nHelperTest.java
   trunk/src/test/java/cc/kune/selenium/tools/Lorem.java
   trunk/src/test/java/cc/kune/selenium/tools/PageObjectModule.java
   trunk/src/test/java/cc/kune/selenium/tools/SeleniumConstants.java
   trunk/src/test/java/cc/kune/selenium/tools/SeleniumModule.java
Modified:
   trunk/
   trunk/pom.xml
   trunk/src/main/java/cc/kune/core/client/auth/SignInForm.java
Log:
More on selenium tests



Property changes on: trunk
___________________________________________________________________
Name: svn:ignore
   - pmd-eclipse.log
.pmd
www-test
screenlog.0
client
public
target
target-local
Main-compile
.settings
.gwt-cache
repository
derby.log
star-yellow-grey.png
run.sh
tomcat
gwt-out
synccss.sh
.externalToolBuilders
.wtpmodules
www
testRepository
kune-OLD-jcr
KuneApp.launch
KuneApp NOSERVER.launch
old_src
org.ourproject.kune.app.Kune
org.ourproject.kune.iml
org.ourproject.kune.ipr
org.ourproject.kune.iws
nbproject
hibernate.reveng.xml
.gwt-tmp
target-eclipse
.checkstyle
.classpath-bien
pom.xml.*
.gwt
.jdee_sources
.jdee_classpath
prj.el
.factorypath
.apt_generated
target.old
_accounts
_certificates
_deltas
logs

   + pmd-eclipse.log
.pmd
www-test
screenlog.0
client
public
target
target-local
Main-compile
.settings
.gwt-cache
repository
derby.log
star-yellow-grey.png
run.sh
tomcat
gwt-out
synccss.sh
.externalToolBuilders
.wtpmodules
www
testRepository
kune-OLD-jcr
KuneApp.launch
KuneApp NOSERVER.launch
old_src
org.ourproject.kune.app.Kune
org.ourproject.kune.iml
org.ourproject.kune.ipr
org.ourproject.kune.iws
nbproject
hibernate.reveng.xml
.gwt-tmp
target-eclipse
.checkstyle
.classpath-bien
pom.xml.*
.gwt
.jdee_sources
.jdee_classpath
prj.el
.factorypath
.apt_generated
target.old
_accounts
_certificates
_deltas
logs

test-output


Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml	2011-05-15 22:23:33 UTC (rev 1395)
+++ trunk/pom.xml	2011-06-01 19:01:44 UTC (rev 1396)
@@ -507,7 +507,7 @@
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
-      <version>4.8.1</version>
+      <version>4.8.2</version>
       <!-- =roo -->
       <scope>test</scope>
     </dependency>
@@ -522,8 +522,12 @@
         </exclusion>
       </exclusions>
     </dependency>
-    <!-- <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId>
-      <version>5.14</version> <scope>test</scope> </dependency> -->
+    <dependency>
+      <groupId>org.testng</groupId>
+      <artifactId>testng</artifactId>
+      <version>6.0.1</version>
+      <scope>test</scope>
+    </dependency>
     <!-- If you want to start a selenium server, you will need the following
       dependency: -->
     <!-- <dependency> -->
@@ -803,12 +807,21 @@
         <!-- =roo + custom -->
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
-        <version>2.8</version>
+        <version>2.8.1</version>
+        <dependencies>
+          <dependency>
+            <groupId>org.apache.maven.surefire</groupId>
+            <artifactId>surefire-junit47</artifactId>
+            <version>2.8.1</version>
+          </dependency>
+        </dependencies>
         <configuration>
           <excludes>
             <exclude>**/*_Roo_*</exclude>
           </excludes>
           <forkMode>pertest</forkMode>
+          <parallel>methods</parallel>
+          <threadCount>10</threadCount>
           <property>
             <name>junit</name>
             <value>true</value>

Modified: trunk/src/main/java/cc/kune/core/client/auth/SignInForm.java
===================================================================
--- trunk/src/main/java/cc/kune/core/client/auth/SignInForm.java	2011-05-15 22:23:33 UTC (rev 1395)
+++ trunk/src/main/java/cc/kune/core/client/auth/SignInForm.java	2011-06-01 19:01:44 UTC (rev 1396)
@@ -30,8 +30,8 @@
 import com.extjs.gxt.ui.client.widget.form.TextField;
 
 public class SignInForm extends DefaultForm {
-  public static final String NICKOREMAIL_FIELD = "kune-sif-nkf";
-  public static final String PASSWORD_FIELD = "kune-sif-psf";
+  public static final String PASSWORD_FIELD_ID = "kune-sif-psf";
+  public static final String USER_FIELD_ID = "kune-sif-nkf";
 
   private final TextField<String> loginNickOrEmailField;
   private final TextField<String> loginPassField;
@@ -42,22 +42,22 @@
 
     loginNickOrEmailField = new TextField<String>();
     loginNickOrEmailField.setFieldLabel(i18n.t("Username"));
-    loginNickOrEmailField.setName(NICKOREMAIL_FIELD);
+    loginNickOrEmailField.setName(USER_FIELD_ID);
     loginNickOrEmailField.setWidth(DEF_SMALL_FIELD_WIDTH);
     loginNickOrEmailField.setAllowBlank(false);
     loginNickOrEmailField.setValidationDelay(1000);
-    loginNickOrEmailField.setId(NICKOREMAIL_FIELD);
+    loginNickOrEmailField.setId(USER_FIELD_ID);
     loginNickOrEmailField.setTabIndex(100);
     super.add(loginNickOrEmailField);
 
     loginPassField = new TextField<String>();
     loginPassField.setFieldLabel(i18n.t("Password"));
-    loginPassField.setName(PASSWORD_FIELD);
+    loginPassField.setName(PASSWORD_FIELD_ID);
     loginPassField.setWidth(DEF_MEDIUM_FIELD_WIDTH);
     loginPassField.setPassword(true);
     loginPassField.setAllowBlank(false);
     loginPassField.setValidationDelay(1000);
-    loginPassField.setId(PASSWORD_FIELD);
+    loginPassField.setId(PASSWORD_FIELD_ID);
     loginPassField.setTabIndex(101);
     loginPassField.addListener(Events.OnKeyPress, new Listener<FieldEvent>() {
       @Override

Added: trunk/src/test/java/cc/kune/selenium/KuneSeleniumDefaults.java
===================================================================
--- trunk/src/test/java/cc/kune/selenium/KuneSeleniumDefaults.java	                        (rev 0)
+++ trunk/src/test/java/cc/kune/selenium/KuneSeleniumDefaults.java	2011-06-01 19:01:44 UTC (rev 1396)
@@ -0,0 +1,109 @@
+package cc.kune.selenium;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.openqa.selenium.support.PageFactory;
+import org.openqa.selenium.support.pagefactory.ElementLocatorFactory;
+import org.testng.Assert;
+import org.testng.ITestContext;
+import org.testng.annotations.AfterSuite;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.DataProvider;
+
+import cc.kune.selenium.login.LoginPageObject;
+import cc.kune.selenium.tools.GenericWebTester;
+import cc.kune.selenium.tools.SeleniumConstants;
+import cc.kune.selenium.tools.SeleniumModule;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+public class KuneSeleniumDefaults {
+  private static final Log LOG = LogFactory.getLog(KuneSeleniumDefaults.class);
+  public static boolean mustCloseFinally = true;
+
+  private final Injector injector;
+
+  protected LoginPageObject login;
+  protected GenericWebTester webtester;
+
+  public KuneSeleniumDefaults() {
+    injector = Guice.createInjector(new SeleniumModule());
+    webtester = injector.getInstance(GenericWebTester.class);
+    login = injector.getInstance(LoginPageObject.class);
+    final ElementLocatorFactory locator = injector.getInstance(ElementLocatorFactory.class);
+    PageFactory.initElements(locator, login);
+  }
+
+  @AfterSuite
+  public void closeBrowser() {
+    // We try to only open one window for all our selenium tests
+    if (mustCloseFinally) {
+      webtester.close();
+    }
+  }
+
+  @DataProvider(name = "correctlogin")
+  public Object[][] createCorrectLogin() {
+    // The default correct user/password used in tests
+    return new Object[][] { { SeleniumConstants.USERNAME, SeleniumConstants.PASSWD }, };
+  }
+
+  // public void moveMouseAt(final Point point) {
+  // webtester.moveMouseAt(point);
+  // }
+
+  @DataProvider(name = "incorrectlogin")
+  public Object[][] createIncorrectLogin() {
+    // Some pairs of user/passwd that must fail when try to login
+    return new Object[][] { { "test1 at localhost", "test1blabla" }, { "test1", "test1" },
+        { "test1 at localhost", "test" }, { "", "" } };
+  }
+
+  @BeforeMethod
+  public void setupSeleniumModule(final ITestContext context) {
+
+    // if (!Suco.getComponents().hasProvider(WebDriver.class)) {
+    // Suco.install(new SeleniumModule());
+    // }
+    if (webtester == null) {
+      // final ChromeDriver driver = new ChromeDriver();
+      // // final HtmlUnitDriver driver = new HtmlUnitDriver(true);
+      //
+      // // final ProfilesIni allProfiles = new ProfilesIni();
+      // // final FirefoxProfile profile =
+      // // allProfiles.getProfile(SeleniumConstants.FIREFOX_PROFILE_NAME);
+      // // final FirefoxDriver driver = new FirefoxDriver(profile);
+      //
+      // locator = new AjaxElementLocatorFactory(driver,
+      // SeleniumConstants.TIMEOUT);
+      // webtester = new GenericWebTester(driver,
+      // "http://kune.beta.iepala.es/ws/?locale=en#");
+      // // webtester = Suco.get(GenericWebTester.class);
+      // // login = Suco.get(LoginPageObject.class);
+      // login = new LoginPageObject();
+      // PageFactory.initElements(locator, login);
+      // driver.get("http://kune.beta.iepala.es/ws/?locale=en#");
+      // roster = Suco.get(RosterPageObject.class);
+      // openChat = Suco.get(OpenChatPageObject.class);
+      // search = Suco.get(SearchPageObject.class);
+      // chat = Suco.get(ChatPageObject.class);
+      // editBuddy = Suco.get(EditBuddyPageObject.class);
+      // groupChat = Suco.get(GroupChatPageObject.class);
+      // userPage = Suco.get(UserPageObject.class);
+      // otherVCardPage = Suco.get(OtherVCardPageObject.class);
+      // copyToClipboard = Suco.get(CopyToClipboardPageObject.class);
+      // openGroupChat = Suco.get(OpenGroupChatPageObject.class);
+    }
+    LOG.info("Going home");
+    webtester.home();
+  }
+
+  public void sleep(final int milliseconds) {
+    try {
+      Thread.sleep(milliseconds);
+    } catch (final InterruptedException e) {
+      Assert.fail("Exception in sleep method", e);
+    }
+  }
+}


Property changes on: trunk/src/test/java/cc/kune/selenium/KuneSeleniumDefaults.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/test/java/cc/kune/selenium/KuneSeleniumTest.java
===================================================================
--- trunk/src/test/java/cc/kune/selenium/KuneSeleniumTest.java	                        (rev 0)
+++ trunk/src/test/java/cc/kune/selenium/KuneSeleniumTest.java	2011-06-01 19:01:44 UTC (rev 1396)
@@ -0,0 +1,31 @@
+package cc.kune.selenium;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Shared behaviour in selenium tests
+ */
+public abstract class KuneSeleniumTest extends KuneSeleniumDefaults {
+
+  protected String getTempString() {
+    final DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
+    final String value = dateFormat.format(new Date());
+    return value;
+  }
+
+  protected void login() {
+    login("admin", "easyeasy");
+  }
+
+  protected void login(final String user, final String password) {
+    login.signIn(user, password);
+    login.assertIsConnectedAs(user);
+  }
+
+  protected void logout() {
+    login.logout();
+  }
+
+}


Property changes on: trunk/src/test/java/cc/kune/selenium/KuneSeleniumTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/test/java/cc/kune/selenium/PageObject.java
===================================================================
--- trunk/src/test/java/cc/kune/selenium/PageObject.java	                        (rev 0)
+++ trunk/src/test/java/cc/kune/selenium/PageObject.java	2011-06-01 19:01:44 UTC (rev 1396)
@@ -0,0 +1,129 @@
+package cc.kune.selenium;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.openqa.selenium.By;
+import org.openqa.selenium.NoSuchElementException;
+import org.openqa.selenium.RenderedWebElement;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.ByIdOrName;
+import org.testng.Assert;
+
+import com.google.inject.Inject;
+
+public abstract class PageObject {
+  protected static final String GWTDEV = "gwt-debug-";
+  private static final Log LOG = LogFactory.getLog(PageObject.class.getName());
+  private static final long[] POLL_INTERVALS = { 10, 20, 30, 40, 50, 50, 50, 50, 100 };
+
+  @Inject
+  private WebDriver webdriver;
+
+  protected RenderedWebElement findElement(final By by) {
+    return (RenderedWebElement) getWebDriver().findElement(by);
+  }
+
+  private WebDriver getWebDriver() {
+    return webdriver;
+  }
+
+  public boolean isPresent(final RenderedWebElement element) {
+    // FIXME: find a better way to do this
+    try {
+      getWebDriver().findElement(By.id(element.getAttribute("id")));
+      return true;
+    } catch (final NoSuchElementException e) {
+      return false;
+    }
+  }
+
+  public void waitFor(final RenderedWebElement element) {
+    final String id = element.getAttribute("id");
+    LOG.info("WAIT FOR: " + id);
+    waitFor(id, new Runnable() {
+      @Override
+      public void run() {
+        Assert.assertTrue(element.isDisplayed());
+      }
+    });
+  }
+
+  /**
+   * Thanks to:
+   * http://groups.google.com/group/webdriver/browse_frm/thread/6e705242
+   * cc6d75ed/f5f8dca438397254?lnk=gst#f5f8dca438397254
+   * 
+   * @param waitForWhat
+   * @param runnable
+   */
+  protected void waitFor(final String waitForWhat, final Runnable runnable) {
+    int i = 0;
+    boolean success = false;
+    final long timeout = System.currentTimeMillis() + 9000;
+    while (i < POLL_INTERVALS.length && !success) {
+      try {
+        runnable.run();
+        success = true;
+      } catch (final Throwable e) {
+        if (++i == POLL_INTERVALS.length) {
+          if (System.currentTimeMillis() > timeout) {
+            throw new RuntimeException("Timeout while waiting for " + waitForWhat, e); // NOPMD
+                                                                                       // by
+                                                                                       // vjrj
+                                                                                       // on
+                                                                                       // 16/05/11
+                                                                                       // 13:05
+          } else {
+            --i;
+          }
+        }
+        try {
+          Thread.sleep(POLL_INTERVALS[i]);
+        } catch (final InterruptedException e2) {
+          Thread.currentThread().interrupt();
+          throw new RuntimeException("Got interrupted while waiting for " + waitForWhat, e2); // NOPMD
+                                                                                              // by
+                                                                                              // vjrj
+                                                                                              // on
+                                                                                              // 16/05/11
+                                                                                              // 13:08
+        }
+      }
+    }
+  }
+
+  protected void waitFor(final WebElement element, final String text) {
+    LOG.info("WAIT FOR: " + text);
+    waitFor(text, new Runnable() {
+      @Override
+      public void run() {
+        final String elText = element.getText();
+        LOG.info("Element text: " + elText);
+        Assert.assertTrue(elText.contains(text));
+      }
+    });
+  }
+
+  protected void waitForId(final String id) {
+    LOG.info("WAIT FOR: " + id);
+    waitFor(id, new Runnable() {
+      @Override
+      public void run() {
+        Assert.assertTrue(((RenderedWebElement) getWebDriver().findElement(new ByIdOrName(id))).isDisplayed());
+      }
+    });
+  }
+
+  protected void waitForValue(final WebElement element, final String text) {
+    LOG.info("WAIT FOR: " + text);
+    waitFor(text, new Runnable() {
+      @Override
+      public void run() {
+        final String elValue = element.getValue();
+        LOG.info("Element value: " + elValue);
+        Assert.assertTrue(elValue.contains(text));
+      }
+    });
+  }
+}


Property changes on: trunk/src/test/java/cc/kune/selenium/PageObject.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/test/java/cc/kune/selenium/login/LoginPageObject.java
===================================================================
--- trunk/src/test/java/cc/kune/selenium/login/LoginPageObject.java	                        (rev 0)
+++ trunk/src/test/java/cc/kune/selenium/login/LoginPageObject.java	2011-06-01 19:01:44 UTC (rev 1396)
@@ -0,0 +1,76 @@
+package cc.kune.selenium.login;
+
+import org.openqa.selenium.RenderedWebElement;
+import org.openqa.selenium.support.FindBy;
+
+import cc.kune.core.client.auth.SignInForm;
+import cc.kune.core.client.auth.SignInPanel;
+import cc.kune.core.client.sitebar.SiteUserOptionsPresenter;
+import cc.kune.core.client.sitebar.SitebarSignInLink;
+import cc.kune.core.client.sitebar.SitebarSignOutLink;
+import cc.kune.selenium.PageObject;
+import cc.kune.selenium.tools.I18nHelper;
+import cc.kune.selenium.tools.SeleniumConstants;
+
+import com.calclab.hablar.login.client.LoginMessages;
+
+public class LoginPageObject extends PageObject {
+
+  @FindBy(id = GWTDEV + SignInPanel.SIGN_IN_BUTTON_ID)
+  private RenderedWebElement button;
+  private final I18nHelper i18n;
+  @FindBy(id = SignInForm.PASSWORD_FIELD_ID + "-input")
+  private RenderedWebElement passwd;
+  @FindBy(id = GWTDEV + SitebarSignInLink.SITE_SIGN_IN)
+  private RenderedWebElement signInLink;
+  @FindBy(id = GWTDEV + SitebarSignOutLink.SITE_SIGN_OUT)
+  private RenderedWebElement signOutLink;
+  @FindBy(id = SignInForm.USER_FIELD_ID + "-input")
+  private RenderedWebElement user;
+  @FindBy(id = GWTDEV + SiteUserOptionsPresenter.LOGGED_USER_MENU_ID)
+  private RenderedWebElement userMenu;
+
+  public LoginPageObject() {
+    i18n = new I18nHelper(LoginMessages.class);
+  }
+
+  public void assertIsConnectedAs(final String user) {
+    waitFor(userMenu, user);
+  }
+
+  public void assertIsDisconnected() {
+    try {
+      signOutLink.click();
+    } catch (final Exception e) {
+    }
+    waitFor(signInLink);
+  }
+
+  public RenderedWebElement getHeader() {
+    return signInLink;
+  }
+
+  public RenderedWebElement header() {
+    return getHeader();
+  }
+
+  public void logout() {
+    signOutLink.click();
+    assertIsDisconnected();
+  }
+
+  public void signIn(final String username, final String password) {
+    assertIsDisconnected();
+    signInLink.click();
+    user.clear();
+    passwd.clear();
+    user.sendKeys(username);
+    passwd.sendKeys(password);
+    button.click();
+  }
+
+  public void signInDefUser() {
+    signIn(SeleniumConstants.USERNAME, SeleniumConstants.PASSWD);
+  }
+
+}


Property changes on: trunk/src/test/java/cc/kune/selenium/login/LoginPageObject.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/test/java/cc/kune/selenium/login/LoginSeleniumTests.java
===================================================================
--- trunk/src/test/java/cc/kune/selenium/login/LoginSeleniumTests.java	                        (rev 0)
+++ trunk/src/test/java/cc/kune/selenium/login/LoginSeleniumTests.java	2011-06-01 19:01:44 UTC (rev 1396)
@@ -0,0 +1,37 @@
+package cc.kune.selenium.login;
+
+import org.testng.annotations.Test;
+
+import cc.kune.selenium.KuneSeleniumTest;
+
+public class LoginSeleniumTests extends KuneSeleniumTest {
+
+  @Test(dataProvider = "correctlogin", enabled = false)
+  public void severalsSignInSingOut(final String user, final String passwd) {
+    login.assertIsDisconnected();
+    login.signIn(user, passwd);
+    login.assertIsConnectedAs(user);
+    login.logout();
+
+    login.assertIsDisconnected();
+    login.signIn(user, passwd);
+    login.assertIsConnectedAs(user);
+    login.logout();
+
+    login.assertIsDisconnected();
+  }
+
+  @Test(dataProvider = "correctlogin")
+  public void signIn(final String user, final String passwd) {
+    login.assertIsDisconnected();
+    login.signIn(user, passwd);
+    login.assertIsConnectedAs(user);
+  }
+
+  @Test
+  public void signInIncorrectPasswd() {
+    login.assertIsDisconnected();
+    login.signIn("nouser", "nopassword");
+    login.assertIsDisconnected();
+  }
+}


Property changes on: trunk/src/test/java/cc/kune/selenium/login/LoginSeleniumTests.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/test/java/cc/kune/selenium/testng.xml
===================================================================
--- trunk/src/test/java/cc/kune/selenium/testng.xml	                        (rev 0)
+++ trunk/src/test/java/cc/kune/selenium/testng.xml	2011-06-01 19:01:44 UTC (rev 1396)
@@ -0,0 +1,8 @@
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
+<suite name="Kune" verbose="1">
+  <test name="Login">
+    <packages>
+      <package name="cc.kune.selenium.login" />
+    </packages>
+  </test>
+</suite>


Property changes on: trunk/src/test/java/cc/kune/selenium/testng.xml
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/test/java/cc/kune/selenium/tools/AbstractWebTester.java
===================================================================
--- trunk/src/test/java/cc/kune/selenium/tools/AbstractWebTester.java	                        (rev 0)
+++ trunk/src/test/java/cc/kune/selenium/tools/AbstractWebTester.java	2011-06-01 19:01:44 UTC (rev 1396)
@@ -0,0 +1,52 @@
+package cc.kune.selenium.tools;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+
+import com.google.gwt.user.client.ui.UIObject;
+
+public abstract class AbstractWebTester {
+  private final String baseUrl;
+  private final WebDriver driver;
+
+  // private final Selenium selenium;
+
+  public AbstractWebTester(final WebDriver driver, final String baseUrl) {
+    this.driver = driver;
+    this.baseUrl = baseUrl;
+
+    // selenium = new WebDriverBackedSelenium(driver, baseUrl);
+    // selenium.setTimeout("5000");
+  }
+
+  public void close() {
+    driver.close();
+  }
+
+  public WebElement getById(final String id) {
+    return driver.findElement(By.id(UIObject.DEBUG_ID_PREFIX + id));
+  }
+
+  public void home() {
+    assert baseUrl != null;
+    // selenium.open(baseUrl);
+    driver.get(baseUrl);
+  }
+  //
+  // public boolean isElementPresent(final String id) {
+  // return true;
+  // // return selenium.isElementPresent(id);
+  // }
+  //
+  // public boolean isTextPresent(final String text) {
+  // return true;
+  // // return selenium.isTextPresent(text);
+  // }
+  //
+  // public void moveMouseAt(final Point point) {
+  // // seenium.mouseMoveAt(String.valueOf(point.getX()),
+  // // String.valueOf(point.getY()));
+  // }
+
+}
\ No newline at end of file


Property changes on: trunk/src/test/java/cc/kune/selenium/tools/AbstractWebTester.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/test/java/cc/kune/selenium/tools/GenericWebTester.java
===================================================================
--- trunk/src/test/java/cc/kune/selenium/tools/GenericWebTester.java	                        (rev 0)
+++ trunk/src/test/java/cc/kune/selenium/tools/GenericWebTester.java	2011-06-01 19:01:44 UTC (rev 1396)
@@ -0,0 +1,14 @@
+package cc.kune.selenium.tools;
+
+import org.openqa.selenium.WebDriver;
+
+import com.google.inject.Inject;
+
+public class GenericWebTester extends AbstractWebTester {
+
+  @Inject
+  public GenericWebTester(final WebDriver driver) {
+    super(driver, "http://kune.beta.iepala.es/ws/?locale=en#");
+  }
+
+}


Property changes on: trunk/src/test/java/cc/kune/selenium/tools/GenericWebTester.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/test/java/cc/kune/selenium/tools/I18nHelper.java
===================================================================
--- trunk/src/test/java/cc/kune/selenium/tools/I18nHelper.java	                        (rev 0)
+++ trunk/src/test/java/cc/kune/selenium/tools/I18nHelper.java	2011-06-01 19:01:44 UTC (rev 1396)
@@ -0,0 +1,82 @@
+package cc.kune.selenium.tools;
+
+import java.lang.reflect.Method;
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.google.gwt.i18n.client.Messages;
+import com.google.gwt.i18n.client.Messages.DefaultMessage;
+import com.google.gwt.i18n.client.Messages.PluralText;
+
+public class I18nHelper {
+
+    public static String get(final Class<? extends Messages> messageType, final String methodName,
+	    final Object... params) {
+	try {
+	    final Class<?>[] classes = new Class<?>[params.length];
+	    for (int i = 0; i < params.length; i++) {
+		final Class<? extends Object> class1 = params[i].getClass();
+		classes[i] = class1 == Integer.class ? int.class : class1;
+	    }
+	    final Method method = messageType.getMethod(methodName, classes);
+	    final String defaultValue = i18nDefaultValue(method, classes);
+	    final String pluralOrDefValue = getPlural(method, getFirstInt(params), defaultValue);
+	    return MessageFormat.format(pluralOrDefValue, params);
+	} catch (final Exception e) {
+	    e.printStackTrace();
+	    return "Error: Inexistent i18n String definition for method: " + methodName;
+	}
+    }
+
+    public static String get(final Class<? extends Messages> classToMock, final Method method, final Object[] arguments) {
+	return get(classToMock, method.getName(), arguments);
+    }
+
+    private static int getFirstInt(final Object[] params) {
+	for (final Object param : params) {
+	    final Class<? extends Object> class1 = param.getClass();
+	    if (class1 == Integer.class) {
+		return (Integer) param;
+	    }
+	}
+	return 0;
+    }
+
+    private static String getPlural(final Method method, final int value, final String def) {
+	final PluralText pluralText = method.getAnnotation(PluralText.class);
+	if (pluralText != null) {
+	    final Map<String, String> pluralMap = new HashMap<String, String>();
+	    final String[] pluralForms = pluralText.value();
+	    for (int i = 0; i + 1 < pluralForms.length; i += 2) {
+		pluralMap.put(pluralForms[i], pluralForms[i + 1]);
+	    }
+	    switch (value) {
+	    case 0:
+		final String zero = pluralMap.get("none");
+		return zero == null ? def : zero;
+	    case 1:
+		final String one = pluralMap.get("one");
+		return one == null ? def : one;
+	    default:
+		final String other = pluralMap.get("other");
+		return other == null ? def : other;
+	    }
+	}
+	return def;
+    }
+
+    private static String i18nDefaultValue(final Method method, final Class<?>... params) {
+	return method.getAnnotation(DefaultMessage.class).value();
+    }
+
+    private final Class<? extends Messages> messagesClass;
+
+    public I18nHelper(final Class<? extends Messages> messagesClass) {
+	this.messagesClass = messagesClass;
+    }
+
+    public String get(final String methodName, final Object... params) {
+	return get(messagesClass, methodName, params);
+    }
+}
\ No newline at end of file


Property changes on: trunk/src/test/java/cc/kune/selenium/tools/I18nHelper.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/test/java/cc/kune/selenium/tools/I18nHelperTest.java
===================================================================
--- trunk/src/test/java/cc/kune/selenium/tools/I18nHelperTest.java	                        (rev 0)
+++ trunk/src/test/java/cc/kune/selenium/tools/I18nHelperTest.java	2011-06-01 19:01:44 UTC (rev 1396)
@@ -0,0 +1,29 @@
+package cc.kune.selenium.tools;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import com.calclab.hablar.login.client.LoginMessages;
+import com.calclab.hablar.search.client.SearchMessages;
+
+public class I18nHelperTest {
+
+    @Test
+    public void testOnePlural() {
+	assertEquals("Results for «test1»: One user found.", I18nHelper.get(SearchMessages.class, "searchResultsFor",
+		"test1", 1));
+    }
+
+    @Test
+    public void testSimpleArg() {
+	assertEquals("Connected as test1", I18nHelper.get(LoginMessages.class, "connectedAs", "test1"));
+    }
+
+    @Test
+    public void testSimpleSeveralArgs() {
+	assertEquals("Results for «test1»: 2 users found.", I18nHelper.get(SearchMessages.class, "searchResultsFor",
+		"test1", 2));
+    }
+
+}


Property changes on: trunk/src/test/java/cc/kune/selenium/tools/I18nHelperTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/test/java/cc/kune/selenium/tools/Lorem.java
===================================================================
--- trunk/src/test/java/cc/kune/selenium/tools/Lorem.java	                        (rev 0)
+++ trunk/src/test/java/cc/kune/selenium/tools/Lorem.java	2011-06-01 19:01:44 UTC (rev 1396)
@@ -0,0 +1,11 @@
+package cc.kune.selenium.tools;
+
+public final class Lorem {
+
+  public static final String CHINESE = "吗 台湾 六种辅音韵尾 中国政府要求在中国出售的软件必须使用编码 过国标 名词的复数形式只在代词及多音节 台湾和港澳三地日益加深的经济联系 白话 如上面提到的 个例外可能是 个有意思的问题是中文数据的繁简体转换看 就有明显的区别 推广普通话的效率 虽然不同方言区的人们可能不能互相理解对方的语音 吗 另外, 汉语维基百科 公元前世纪到世纪随着中国大陆政治上的影响不断增加 韩语 上, 文言 新 唐朝和宋朝 历史书书经以及部分的易经 上古汉语存在于周朝前期和中期\n";
+
+  public static final String LATIN = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Fusce leo felis, cursus eget, scelerisque adipiscing, fringilla vel, sem. Vestibulum semper tristique sem. Etiam quam neque, consectetuer at, fermentum id, vulputate non, leo. Ut condimentum, mauris et sollicitudin faucibus, lectus arcu facilisis mi, eu pretium arcu tortor quis sem. Pellentesque sit amet nulla ut tellus dapibus blandit. Donec eu dolor vitae mi scelerisque pretium. Donec sit amet nunc ut risus laoreet porta. Integer dictum mi at mauris. Vivamus vulputate, dolor quis pharetra interdum, augue nisi congue eros, a consectetuer libero mi ut quam. Fusce commodo sem blandit massa. Phasellus vehicula varius felis.\n";
+
+  private Lorem() {
+  }
+}


Property changes on: trunk/src/test/java/cc/kune/selenium/tools/Lorem.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/test/java/cc/kune/selenium/tools/PageObjectModule.java
===================================================================
--- trunk/src/test/java/cc/kune/selenium/tools/PageObjectModule.java	                        (rev 0)
+++ trunk/src/test/java/cc/kune/selenium/tools/PageObjectModule.java	2011-06-01 19:01:44 UTC (rev 1396)
@@ -0,0 +1,15 @@
+package cc.kune.selenium.tools;
+
+import org.openqa.selenium.support.PageFactory;
+import org.openqa.selenium.support.pagefactory.ElementLocatorFactory;
+
+import com.google.inject.AbstractModule;
+
+public abstract class PageObjectModule extends AbstractModule {
+  protected <T> void registerPageObject(final Class<T> componentType, final T object,
+      final ElementLocatorFactory locator) {
+    bind(componentType).toInstance(object);
+    PageFactory.initElements(locator, object);
+
+  }
+}


Property changes on: trunk/src/test/java/cc/kune/selenium/tools/PageObjectModule.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/test/java/cc/kune/selenium/tools/SeleniumConstants.java
===================================================================
--- trunk/src/test/java/cc/kune/selenium/tools/SeleniumConstants.java	                        (rev 0)
+++ trunk/src/test/java/cc/kune/selenium/tools/SeleniumConstants.java	2011-06-01 19:01:44 UTC (rev 1396)
@@ -0,0 +1,12 @@
+package cc.kune.selenium.tools;
+
+public final class SeleniumConstants {
+  public static final String FIREFOX_PROFILE_NAME = "selenium";
+  public static final String PASSWD = "easyeasy";
+  public static final int TIMEOUT = 15;
+  public static final String USERNAME = "admin";
+
+  SeleniumConstants() {
+    // Final class
+  }
+}


Property changes on: trunk/src/test/java/cc/kune/selenium/tools/SeleniumConstants.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/test/java/cc/kune/selenium/tools/SeleniumModule.java
===================================================================
--- trunk/src/test/java/cc/kune/selenium/tools/SeleniumModule.java	                        (rev 0)
+++ trunk/src/test/java/cc/kune/selenium/tools/SeleniumModule.java	2011-06-01 19:01:44 UTC (rev 1396)
@@ -0,0 +1,55 @@
+package cc.kune.selenium.tools;
+
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.chrome.ChromeDriver;
+import org.openqa.selenium.firefox.FirefoxDriver;
+import org.openqa.selenium.firefox.FirefoxProfile;
+import org.openqa.selenium.firefox.internal.ProfilesIni;
+import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
+import org.openqa.selenium.support.pagefactory.ElementLocatorFactory;
+
+import cc.kune.selenium.login.LoginPageObject;
+
+import com.google.inject.Singleton;
+
+public class SeleniumModule extends PageObjectModule {
+
+  public SeleniumModule() {
+  }
+
+  @Override
+  protected void configure() {
+
+    // bind(WebDriver.class).toInstance(creatFirefoxDriver());
+    final ChromeDriver driver = createChromeDriver();
+    bind(WebDriver.class).toInstance(driver);
+
+    bind(GenericWebTester.class).in(Singleton.class);
+
+    // "http://127.0.0.1:8888/ws/?locale=en&log_level=INFO&gwt.codesvr=127.0.0.1:9997#");
+
+    bind(ElementLocatorFactory.class).toInstance(
+        new AjaxElementLocatorFactory(driver, SeleniumConstants.TIMEOUT));
+
+    // Page Objects here!
+    bind(LoginPageObject.class).in(Singleton.class);
+  }
+
+  private ChromeDriver createChromeDriver() {
+    final ChromeDriver driver = new ChromeDriver();
+    return driver;
+  }
+
+  @SuppressWarnings("unused")
+  private FirefoxDriver creatFirefoxDriver() {
+    // final FirefoxProfile profile = new FirefoxProfile();
+    // profile.setPreference("webdriver.firefox.profile",
+    // SeleniumConstants.FIREFOX_PROFILE_NAME);
+    // profile.setPreference("webdriver.firefox.useExisting",true);
+    final ProfilesIni allProfiles = new ProfilesIni();
+    final FirefoxProfile profile = allProfiles.getProfile(SeleniumConstants.FIREFOX_PROFILE_NAME);
+    // profile.setPreferences("foo.bar", 23);
+    final FirefoxDriver driver = new FirefoxDriver(profile);
+    return driver;
+  }
+}


Property changes on: trunk/src/test/java/cc/kune/selenium/tools/SeleniumModule.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the kune-commits mailing list