geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r439696 - in /geronimo/server/trunk/maven-plugins/selenium-maven-plugin: ./ src/main/java/org/apache/geronimo/mavenplugins/selenium/ src/main/resources/ src/main/resources/org/ src/main/resources/org/apache/ src/main/resources/org/apache/ge...
Date Sun, 03 Sep 2006 01:28:14 GMT
Author: jdillon
Date: Sat Sep  2 18:28:13 2006
New Revision: 439696

URL: http://svn.apache.org/viewvc?rev=439696&view=rev
Log:
Adding support for a default set of user extentions, and merging with local if needed

Added:
    geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/
    geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/
    geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/apache/
    geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/apache/geronimo/
    geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/apache/geronimo/mavenplugins/
    geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/apache/geronimo/mavenplugins/selenium/
    geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/apache/geronimo/mavenplugins/selenium/default-user-extentions.js
  (with props)
Modified:
    geronimo/server/trunk/maven-plugins/selenium-maven-plugin/pom.xml
    geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/selenium/StartServerMojo.java

Modified: geronimo/server/trunk/maven-plugins/selenium-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/selenium-maven-plugin/pom.xml?rev=439696&r1=439695&r2=439696&view=diff
==============================================================================
--- geronimo/server/trunk/maven-plugins/selenium-maven-plugin/pom.xml (original)
+++ geronimo/server/trunk/maven-plugins/selenium-maven-plugin/pom.xml Sat Sep  2 18:28:13
2006
@@ -38,6 +38,12 @@
             <artifactId>selenium-server</artifactId>
             <version>0.8.1</version>
         </dependency>
+
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>1.2</version>
+        </dependency>
     </dependencies>
     
     <repositories>

Modified: geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/selenium/StartServerMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/selenium/StartServerMojo.java?rev=439696&r1=439695&r2=439696&view=diff
==============================================================================
--- geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/selenium/StartServerMojo.java
(original)
+++ geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/selenium/StartServerMojo.java
Sat Sep  2 18:28:13 2006
@@ -14,19 +14,27 @@
  *  limitations under the License.
  */
 
-package org.apache.geronimo.mavenplugins.server;
+package org.apache.geronimo.mavenplugins.selenium;
 
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.artifact.resolver.ArtifactResolver;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.plugin.MojoFailureException;
 
 import java.io.File;
+import java.io.PrintWriter;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+
+import java.net.URL;
+import java.net.MalformedURLException;
 
 import org.apache.geronimo.genesis.AntMojoSupport;
 import org.apache.geronimo.plugin.ArtifactItem;
 import org.apache.commons.lang.SystemUtils;
+import org.apache.commons.io.IOUtils;
 
 import org.apache.tools.ant.taskdefs.ExecTask;
 
@@ -45,29 +53,45 @@
      *
      * @parameter default-value="4444"
      */
-    private int port;
+    private int port = -1;
     
     /**
      * Timeout for the server in seconds.
      *
      * @parameter default-value="-1"
      */
-    private int timeout;
-    
-    
+    private int timeout = -1;
+
     /**
      * Enable the server's debug mode..
      *
      * @parameter default-value="false"
      */
-    private boolean debug;
-    
+    private boolean debug = false;
+
+    /**
+     * The file or resource to use for default user-extentions.js.
+     *
+     * @parameter default-value="org/apache/geronimo/mavenplugins/selenium/default-user-extentions.js"
+     */
+    private String defaultUserExtensions = null;
+
+    /**
+     * Enable or disable default user-extentions.js
+     *
+     * @parameter default-value="true"
+     */
+    private boolean defaultUserExtensionsEnabled = true;
+
     /**
      * Location of the user-extentions.js to load into the server.
      *
+     * <p>
+     * If defaultUserExtensionsEnabled is true, then this file will be appended to the defaults.
+     *
      * @parameter
      */
-    private File userExtensions;
+    private String userExtensions = null;
     
     //
     // MojoSupport Hooks
@@ -82,7 +106,6 @@
      */
     private MavenProject project = null;
 
-
     protected MavenProject getProject() {
         return project;
     }
@@ -146,62 +169,125 @@
 
         final String executable = "java" +  (SystemUtils.IS_OS_WINDOWS ? ".exe" : "");
 
