Wednesday, February 17, 2010

Recursive search on the filesystem for the content of a log-file

I had the following problem lately:

On a test server I was looking for a log-file on the installation path and/or one of its sub-folders with some information about a "session timeout".

I didn't know the the log-files name, but new, that it had the extension ".log". I also didn't know which exception was was creating the entry. All I had, was the string "session timeout".

With the following Groovy script I could find all the log-files containing the string "session timeout" and from there it was easy to identify the log-file.


def dir = 'C:/some_installation_folder'
def fileExtension = '.log'
def searchString = 'session timeout'

new File(dir).eachFileRecurse() { f ->
if (f.directory) {
def p = ~/.*\${fileExtension}/
f.eachFileMatch(p) { log ->
def exceptions = []

log.eachLine { ln ->
if (ln =~ '.*' + searchString + '.*') {
exceptions << "${ln}"
}
}

if (!exceptions.empty) {
println log
exceptions.each{println " $it"}
}
}
}
}


Enjoy! :)

Tuesday, January 19, 2010

Date Format Fix in Excel 2003

Due to an issue in Excel 2003, sometime the date formats are not updated in the cells, which leads to the problem, that a cell shows a date but is not read as a date by macros and formulas.

You could go through each cell, press 'F2' and 'Enter' and Excel would finally identify the content of the cell as a date. But this you would do manually and not by script.

With the following VBA script for Excel, the format can be updated:


Sub UpdateColumnFormat()

Dim usedRangeOfRows As Integer
usedRangeOfRows = ActiveSheet.UsedRange.Rows.Count

'Date
Columns("A:A").Select
Dim e As Range
Dim currentValueE As Date
For Each e In Range("A2:A" & usedRangeOfRows).Cells
e.Select
currentValueE = ActiveCell.Value
ActiveCell.FormulaR1C1 = currentValueE
Next

End Sub


This problem occurs regularly, when I copy data from one sheet to another by VBA scripts.

With the above script, I could fix (at least work around it) this issue.

Enjoy :)

Monday, January 18, 2010

"Create List..." in Excel 2003 with VBA

While working on data within Excel with VBA, I like to use dynamic lists to address the data and eventually to give it a name.

To create a list, the same one as you would do manually by calling "Create List..." from the context menu, you can execute the VBA script below.


Private Sub CreateList()

Range("A1").Select

Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select

Dim NumberOfColumns As Integer
Dim NumberOfRows As Integer
Dim StartCell As Range
Dim EndCell As Range

NumberOfColumns = ActiveSheet.UsedRange.Columns.Count
NumberOfRows = ActiveSheet.UsedRange.Rows.Count

Set StartCell = Cells(1, 1)
Set EndCell = Cells(NumberOfRows, NumberOfColumns)

Dim DataRange As Range
Set DataRange = Range(StartCell, EndCell)

ActiveSheet.ListObjects.Add(xlSrcRange, DataRange, , xlYes).Name = "List1"
Range(StartCell, EndCell).Select
ActiveWorkbook.Names.Add Name:="Data", RefersToR1C1:=DataRange
Range("Data").Select

End Sub


I also give the list the name "Data", which I do to access the data by name afterwords, but this is not required to create the list.

Enjoy :)

Monday, September 21, 2009

Read File Properties with Excel VBA

The VBA script for Excel below will read the 'File Version' from the file properties and will read file name and its version each into a column in a Excel sheet.


Sub getFileProductVersion()

Dim objShell As Shell
Dim objFolder As Folder
Dim objFolderItems As FolderItems
Dim objFolderItem As FolderItem
Dim numberOfFiles As Long
Dim i As Integer
Dim j As Integer

Set objShell = New Shell
Set objFolder = objShell.Namespace("C:\Temp\files")

If (Not objFolder Is Nothing) Then
Set objFolderItems = objFolder.Items()
numberOfFiles = objFolderItems.Count
Range("A1").Select

For i = 0 To numberOfFiles - 1
Set objFolderItem = objFolderItems.Item(i)
ActiveCell.Offset(i, 0) = objFolderItem.Name
ActiveCell.Offset(i, 1) = objFolder.GetDetailsOf(objFolderItem, 39)
Next i

End If

Set objFolder = Nothing
Set objShell = Nothing

End Sub


Enjoy :)

How to specify the browser that should be used in WebTest

In WebTest it is possible to define which browser shall be simulated. Currently WebTest support the following browsers:
  • Firefox3 (or FF3)
  • Firefox2 (or FF2)
  • InternetExplorer6 (or IE6)
  • InternetExplorer7 (or IE7)
