Thursday, October 24, 2013

Casper JS test result XML conversion to HTML + XUnit XML Conversion to HTML Reports using JUNIT XSL

Found a problem wherein I had the XML for my results in casperJS via XUnit.

1. CasperJS Results can be held within an XML via the switch --xunit
casperjs test chatPairing.js basicChatDropAllEndpoints.js --xunit=log.xml

Now when checked at all places, there seemed no way. There is the build.xml and ant thisng. But it said my xml was invalid as it seemed the junit xsd that ant uses refused to match the xml generated by xunit.

2. So here is the simplest solution I formulated found post much working

a. Get a copy of JUNIT.XSL from the web. OR http://svn.apache.org/repos/asf/directory/studio/trunk/tests/test.integration.core/resources/test-plugins/org.eclipse.test_3.2.0/JUNIT.XSL

b. Add the following
 casperjs test chatPairing.js basicChatDropAllEndpoints.js --xunit=log.xml
sed -i 's#UTF-8"?>#UTF-8"?><?xml-stylesheet type="text/xsl" href="JUNIT.XSL"?>#' log.xml

 c. Now log.xml is rendered as a transformed xml file containing your results formatted like an html in supported browsers.

~joviano_dias@hotmail.com

Wednesday, October 23, 2013

Convert TestNG/JUnit XML to HTML reports

Create a DIR for you report in the dir where this is (Or change path)
Place this where your XML is (Or change path)

<project name="TestNG_WORKSPACE" default="junit-report" basedir=".">
  <!-- Sets the property variables to point to respective directories -->
  <property name="junit-xml-dir" value="./"/>
  <property name="report-dir" value="./ChatReport/" />

  <!-- Ant target to generate html report -->
  <target name="junit-report">
    <!-- Delete and recreate the html report directories -->
    <delete dir="${report-dir}" failonerror="false"/>
    <mkdir dir="${report-dir}" />
    <mkdir dir="${report-dir}/Html" />
    <!-- Ant task to generate the html report.
    todir - Directory to generate the output reports

    fileset - Directory to look for the junit xml reports.

    report - defines the type of format to be generated.
      Here we are using "noframes" which generates a single html report.
     -->
    <junitreport todir="${report-dir}/Html">
      <fileset dir="${junit-xml-dir}">
        <include name="**/*.xml" />
      </fileset>
      <report format="noframes" todir="${report-dir}/Html" />
    </junitreport>
  </target>
</project>

It will generate the html reports under value="./ChatReport/Html

~joviano_dias@hotmail.com

Monday, October 21, 2013

HTML templates for JENKINS email-ext to report TestNG results


If you are using testNG and Jenkins Here is a template that I designed. No these are not the conventional templates for jenkins using groovy scripts. Just a plain HTML template that does that job and looks neat. The trend Map will work if you are using Jenkins JUNIT reports from xml

<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 Width="100%">

<TR  BGCOLOR="#989898" width="100%"><td colspan=2><FONT COLOR=White FACE="Geneva, Arial" SIZE=2>  Summary</font></td></TR>

<TR><TD BGCOLOR="#0099CC" width="20%"><FONT COLOR=White FACE="Geneva, Arial" SIZE=2>  Total</font></td><TD BGCOLOR="#FFFFFF"><FONT COLOR=#0099CC FACE="Geneva, Arial" SIZE=2>${TEST_COUNTS,var="total"}</font></td></TR>

<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 Width="100%">
<TR><TD BGCOLOR="#04B431" width="20%"><FONT COLOR=white FACE="Geneva, Arial" SIZE=2>  Pass</font></td><TD BGCOLOR="#FFFFFF"><FONT COLOR=#04B431 FACE="Geneva, Arial" SIZE=2>${TEST_COUNTS,var="pass"}</font></td></TR>

<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 Width="100%">
<TR><TD BGCOLOR="#DF3A01" width="20%"><FONT COLOR=white FACE="Geneva, Arial" SIZE=2>  Fail</font></td><TD BGCOLOR="#FFFFFF"><FONT COLOR=#DF3A01 FACE="Geneva, Arial" SIZE=2>${TEST_COUNTS,var="fail"}</font></td></TR>

<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 Width="100%">
<TR><TD BGCOLOR="#A4A4A4" width="20%"><FONT COLOR=white FACE="Geneva, Arial" SIZE=2>  Skip</font></td><TD BGCOLOR="#FFFFFF"><FONT COLOR=#A4A4A4 FACE="Geneva, Arial" SIZE=2>${TEST_COUNTS,var="skip"}</font></td></TR>

</TABLE>
<br/>
<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 Width="100%">
<TR  BGCOLOR="#989898" width="100%"><td><FONT COLOR=White FACE="Geneva, Arial" SIZE=2>  Failure Analysis</font></td></TR>
<TR  BGCOLOR="#424242" width="100%"><td><FONT COLOR=White FACE="Courier New, Lucida Console" SIZE=2>${FAILED_TESTS, showStack=false}</font></td></TR>
</TABLE>