+        final ExecTask exec = (ExecTask)createTask("exec");
+        exec.setExecutable(executable);
+
+        //
+        // HACK: Use Simple log instead of evil JDK 1.4 logging
+        //       Should change to Java task and setup log4j.properties in the cp
+        //
+        exec.createArg().setValue("-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog");
+
+        exec.createArg().setValue("-jar");
+        exec.createArg().setFile(artifact.getFile());
+
+        exec.createArg().setValue("-port");
+        exec.createArg().setValue(String.valueOf(port));
+
+        if (debug) {
+            exec.createArg().setValue("-debug");
+        }
+
+        if (timeout > 0) {
+            log.info("Timeout after: " + timeout + " seconds");
+
+            exec.createArg().setValue("-timeout");
+            exec.createArg().setValue(String.valueOf(timeout));
+        }
+
+        File userExtentionsFile = getUserExtentionsFile();
+        if (userExtentionsFile != null) {
+            log.info("Using user extensions: " + userExtentionsFile);
+
+            exec.createArg().setValue("-userExtensions");
+            exec.createArg().setFile(userExtentionsFile);
+        }
+
+        exec.setLogError(true);
+
         // Start the server int a seperate thread
         Thread t = new Thread("Server Runner") {
             public void run() {
                 try {
-                    ExecTask exec = (ExecTask)createTask("exec");
-                    exec.setExecutable(executable);
-                    
-                    //
-                    // HACK: Use Simple log instead of evil JDK 1.4 logging
-                    //       Should change to Java task and setup log4j.properties in the
cp
-                    //
-                    exec.createArg().setValue("-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog");
-                    
-                    exec.createArg().setValue("-jar");
-                    exec.createArg().setFile(artifact.getFile());
-                    
-                    exec.createArg().setValue("-port");
-                    exec.createArg().setValue(String.valueOf(port));
-                    
-                    if (debug) {
-                        exec.createArg().setValue("-debug");
-                    }
-                    
-                    if (timeout > 0) {
-                        log.info("Timeout after: " + timeout + " seconds");
-                        
-                        exec.createArg().setValue("-timeout");
-                        exec.createArg().setValue(String.valueOf(timeout));
-                    }
-                    
-                    if (userExtensions != null) {
-                        log.info("Using user extensions: " + userExtensions);
-                        
-                        exec.createArg().setValue("-userExtensions");
-                        exec.createArg().setFile(userExtensions);
-                    }
-                    
-                    exec.setLogError(true);
                     exec.execute();
                 }
                 catch (Exception e) {
                     log.error("Failed to start server", e);
                 }
-                
-                try {
-                    synchronized(this) {
-                        wait();
-                    }
-                }
-                catch (Exception e) {
-                    // ignore
-                }
             }
         };
         t.start();
 
         log.info("Server started");
+    }
+
+    /**
+     * Resolve a resource to a file, URL or resource.
+     */
+    private URL resolveResource(final String name) throws MalformedURLException, MojoFailureException
{
+        assert name != null;
+
+        URL url;
+
+        File file = new File(name);
+        if (file.exists()) {
+            url = file.toURL();
+        }
+        else {
+            try {
+                url = new URL(name);
+            }
+            catch (MalformedURLException e) {
+                url = Thread.currentThread().getContextClassLoader().getResource(name);
+            }
+        }
+
+        if (url == null) {
+            throw new MojoFailureException("Could not resolve resource: " + name);
+        }
+
+        log.debug("Resolved resource '" + name + "' as: " + url);
+
+        return url;
+    }
+
+    /**
+     * Retutn the user-extentions.js file to use, or null if it should not be installed.
+     */
+    private File getUserExtentionsFile() throws Exception {
+        if (!defaultUserExtensionsEnabled && userExtensions == null) {
+            return null;
+        }
+
+        File file = File.createTempFile("user-extentions-", ".js");
+        file.deleteOnExit();
+        PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(file)));
+
+        if (defaultUserExtensionsEnabled) {
+            URL url = resolveResource(defaultUserExtensions);
+            log.debug("Using defaults: " + url);
+
+            writer.println("//");
+            writer.println("// Default user extentions; from: " + url);
+            writer.println("//");
+
+            IOUtils.copy(url.openStream(), writer);
+        }
+
+        if (userExtensions != null) {
+            URL url = resolveResource(userExtensions);
+            log.debug("Using user extentions: " + url);
+
+            writer.println("//");
+            writer.println("// User extentions; from: " + url);
+            writer.println("//");
+
+            IOUtils.copy(url.openStream(), writer);
+        }
+
+        writer.flush();
+        writer.close();
+
+        return file;
     }
 }

