Tuesday, May 19, 2009

maven and selenium in linux

i'm currently coding selenium scripts for automating our tests for a portal application.

here are the pom.xml customizations for using selenium server and client




4.0.0
com.spongeduke.tws.portal.webtests
com.spongeduke.tws.portal.webtests
jar
1.0-SNAPSHOT
com.spongeduke.tws.portal.webtests
http://maven.apache.org


1.0-beta-1
2.5.6
4.4






org.openqa.selenium.client-drivers
selenium-java-client-driver
${selenium.version}
test


org.springframework
spring
${spring.version}
test


junit
junit
${junit.version}
test








maven-compiler-plugin

1.5
1.5




org.codehaus.mojo
selenium-maven-plugin



xvfb
pre-integration-test

xvfb


:1




pre-integration-test

start-server


4447
true






org.apache.maven.plugins
maven-surefire-plugin


true



integration-test

test


false










openqa-releases
Openqa Release Repository
http://nexus.openqa.org/content/repositories/releases
default

false


true



openqa-snapshots
Openqa Snapshot Repository
http://nexus.openqa.org/content/repositories/snapshots
default

true
daily
ignore


false








and here's the sample unit test:


/**
* spongeduke (c) 2009
*/
package com.spongeduke.tws.portal.webtests;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestCase;
import com.thoughtworks.selenium.Selenium;

/**
* Sample Selenium Test
*
* @author ctract2
*/
public class SampleSeleniumTest extends SeleneseTestCase {

private Selenium selenium;

public void setUp() {
selenium = new DefaultSelenium("localhost", 4447, "*firefox", "http://localhost:8080");
selenium.start();
}

public void testShouldShowWelcomePage() throws InterruptedException {
selenium.open("/portal");
selenium.waitForPageToLoad("5000");
verifyEquals("spongeduke DevPortal", selenium.getTitle());
verifyTrue(selenium.isTextPresent("spongeduke"));
}

public void tearDown() {
selenium.stop();
}

}


two ways of running the test:

1. using maven
$ mvn integration-test

2. using JUnit Runner in eclipse:
a. start Selenium Server: java -jar selenium-server.jar -port 4447
b. run Selenium Unit Test in eclipse using JUnit Runner

required selenium distribution: selenium-remote-control-1.0-beta-2-dist.zip
and can be downloaded from http://seleniumhq.org/download/

that's all folks!

Monday, May 18, 2009

export command not found

if the command export is not installed in your linux machine, try this:

1. edit .personal file

2. edit and add the following at the end of the file

setenv M2_HOME /usr/share/apache-maven-2.1.0

alias mvn '$M2_HOME/bin/mvn'

3. save the file and launch a new terminal session

Wednesday, May 6, 2009

bypass password prompt in ssh connection

just developed a tool for checking out svn artifacts using the svn + ssh, and had to bypass the password prompt.  to enable this, execute the following commands in the remote server:

$ ssh-keygen -t rsa1
(accept paraphraseless input)

$ ssh-keygen -t rsa
(accept paraphraseless input)

$ ssh-keygen -t dsa
(accept paraphraseless input)

add identity.pub to authorized_keys
$ cat identity.pub >> authorized_keys

add id_dsa.pub to authorized_keys2
$ cat id_dsa.pub >> authorized_keys2

some svn pointers,
checkout: svn co
checkout with revision arg: svn co -r HEAD
checkout with user credentials: --username --password

take note:
in linux, for passwords with escape characters, enclose the password with double quotes and add a \ prefix to the special character (i.e., "ohmy\!password")