Posts

Using Selenium WebDriver to select JSF/PrimeFaces selectOneMenu options

I'm using JBehave with Selenium WebDriver to test my PrimeFaces (JSF2) application. Selecting an option from a SelectOne option list isn't standard though because of the HTML markup generated by the JSF component. The facelets code to place the selectOneMenu uses the ID 'state': This generates HTML div blocks with id's prefixed with this components id: To select an option, I use a method which manipulates the appropriate divs - this can be used as illustrated below: To reuse this type of utility method, I put it in a base Page Object class:

Some user feedback

I was exporting my banking transactions the other day. It's a much more tedious process than it has to be and after using this for years and not seeing any updates to the site I thought I'd send some feedback - written as stories: As an Online Banking Customer, I want the system to remember my export preferences so that I can efficiently export my transactions ­  currently I have to set everything every time (even if you navigate from a selected account, you still have to pick an account) ­  file format (i.e CSV) ­  date format (dd/mm/yycc)  As an Online Banking Customer, I want to export transactions for all my accounts in one go so that I can efficiently export my transactions ­ so I don't have to do them one at a time ideally multiple accounts in one file  As an Online Banking Customer, I want to be able to access more than 12 months worth of transactions so that I don't have to export so often. ­  not much history is available online...

Exposing the version of your Maven built web application

Sometimes its useful to expose the version of your web application - I find it useful so vsConsole can display the version of the deployed application for each environment on the dashboard. If you build your app with Maven, you can use this code to get the version, and simply wire up a controller/rest endpoint to return it as text/plain. To expose the version of your maven built spring web application, you can use a REST controller like that shown below. Note, you won't see a valid version while running in the IDE - it'll only work when running the Maven built WAR. If you want to add the Jersey dependencies to your spring application try using the following dependency declaration.

Avoid embedding database connection information in your code

I've seen projects where the application code base contains database connection information - passwords and all, or, WAR files are rebuilt for each environment with properties substituted appropriately for the target environment. Rather than putting database information in the application code, it makes more sense to use a JDNI data source provided by the container. This way the exact same application code is deployed to all environments, and we don't encounter any exposed passwords - since the owner of the container (in production environments the infrastructure/support team) define the data source themselves. Database access via JNDI data source in Tomcat In your application server you want to define a data source which points to the database server and schema of your choice. Here, I'm using the H2 database , and assuming this is the DEV Tomcat server, I point it to the DEV schema - define this resource in the Tomcat context.xml :  <Resource name=" jdbc/...

Deploying to Tomcat 7 with Maven

It's sometimes nice to be able to update a development Tomcat 7 server from Maven - this makes it simple to hook automatic deployment into a CI server or just update the dev server as a developer. First, the Tomcat manager application needs to be installed (check Tomcat's webapps directory for the manager application) and configured with the appropriate user credentials: Now, I needed to define the server admin credentials in my maven settings (~/.m2/settings.xml): Then, I updated the POM to configure the maven tomcat plugin : Now, using 'mvn tomcat7:redeploy' lets me update the dev server. Note however, on Windows you may have some problems with undeploying the application - after an undeploy command, some jars may be left over in the webapps/appname directory. When you try to redeploy your app you'll see an error containing " cannot invoke tomcat manager fail - unable to delete... ". To work around this, you can change the TOMCAT_HOME/...

Exception: AbstractMethodError requires c3p0 upgrade

Image
photo credit: markchadwickart via photopin cc I just encountered this exception: Exception in thread "main" java.lang.AbstractMethodError: com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setCharacterStream(ILjava/io/Reader;J)V at org.hibernate.type.descriptor.sql.ClobTypeDescriptor$4$1.doBind(ClobTypeDescriptor.java:114) at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:92) It turns out that upgrading c3p0 does the trick (from 0.9.1.2 to 0.9.2.1):         <dependency>             <groupId>com.mchange</groupId>             <artifactId>c3p0</artifactId>             <version>0.9.2.1</version>         </dependency>

Week in Review - 2013-16

Print to Google Drive I just noticed 'Save to Google Drive' in my 'Print' options in Chrome! This is awesome - when you want to save something for reference, and you don't want to go through thousands of bookmarks, this is exactly what I wanted! Media Problems Here is a great blog post about trying to find a decent movie streaming service. Now I have FetchTV (this lets me buy movies to stream, much like the Google Play option) I'm considering turning my MythTV media center off, but I still need an option for playing music/displaying photos/etc. There are lots of options, from AppleTV to Western Digital et al media players. Props to Google for actually selling us here in Australia movies and music - unlike Amazon (we still can't buy movies and music from Amazon in 2013). Andrew Chen quits RSS - WTF! Andrew Chen just announced that he's quitting RSS in favour of email notifications. Look at the comments though, and there isn't a single p...