<br/>
<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 Width="100%">
<TR  BGCOLOR="#989898" width="100%"><td><FONT COLOR=White FACE="Geneva, Arial" SIZE=2>HTML Report</font></td></TR>
<TR  width="100%"><td><FONT FACE="Geneva, Arial" SIZE=2>${JOB_URL}ws/path/to-your-html-report</font></td></TR>
</TABLE>
<br/>


<br/>
<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 Width="100%">
<TR  BGCOLOR="#989898" width="100%"><td><FONT COLOR=White FACE="Geneva, Arial" SIZE=2>Jenkins Job URL</font></td></TR>
<TR  width="100%"><td><FONT FACE="Geneva, Arial" SIZE=2>${JOB_URL}</font></td></TR>
</TABLE>

<br/>
<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=2 Width="100%">
<TR  BGCOLOR="#989898" width="100%"><td><FONT COLOR=White FACE="Geneva, Arial" SIZE=2>Test Trend</font></td></TR>
<TR width="100%"><td><img lazymap="${JOB_URL}test/trendMap" src="${JOB_URL}test/trend" alt="Trend Graph - Enable Email Images To View" usemap="${JOB_URL}test/trendMap#map0">
</TR>
</TABLE>



What you need to do is-  setup the Email-Ext extension well. To report on failures and success (don't rely on the default). Also attach you screenshots/ reports in email.

~joviano_dias@hotmail.com

Jenkins check if selenium server is fine and no false postitives/errors in email before email-ext email is sent

This script is a groovy script that helps you detect if you selenium server is up and running and the state is success.

#!/usr/local/bin/groovy

import groovy.json.JsonSlurper

if ( "curl -s http://10.5.5.57:4444/wd/hub/status --max-time 15".execute().text == "" ) {
        println "Cannot connect to selenium server"
        return false
}

println "Connected to selenium server"

def restResponse = "curl -s http://10.5.5.57:4444/wd/hub/status --max-time 15".execute().text
def list = new JsonSlurper().parseText( restResponse )

if ( list.state == "success" ) {
        println "Server is running fine"
        return 0

} else {
        println "Server state found down"
        return 1
}

You can configure it as a Pre-send Script (NOT Pre Build Script Trigger) in Jenkins for your testng-selenium-java job You would need to install groovy though on your linux box to test it as a script. This will ensure that your tests are run only when the selenium server is alive.

A shell equivalent of doing so. But found this wouldn't help me in jenkins. May help you elsewhere

isSelServerUp=`curl -i -s http://10.5.5.57:4444/wd/hub/status | grep -e "\"state\":\"success\""`
echo "selenium server:\n"
echo $isSelServerUp
if [ -z "$isSelServerUp" ]; then
        echo 'Selenium server is not running at http://10.5.5.57:4444/wd/hub/status'
        exit 1
else
        echo "Selenium server found in good state"


fi

Update:
However post this I found problems with test emails being generated even if there were problems with machine access etc. So to suppress emails when no tests were run modified it tot he following-

#!/usr/local/bin/groovy

import groovy.json.JsonSlurper
import java.util.regex.Matcher
import java.util.regex.Pattern

String jobLog = build.getLog(20000);

def m = jobLog =~ /Test reports were found but none of them are new. Did tests run/;
def n = jobLog =~ /Tests run: 0, Failures: 0, Errors: 0, Skipped: 0/;

if (m.size())
{
        logger.println("Tests Did Not Run. Not Sending Email. Found Line - " + m[0])
        cancel=true;
}else if (n.size())
{
        logger.println("Tests Did Not Run 0 0 0. Not Sending Email. Found Line - " + m[0])
        cancel=true;
}else if( "curl -s http://10.5.5.57:4444/wd/hub/status --max-time 15".execute().text == "" ) {
        logger.println "Cannot connect to selenium server - Not sending email";
        cancel=true;
}else{
        logger.println "Connected to selenium server and confirmed that tests ran - Cleared to send email";
}


This worked great. Further inspired from http://massol.myxwiki.org/xwiki/bin/view/Blog/JenkinsDontSendEmailForFalsePositives, checked all conditions via a list-

#!/usr/local/bin/groovy

import groovy.json.JsonSlurper
import java.util.regex.Matcher
import java.util.regex.Pattern

String jobLog = build.getLog(20000);

def messages = [
  [".*A fatal error has been detected by the Java Runtime Environment.*", "JVM Crash", "A JVM crash happened!"],
  [".*Error: cannot open display: :1.0.*", "VNC not running", "VNC connection issue!"],
  [".*java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment.*", "VNC issue", "VNC connection issue!"],
  [".*hudson.plugins.git.GitException: Could not fetch from any repository.*", "Git issue", "Git fetching issue!"],
  [".*Error communicating with the remote browser. It may have died..*", "Browser issue", "Connection to Browser has died!"],
  [".*Error communicating with the remote browser. It may have died..*", "Browser issue", "Connection to Browser has died!"],
  [".*UnreachableBrowser Error.*", "Browser issue", "Browser has died!"],
  [".*Fatal Error: Unable to find package java.lang in classpath or bootclasspath.*", "Compilation issue", "Compilation issue!"],
  [".*Tests run: 0, Failures: 0, Errors: 0, Skipped: 0.*", "No Tests Ran", "Tests Did Not Run!"],
  [".*Test reports were found but none of them are new. Did tests run.*", "Tests did not run", "No Tests Ran!"]
]

def shouldSendEmail = true
messages.each { message ->
  if (jobLog =~ message.get(0)) {
    logger.println message.get(0)
    logger.println message.get(1)
    logger.println message.get(2)
    shouldSendEmail = false
  }
}

if( "curl -s http://10.5.5.57:4444/wd/hub/status --max-time 15".execute().text == "" ) {
    logger.println "Cannot connect to selenium server";
    shouldSendEmail = false
}else{
        logger.println "Connected to selenium server";
}

if(!shouldSendEmail){
        logger.println "Connected to selenium server and No log errors - Not sending email";
        cancel=true;
}

Buzz me out for any questions!
Joviano Dias ~joviano_dias@hotmail.com


Monday, September 23, 2013

World Wide Browser Usage Statistics October 2013 (Sept 15-Oct 1)



Browser Instance samples     % of total
chrome  35293 45.38%
firefox  12572 16.16%
ie  22441 28.85%
opera  31 0.04%
safari  7439 9.56%
Grand Total 77776 100.00%

















By Browser Versions

By Version (15 d)
Browsers  Instance Count
chrome  45.38% 35293
11 0.02% 12
12 0.02% 13
13 0.04% 33
16 0.00% 2
17 0.03% 20
18 0.01% 5
19 0.00% 3
20 0.04% 30
21 0.18% 142
22 0.05% 40
23 0.22% 169
24 0.14% 112
25 0.33% 258
26 0.28% 219
27 0.34% 263
28 2.83% 2201
29 39.90% 31031
30 0.72% 560
31 0.23% 180
firefox  16.16% 12572
13 0.03% 24
14 0.04% 33
15 0.10% 81
16 0.10% 76
17 0.95% 737
18 0.13% 99
19 0.13% 101
20 0.14% 110
21 0.26% 202
22 0.63% 490
23 13.13% 10211
24 0.50% 391
25 0.02% 13
26 0.00% 3
27 0.00% 1
ie  28.85% 22441
8 9.66% 7511
9 9.46% 7358
10 9.74% 7572
opera  0.04% 31
12 0.04% 31
safari  9.56% 7439
5 0.97% 753
6 8.53% 6634
7 0.07% 52
Grand Total 100.00% 77776















Inference
 Most preferred browsers  
          Chrome->IE->Firefox->Safari
 By Version 
          Chrome 29 -> Firefox 15 -> IE 10 -> IE 8 -> IE 9 ->  Safari 6


~joviano_dias@hotmail.com

Friday, October 22, 2010

JMeter ebook download [Packt Publishing Apache JMeter Jun 2008]

Here is an E-book on JMeter. Hope you'll will find it useful.

File name: Packt Publishing Apache JMeter Jun 2008.pdf
File size:5.24 MB


Table of Contents

Chapter 1: Automated Testing
Why Automate Testing?
To Automate or Not to Automate—Some Hints
How Much Does it Cost?

Chapter 2: Introduction to JMeter
The Humble Beginning
The Features—What JMeter Can Do for You
The Look-How-Easy-to-Use GUI
The Requirements

Chapter 3: Getting Started
Installing JMeter
Setting the Environment
Running JMeter

Chapter 4: The Test Plan
What Is a Test Plan?
Elements of a Test Plan
Thread Group
Controllers
Samplers
Logic Controllers
Listeners
Timers
Assertions
Configuration Elements
Pre-Processor Elements
Post-Processor Elements
Building a Test Plan That Tests Web Sites

Chapter 5: Load/Performance Testing of Websites
Preparing for Load Testing
What You Need to Know
Some Helpful Tips to Get Better Results
Using JMeter Components
Recording HTTP Requests
Creating the Test Plan
Adding Listeners
Adding Timers
Running the Test Plan
Interpreting the Results
Remote Testing with JMeter
Monitoring the Server's Performance

Chapter 6: Functional Testing
Preparing for Functional Testing
Using JMeter Components
Using HTTP Proxy Server to Record Page Requests
Configuring the Proxy Server
Adding HTTP Request Default
Adding HTTP Header Manager
Let the Recording Begin...
Adding User Defined Variables
Running the Test

Chapter 7: Advanced Features
Extending the Web Test Plan
Using the ForEach Controller
Using the While Controller and the StringFromFile Function
Using the Loop Controller and the StringFromFile Function
Using Regular Expressions
Testing a Database Server
Testing an FTP Server

Chapter 8: JMeter and Beyond