svn commit: r901704 - in /ofbiz/trunk: applications/marketing/testdef/CommEventCreateOpportunity_testsuite.xml framework/testtools/config/seleniumXml.properties framework/testtools/src/org/ofbiz/testtools/seleniumxml/SeleniumXml.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r901704 - in /ofbiz/trunk: applications/marketing/testdef/CommEventCreateOpportunity_testsuite.xml framework/testtools/config/seleniumXml.properties framework/testtools/src/org/ofbiz/testtools/seleniumxml/SeleniumXml.java

erwan
Author: erwan
Date: Thu Jan 21 13:41:21 2010
New Revision: 901704

URL: http://svn.apache.org/viewvc?rev=901704&view=rev
Log:
Correct the firefox location on debian and add new functionnalities to seleniumXml :
* take a browser screenshot with "captureEntirePageScreenshot"
* close the browser at a test's end with "closeBrowser"
Screenshots are saved in runtime/logs/ but can be changed in seleniumXml.properties file

You can try those by launching the test CommEventCreateOpportunity_testsuite.xml

The magic used to take screenshots was found on the seleniumexamples blog.

Modified:
    ofbiz/trunk/applications/marketing/testdef/CommEventCreateOpportunity_testsuite.xml
    ofbiz/trunk/framework/testtools/config/seleniumXml.properties
    ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/seleniumxml/SeleniumXml.java

Modified: ofbiz/trunk/applications/marketing/testdef/CommEventCreateOpportunity_testsuite.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/marketing/testdef/CommEventCreateOpportunity_testsuite.xml?rev=901704&r1=901703&r2=901704&view=diff
==============================================================================
--- ofbiz/trunk/applications/marketing/testdef/CommEventCreateOpportunity_testsuite.xml (original)
+++ ofbiz/trunk/applications/marketing/testdef/CommEventCreateOpportunity_testsuite.xml Thu Jan 21 13:41:21 2010
@@ -47,4 +47,6 @@
     <waitForPageToLoad value="50000" />
     <click locator="link=Communications" />
     <waitForPageToLoad value="50000" />
+    <captureEntirePageScreenshot value="CommEventCreateOpportunity"/>
+    <closeBrowser/>
 </testcase>

Modified: ofbiz/trunk/framework/testtools/config/seleniumXml.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/config/seleniumXml.properties?rev=901704&r1=901703&r2=901704&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/config/seleniumXml.properties (original)
+++ ofbiz/trunk/framework/testtools/config/seleniumXml.properties Thu Jan 21 13:41:21 2010
@@ -1,7 +1,7 @@
 serverHost=localhost
 proxyPort=4444
 #for debian, use the following line
-#browser=*firefox /usr/lib/iceweasel/iceweasel
+#browser=*firefox /usr/lib/iceweasel/firefox-bin
 browser=*firefox /usr/lib/firefox-3.0.8/firefox
 startUrl=http://localhost:8080/
 log4jFile=./config/log4j.properties
\ No newline at end of file

Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/seleniumxml/SeleniumXml.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/seleniumxml/SeleniumXml.java?rev=901704&r1=901703&r2=901704&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/seleniumxml/SeleniumXml.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/seleniumxml/SeleniumXml.java Thu Jan 21 13:41:21 2010
@@ -19,9 +19,6 @@
 
 package org.ofbiz.testtools.seleniumxml;
 
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.DataInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -30,7 +27,6 @@
 import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.net.URLConnection;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -41,10 +37,11 @@
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+
 import javolution.util.FastMap;
 import junit.framework.Assert;
 
-import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.lang.RandomStringUtils;
 import org.apache.log4j.BasicConfigurator;
 import org.apache.log4j.Level;
@@ -53,7 +50,7 @@
 import org.jdom.Element;
 import org.jdom.JDOMException;
 import org.jdom.input.SAXBuilder;