Added: geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/apache/geronimo/mavenplugins/selenium/default-user-extentions.js
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/apache/geronimo/mavenplugins/selenium/default-user-extentions.js?rev=439696&view=auto
==============================================================================
--- geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/apache/geronimo/mavenplugins/selenium/default-user-extentions.js
(added)
+++ geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/apache/geronimo/mavenplugins/selenium/default-user-extentions.js
Sat Sep  2 18:28:13 2006
@@ -0,0 +1,123 @@
+/*
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+//
+// $Rev$ $Date$
+//
+
+//
+// Incorporated from: http://wiki.openqa.org/display/SEL/removeCookie
+//
+
+function createCookie(doc, name, value, path, days) {
+    if (!path) {
+        path = "/";
+    }
+
+    if (days) {
+        var date = new Date();
+        date.setTime(date.getTime()+(days*24*60*60*1000));
+        var expires = "; expires=" + date.toGMTString();
+    }
+    else {
+        var expires = "";
+    }
+    
+    doc.cookie = name + "=" + value + expires + "; path=" + path;
+}
+
+/**
+ * Removes the cookie with the given name.
+ *  text - the cookie name
+ *  path - the cookie path
+ */
+Selenium.prototype.removeCookie = function(text, path) {
+    createCookie(this.page().currentDocument, text, "", path, -1);
+};
+
+//
+// Incorporated from user-extentions.js.sample from Selenium RC 0.8.1
+//
+
+// The following examples try to give an indication of how Selenium can be extended with
javascript.
+
+/**
+ * All do* methods on the Selenium prototype are added as actions.
+ * Eg add a typeRepeated action to Selenium, which types the text twice into a text box.
+ * The typeTwiceAndWait command will be available automatically
+ */
+Selenium.prototype.doTypeRepeated = function(locator, text) {
+    // All locator-strategies are automatically handled by "findElement"
+    var element = this.page().findElement(locator);
+
+    // Create the text to type
+    var valueToType = text + text;
+
+    // Replace the element text with the new text
+    this.page().replaceText(element, valueToType);
+};
+
+/**
+ * All assert* methods on the Selenium prototype are added as checks.
+ * Eg add a assertValueRepeated check, that makes sure that the element value
+ * consists of the supplied text repeated.
+ * The verify version will be available automatically.
+ */
+Selenium.prototype.assertValueRepeated = function(locator, text) {
+    // All locator-strategies are automatically handled by "findElement"
+    var element = this.page().findElement(locator);
+
+    // Create the text to verify
+    var expectedValue = text + text;
+
+    // Get the actual element value
+    var actualValue = element.value;
+
+    // Make sure the actual value matches the expected
+    Assert.matches(expectedValue, actualValue);
+};
+
+/**
+ * All get* methods on the Selenium prototype result in
+ * store, assert, assertNot, verify, verifyNot, waitFor, and waitForNot commands.
+ * E.g. add a getTextLength method that returns the length of the text
+ * of a specified element.
+ * Will result in support for storeTextLength, assertTextLength, etc.
+ */
+Selenium.prototype.getTextLength = function(locator) {
+	return this.getText(locator).length;
+};
+
+/**
+ * All locateElementBy* methods are added as locator-strategies.
+ * Eg add a "valuerepeated=" locator, that finds the first element with the supplied value,
repeated.
+ * The "inDocument" is a the document you are searching.
+ */
+PageBot.prototype.locateElementByValueRepeated = function(text, inDocument) {
+    // Create the text to search for
+    var expectedValue = text + text;
+
+    // Loop through all elements, looking for ones that have a value === our expected value
+    var allElements = inDocument.getElementsByTagName("*");
+    for (var i = 0; i < allElements.length; i++) {
+        var testElement = allElements[i];
+        if (testElement.value && testElement.value === expectedValue) {
+            return testElement;
+        }
+    }
+    return null;
+};
+

Propchange: geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/apache/geronimo/mavenplugins/selenium/default-user-extentions.js
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/apache/geronimo/mavenplugins/selenium/default-user-extentions.js
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/apache/geronimo/mavenplugins/selenium/default-user-extentions.js
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message