To get a more detailed list, have a look at the WebTest config page (http://webtest.canoo.com/webtest/manual/config.html).

As you can see in the simple example below, it is very easy to define the simulated browser for your test:







'Here goes your test code...'







This example is an extract from a browser test of the self test suite of WebTest. For more details, have a look a the self test suite (https://svn.canoo.com/trunk/webtest/selftests/).

Enjoy :)

Wednesday, August 12, 2009

How to create a WebTest project in less than a minute

Assuming you have WebTest installed you can create a WebTest project in less than a minute:

Go to the directory where you want to create the WebTest project


E.g.:

C:\projects


Call the createProject task and provide a name for the project, e.g. myWebTestProject


C:\projects>ant -f %WEBTEST_HOME%\webtest.xml wt.createProject


Change to the project directory


C:\projects>cd myWebTestProject


Call WebTest


C:\projects\myWebTestProject>webtest


Done :)

Tuesday, August 11, 2009

Functional Testing for Joomla! with WebTest

Joomla! is a very popular open-source CMS based on PHP. It is simple to use and makes creating and maintaining Web sites easy for everyone, from total beginners setting up their first site to IT professionals managing enterprise installations.

Like many other projects (not only open-source projects) testing is not the most popular subject. However, testing is very crucial for every project to be able to grow and handle complexity within the project.

Functional testing is one aspect of testing which can focus on the users perspective of using an application.

I started a functional test suite for Joomla! with Canoo WebTest, an open-source tool for automated testing of web applications in a very effective way.

If you would like to have a look at the current state of the work, see here:
Some initial documentation can be found here:
Enjoy :)

Sunday, December 30, 2007

The Screencast Blog

Today I found the screencast blog, which provides a huge number of screencast which mostly show Eclipse features.

Have a look, it's really interesting:
Enjoy!

Regards,
Tomi

Tuesday, November 13, 2007

WebTest Screencast: Data Driven WebTest

We finally made it :)

Marc Guillemot (http://mguillem.wordpress.com/) and I published the new WebTest (http://webtest.canoo.com/) screencast showing Data Driven WebTest based on Google Calculations.

You can find the screencast here:

New screencasts will follow soon...

Enjoy!

Kind regards,
Tomi

Tuesday, November 06, 2007

Groovy Posts & Links

I'm following the Groovy (http://groovy.codehaus.org/) posts and links on http://www.dzone.com/ and http://del.icio.us/. It is amazing, how the number of posts and saved URL's increased over the last couple months.

If you would like to have a look at these, check the following links...

dzone

del.cio.us

Enjoy reading!

Regards,
Tomi

Monday, October 29, 2007

WebTest vs. Selenium

Marc Guillemot compares the features of two popular open source testing tools: WebTest and Selenium!

A must read post! Very interesting!

[..] The maintainability of automated tests depends primarily on the skills of the test authors, but different tools have different features that impact their efficiency. This blog post compares the features of two open source automated web testing tools: Canoo WebTest and Selenium.

http://mguillem.wordpress.com/2007/10/29/webtest-vs-selenium-webtest-wins-13-5/

Enjoy!

Regards,
Tomi

Monday, September 10, 2007

WebTest Screencast: New cast on its way...

Tonight we (Marc Guillemot and myself) were working on a new screencast for WebTest. The new cast will be about data driven web testing.

I'll try to bring the cast online till end of the week, or at least a first beta version :) As soon as I have it published, I'll post a new blog entry.

Regards,
Tomi

Wednesday, August 22, 2007

WebTest Screencast: Creating a first WebTest project

Marc Guillemot (http://mguillem.wordpress.com/) and myself are working on some screencasts to show WebTest capabilities. The first screencast has been announced on the WebTest mailing list:

and can be found here:

We are looking forward to publish a couple more screencasts within the next few months. If there are special features you would like to see in the upcoming screencast, let me know :)

Enjoy!

Regards,
Tomi

Wednesday, August 08, 2007

Dealing with critics?

There is an interesting post on Marc Guillemot's blog:

He's blog entry can be understood in a way, that the lack of XPath can be associated to the lack of test automation experience. If this relation is correct or not is not as interesting as the reaction which has raised based on his entry.

I'm very surprised, how personal this was taken, especially the comment of Neil: http://mguillem.wordpress.com/2007/07/31/xpath-power-2-detect-lack-of-experience/#comment-16. I would have expected more distance to such a statement and more tolerance.

My understanding of Marc's statement is, that the better an XPath expression is (better in the sense of robust), the better the tests are which might be based on the XPath expression. The first XPath statement Marc is quoting:

is not robust at all. If there a small change in the used tables or additional items in the lists, the test will break. If there is a relationship between robust and better, that this statement is not prefered and in this sense, I can understand the statement of Marc very well.

Regards,
Tomi


Wednesday, December 20, 2006

Groovy in Action

The book "Groovy in Action" is finally out! Have a look, it's worth reading it!

URL:

http://groovy.canoo.com/gina

Description:

Groovy in Action is a comprehensive description of the Groovy programming language, its libraries, and its everyday use. With the release of JSR 241, Groovy has become the second standard language for the Java platform. The book introduces Java developers to the new dynamic features that Groovy brings to this platform.

Enjoy!

Groovy in Action

The book "Groovy in Action" is finally out! Have a look, it's worth reading it!

URL:

http://groovy.canoo.com/gina

Description:

Groovy in Action is a comprehensive description of the Groovy programming language, its libraries, and its everyday use. With the release of JSR 241, Groovy has become the second standard language for the Java platform. The book introduces Java developers to the new dynamic features that Groovy brings to this platform.

Enjoy!

Monday, September 25, 2006

groovy articles on del.icio.us

Since I'm using Groovy in the current project (thanks to Dierk and Marc) I'll start collect articles about groovy...

This might help some other beginners to start with a steeper learning curve as well :)Enjoy!

