Posts Tagged JRuby

Multithreaded Automated UI Testing

Well my latest bit of personal development in the IT world is multithreaded development using scripting languages (as I don’t like waiting for stuff to compile).

Using multithreading as far as UI testing can goes means you can cover a lot in less time.

Where I’m looking at is Python (due to it’s integration with Quality Center) as well as Ruby (because I like the syntax and it offers a language which interacts with the JVM).

An area of interest is probably Jython. If I can get that integrated with a Quality Center VAPI-XP test, then I almost got the best of both worlds.

Tags: , , ,

JDBC/log4j and JRuby

Have been experimental with various Java technologies (At this time, JDBC, reading from properties files and log4j) and tying it all together with JRuby – Which I might add runs also in compiled mode as well.

Simple use of properties files in JRuby involves

# Initialize the properties object from java.util
# Refer to http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html
# on how to use.
properties = java.util::Properties.new
# Make sure that propertyfile exists!
properties.load(java.io.FileInputStream.new("propertyfile.properties"))
puts properties.getProperty("propertykey")

Now for some jdbc action! (The below code is well commented.. Enjoy!)

require 'java' # So we can use the sexy java goodness!
# Make sure you download this from the mysql site! (Link: http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-3.1.10.zip/from/pick)
require 'mysql-connector-java-3.1.10-bin.jar'
import 'com.mysql.jdbc.Driver' # Load the JDBC Driver

# Replace 'conn_string' with the JDBC Connection string (e.g. jdbc:mysql://localhost:3306/DBNAME)
# Replace 'uid' with the database username
# Replace 'pwd' with the database password
conn = java.sql::DriverManager.getConnection(conn_string, uid, pwd);
# Prepared queries are teh win
stmt = conn.prepareStatement("select field from table where otherfield = ?")
stmt.setString(1, "Whatwearesearchingfor") # First param
stmt.executeQuery
while rs.next do
puts rs.getString("field")
end
stmt.close # Because we should close what we open
conn.close # Same as above

And finally, some log4j thrown in!

require 'log4j-1.2.15.jar' # Assume you have already done require java
# The below is how you use log4j controlled by XML
import org.apache.log4j.Logger
import org.apache.log4j.xml.DOMConfigurator
logger = Logger.getLogger("LoggerName") # LoggerName would be defined in the XML file
DOMConfigurator.configure("log4j.xml")
logger.info "This would log an INFO entry if it were configured to be shown"
# Additionally you can use debug, info, warn, error, fatal

The results have been to a good degree of success. All I will need now to create a kickass and open source web frontend testing framework is:

  • Celerity
  • log4j
  • JDBC
  • properties files

I’ve basically got 90% of the functionality of a commercial tool right here!  Schweet!

Tags: , , , ,