Monday, October 7, 2013

How to handle commandLink in Selenium 2?

My initial assumption on the link is constructed using <a href...="">. Thus when I initiate my test using following code, it was failed unexpectedly.
WebElement clickMe = webDriver.findElement(By.partialLinkText("Click Me"));
clickMe.click();
Why this happened? I have double verify on my code, it just looking fine. But when I view the page’s source, I got the following code in my mind.

    Click Me

Doesn’t it sound funny? Consider the page was build using JSF and the link is construct using commandLink in JSF like this:


I wasn’t sure the background on how JSF is render on the browser. But one thing I am sure is the link has JavaScript. Without further ado, my temporary solution is to workaround the JavaScript using third party library called SeleniumJQuery. It is quite straight forward to use and pretty simple, to click on the link containing JavaScript, do this code:
jQueryFactory jq = new jQueryFactory();
jq.setJs(webDriver);

WebElement clickMe = webDriver.findElement(By.partialLinkText("Click Me"));
jq.query(clickMe).click();
It will work like charm.

AnnotationConfiguration is deprecated?

The SessionManager utility class is the famous one among JAVA programmer who has been working with Hibernate.
public class SessionManager {

 private static final SessionFactory sessionFactory = buildSessionFactory();
 
 private static SessionFactory buildSessionFactory() {
  
  try {
   return new AnnotationConfiguration().configure().buildSessionFactory();
  }
  catch( Throwable e ) {
   
   throw new ExceptionInInitializerError(e);
  }
 }
 
 public static SessionFactory getSessionFactory() {
  return sessionFactory;
 }
}

Unfortunately, I just realize that AnnotationConfiguration has already been deprecated Since Hibernate 3.6. Do you know what is the new implementation of this class? Well, replace this with Configuration.

Do you save login password in Keystore?

I don’t know the real use of Keystore? But I do know it was a file created using keytool provided by JDK. What I’m concern about is do you keep username and credential of a web application in keystore? The feedback I got from forum is not encourage to do so because Keystore is a file, keeping this file somewhere else will create additional vulnerabilities.

Sunday, September 22, 2013

Unity Game Engine first touch

For the past few weeks, I'm not working on the programming whereas I'm spending my time learning Unity Game Engine. The first game I made was a rather simple game where there is a space ship at the bottom of the screen shooting the asteroid coming from the top of the screen. I am quite satisfied with the engine especially on particle system, it makes my life easier when creating the explosion effect. This is not my intention to bring the game to the world since I'm still studying on the game engine, but to get myself familiar with the user interface.

Next I am going to learn to make a Load Runner game, I miss this game when I was still in young. The game development on this time is slightly advance where I am using Orthello, a 2D game framework. Below is my progress for this week, where I have the level design setup.

load_runner_20130922

Sunday, September 1, 2013

'for' attribute is not defined in JSF

Great finding from my colleague. When retrieve systemout.log from WebSphere Application Server, noticed that the following warning seem to be flooding in the log.

Attribute 'for' of label component with id xxxxxxxxxxxxxxxxxxxxxx is not defined 

This warning is due to the missing of attribute 'for' in a component being called. For example,


The purpose is to let the outputlable know which component to label. For suppressing the excessive non-informational logging line, always practise to use the 'for' attribute.

Retrieve IP address from JSF

One of my requirement in audit trail module is to capture the IP address of the user accessing the web application. My web application was developed using JSF, may I know could this be done? Such an easy job, below is the code for this mission:
 HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
 String ipAddress = request.getHeader("X-FORWARDED-FOR");
 if( ipAddress == null ) {
  ipAddress = request.getRemoteAddr();
 }

web-app_3_0.xsd schema is reference from javaee



   ...
   ...
I was clueless when I first saw the above code causing an error in Deployment Descriptor. I was trying to retrieve web-app_3_0.xsd schema but I couldn’t spot the typo error in the above code. If you were me, can you spot the error? If you take a closer look, the error happened on j2ee. It was cause by my copy and paste habit.

http://java.sun.com/xml/ns/j2ee is no longer a valid URL to retrieve JAVA EE 5 (and above) schema, it is only valid for J2EE 1.4. For JAVA EE 5 (and above) schema, the URL has been update to http://java.sun.com/xml/ns/javaee.