Read more at del.icio.us/TomiSchuetz...

Monday, August 28, 2006

Groovy: Parsing an XML file with Groovy

Groovy comes with a handy XML parser. With this parser you can load an XML file quickly and navigate it easy.

Currently I'm working with WebTest (http://webtest.canoo.com/) for testing functional aspects of an web application.

WebTest comes with a nice overview to present the results of the test runs. The report itself is transformed out of an XML file. For statistics reason, I'm using this XML file to extract specific data. This extraction is done with a little Groovy script.

To get an idea of the WebTest report XML file, have a look a the fragment below:

WebTestReport.xml:








...










name="resultFilename" value="response_1156746643278_invoke.html"/>
















...



This file can be parsed with the following code:


import java.text.SimpleDateFormat

FormatUS = new SimpleDateFormat('EEE MMM dd hh:mm:ss z yyyy', Locale.US)
FormatDE = new SimpleDateFormat('dd.MM.yyyy hh:mm:ss', Locale.GERMAN)

def folder = args?.size() ? args[0] : "data"
println "reading files from directory '$folder'"
def basedir = new File(folder)

// result files of the current run
files = basedir.listFiles().grep(~/.*xml$/)

List resultLines() {
List result = []
for (currentFile in files) {
println " processing $currentFile"
def summary = new XmlParser().parse(currentFile)

// List with all 'testresult' elements
def testresults = summary.testresult


testresults.each { testcase ->
def entry = [:]
entry.name = testcase.'@testspecname'.split(/\W/)[0]
entry.time = testcase.'@starttime'
entry.time = FormatUS.parse(entry.time)
entry.time = FormatDE.format(entry.time)
entry.ok = testcase.'@successful'

def rt = testcase.depthFirst().findAll { element ->
if (element.name() != 'parameter') return false
if (element.'@name' != 'taskName') return false
def roundtripTags = 'clickLink clickButton clickElement'
roundtripTags.tokenize().contains(element.'@value')
}
entry.roundtrips = rt.size()

def fields = testcase.depthFirst().findAll { element ->
if (element.name() != 'parameter') return false
if (element.'@name' != 'taskName') return false
def fieldsTags = 'selectForm setCheckbox setFileField setInputField setRadioButton'
fieldsTags.tokenize().contains(element.'@value')
}
entry.fields = fields.size()

def verifies = testcase.depthFirst().findAll { element ->
if (element.name() != 'parameter') return false
if (element.'@name' != 'taskName') return false
def fieldsTags = 'verifyCheckbox verifyCookie verifyDocumentURL verifyElement'
fieldsTags.tokenize().contains(element.'@value')
}
entry.verifies = verifies.size()

if (testcase.results.error) {
entry.resultsError = testcase.results.error.'@exception'[0]
} else {
entry.resultsError = ''
}

/*
if (testcase.results.failure) {
entry.resultsFailure = testcase.results.failure.'@message'[0].replaceAll(/\W/, " ")
println "####" + entry.resultsFailure
} else {
entry.resultsFailure = ''
}
*/

def groupSteps = testcase.results.step.findAll { step ->
step.parameter.any { param ->
param.'@name' == 'taskName' && param.'@value' == 'group'
}
}

def goodSteps = groupSteps.findAll{ it.result?.completed }

// assumed: there is always at least one group step, size() never 0
if (groupSteps.size() != 0) {
entry.complete_pct = goodSteps.size() / groupSteps.size()
} else {
entry.complete_pct = 0
}

if (goodSteps) {
entry.description = goodSteps[-1].parameter.findAll{it.'@name'=='description'}.'@value'[0]
} else {
entry.description = ''
}

result <<>
writer <<
"Testfall\t" <<
"Datum\t" <<
"Erfolgreich\t" <<
"Prozent\t" <<
"Error\t" <<
"Server Roundtrips\t" <<
"Number of Fields\t" <<
"Verifications\t" <<
"Beschreibung\n"
for (entry in resultLines()) {
writer <<
entry.name << "\t" <<
entry.time << "\t" <<
entry.ok << "\t" <<
entry.complete_pct << "\t" <<
entry.resultsError << "\t" <<
entry.roundtrips << "\t" <<
entry.fields << "\t" <<
entry.verifies << "\t" <<
entry.description << "\n"
}
}


Now you get a tab seperated file with the content of your result files from the web testing runs. I
import this file into Excel and create a pivot table to understand the results better.

I hope this helps :)

Friday, August 25, 2006

Groovy: Get all XML files from a directory tree

Currently I'm working in a project, where Groovy (a dynamic scripting language for the JVM) is used. One of the project members is Dierk König, which is a Groovy commiter and the author of Groovy in Action. This gives a real insight in the beauty of Groovy :)

Below you can see a nice solution for finding all XML files in a directory tree:


// pass a directory or use the current directory
def folder = args?.size() ? args[0] : "."
println "reading files from directory '$folder'"
def basedir = new File(folder)

// result files of the current run
files = basedir.listFiles().grep(~/.*xml$/)

List resultLines() {
List result = []
for (currentFile in files) {
println " processing $currentFile"
}
return result
}

Monday, August 14, 2006

GWT Widget Library

Google released a new version of GWT today, version 1.1.0. There were some API changes made that broke a few things in the GWT-WL, namely the FormPanel and SVG support. This release is to make the GWT-WL compatible with the latest GWT release. Below are a list of changes...

[from the site]

Read more at gwt-widget.sourceforge....

Friday, August 11, 2006

Eclipse Summit Europe 2006

The Eclipse Summit Europe will take place in Esslingen, Germany from October 11-12, 2006

Read more at www.eclipsecon.org/summ...

Eclipse 3.3 M1 - New and Noteworthy

It's amazing, how fast the Eclipse people work! Thanks to all of them :)

Read more at download.eclipse.org/ec...

Tuesday, August 08, 2006

Lint4j Maven Plugin - Lint4j

Lint4j comes with a Maven Plugin that simplifies generation of reports significantly.

I'll have to check this plugin with WebTestClipse ...

Read more at www.jutils.com/maven-pl...

dzone.com

An interesting site for developers. It's similar to del.icio.us and stumbleupon , but more focused on developers.

I like these community driven sites, because it allows me to find high quality sites.

Read more at www.dzone.com/

Thursday, August 03, 2006

SourceForge.net: WebTestClipse

I added WebTestClipse as a project to Sourceforge.net ( http://sourceforge.net/projects/webtestclipse/ ). The idea is, to use Sourceforge.net as a portal and to redirect to http://webtestclipse.canoo.com/ where the project is hosted and developed...

Read more at sourceforge.net/project...

Friday, July 28, 2006

Setting up the master Maven 2 project for WebTestClipse - Install Maven 2

I'm setting up the master Maven 2 project for WebTestClipse . You can follow these steps to set up any kind of project.In this post I'll descripe the installation of Maven 2, based on links and some minor notes. It's not to be considered to be a complete installation guide.

1.) Download Maven 2

Download Maven 2 from http://maven.apache.org/download.html and chose the right distribution. I'm using http://www.apache.org/dyn/closer.cgi/maven/binaries/maven-2.0.4-bin.zip .

2.) Unpack Maven into a local directory

I've chosen C:\dev\maven-2.0.4 as my Maven 2 home directory.

3.) Environment Variable

Define a %MAVEN_HOME% variable and extend the %PATH% variable. This will make it possible to call Maven 2 commands from the command line

4.) Test your Installation

Testing the installation is fairly simple. Just call a Maven 2 command from the command shell:

mvn -v

As a result you should see:

Maven version: 2.0.4

Joined WebTestClipse

I joined the WebTestClipse project. The goal of the project is to provide a set of Eclipse features and plugins to develop tests for WebTest .

Read more at webtestclipse.canoo.com...