-import org.ofbiz.testtools.seleniumxml.util.TestUtils;
+import org.ofbiz.base.util.UtilDateTime;
 import org.ofbiz.base.util.UtilGenerics;
 import org.ofbiz.base.util.UtilHttp;
 import org.ofbiz.base.util.UtilProperties;
@@ -63,6 +60,8 @@
 import org.ofbiz.testtools.seleniumxml.GroovyRunner;
 import org.ofbiz.testtools.seleniumxml.JythonRunner;
 import org.ofbiz.testtools.seleniumxml.RemoteRequest;
+import org.ofbiz.testtools.seleniumxml.TestCaseException;
+import org.ofbiz.testtools.seleniumxml.util.TestUtils;
 
 import com.thoughtworks.selenium.DefaultSelenium;
 import com.thoughtworks.selenium.SeleniumException;
@@ -81,7 +80,8 @@
     private String username;
     private String password;
     private String testCaseDirectory;
-
+    private String imagePath = null;
+    
     public static void main(String[] args) throws JDOMException, IOException, TestCaseException{
         if(args.length == 0) {
             System.out.println("Please include a path for the selenium XML test file.");
@@ -145,9 +145,9 @@
             }
         }catch(JDOMException jdome){
              System.out.println(jdome.getMessage());
-         }catch(IOException ioe){
+        }catch(IOException ioe){
              System.out.println("Error message : "+ioe.getMessage());
-         }finally{
+        }finally{
              return "success";
          }
     }
@@ -320,8 +320,12 @@
                 selectWindow(elem);
             }  else if("assertConfirmation" == thisName) {
                 assertConfirmation(elem);
+            }  else if("captureEntirePageScreenshot" == thisName) {
+                captureEntirePageScreenshotCmd(elem);
             } else if("runScript" == thisName) {
                 runScript(elem);
+            } else if("closeBrowser" == thisName) {
+                sel.stop();
             } else {
                 logger.info("Undefined command calling by reflection for command: " + thisName);
                 callByReflection(elem);
@@ -686,6 +690,29 @@
     }
 
     /**
+     * @param elem
+     * Will save a browser's screenshot in runtime/logs
+     * Need to be called with captureEntirePageScreenshot and the name of the test case
+     * example :
+     *     <captureEntirePageScreenshot value="CommEventCreateOpportunity"/>
+     */
+    private void captureEntirePageScreenshotCmd(Element elem) {
+        Long now = UtilDateTime.nowTimestamp().getTime();
+        String imageName = replaceParam(elem.getAttributeValue("value")) + "-" + now.toString();
+        logger.debug("captureEntirePageScreenshot: " + imageName);
+        imagePath = "runtime/logs/" + imageName + ".png";
+        try {
+            String base64Screenshot = sel.captureEntirePageScreenshotToString("");
+            byte[] decodedScreenshot = Base64.decodeBase64(base64Screenshot.getBytes());
+            FileOutputStream fos = new FileOutputStream(new File(imagePath));
+            fos.write(decodedScreenshot);
+            fos.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
      * @param elem takes a Selenium String locator.  See Javadocs for more information.  Here are some
      * example locators:
      * id="buttonId"  - the easiest
@@ -949,11 +976,11 @@
 
         //First initialize with property values
         if(props != null ) { //Get setup params from property value
-
             serverHost = props.getProperty("serverHost", "localhost");
             serverPort = props.getProperty("proxyPort", "4444");
             browser = props.getProperty("browser", "*iexplore");
             startUrl = props.getProperty("startUrl", "http://localhost:8080");
+            imagePath = props.getProperty("imagePath", "runtime/logs/");
         }
         //Second over ride properties if defined in the "setup" element
         Element elem = this.doc.getRootElement().getChild("setup");
@@ -976,6 +1003,7 @@
         logger.info("setup: serverPort=" + serverPort);
         logger.info("setup: browser=" + browser);
         logger.info("setup: startUrl=" + startUrl);
+        logger.info("setup: imagePath=" + imagePath);
         this.sel = new DefaultSelenium(serverHost, Integer.parseInt(serverPort), browser, startUrl);
         this.sel.start();
     }