Home > tech > Automated Smoke Tests With Selenium, Cargo, TestNG and Maven

Automated Smoke Tests With Selenium, Cargo, TestNG and Maven

In the project I am working on right now, we have decent amount of unit tests. Some of the unit tests launch an in-memory HSQL DB and run the tests against them – this helps us catch bugs in schema, Hibernate mapping etc. We use a Continuous Integration server which checks out code from the repository every hour and runs the tests. This setup helps us catch some kind of bugs early, but some other errors still can happen – for example, errors in web.xml, javascript errors etc.

Also, we frequently deploy newer releases to QA. Before making a release, we do a “smoke test” where one of us runs through the major functional areas of the application. Sometimes we encounter bugs at this stage. The development web server is Jetty, but all deployments from QA upwards happen on Tomcat – minor incompatibilities between Jetty and Tomcat are identified very late, usually when the smoke test is run right after a deployment.

I devised a mechanism to run an automated smoke test, and I will describe the process here.

The tools we use for this are:

  1. Maven: The build tool we use
  2. Selenium Remote Control: A package which lets one programatically control a browser, mimicking the actions of a real user
  3. Cargo: A package which lets one programatically control a server
  4. TestNG: A test framework

All the above tools are available free and open source. This is not an exhaustive tutorial on any of these tools. All I intend to do is show how these can be used together to write a smoke test process. I have broken down the integration of these tools into eight steps. This tgz bundle contains the files needed for each step – kindly rename the file to steps.tar.gz (without the .pdf extension) and uncompress it to your local disk.
Note:I do not discuss creating the database schema for the test.

Step 0: Application under test
The web application we are going to test is a very simple one. On the first page there is a link, and when a user clicks on it she is taken to a form. The form is a simple Celsius-Fahrenheit converter; on submitting the form the user is shown the result of the conversion, and she is shown the form again so that she can try another conversion. There is a link at the bottom of the form which takes the user back to the index page. The application is developed using WebWork.
To run this app, get the file, uncompress it to your local disk, run:

steps/step0/mywebapp> mvn jetty:run

and open http://localhost:8080/mywebapp/index.html on your browser.

Note: If you have not worked on Maven before, setting it up is real easy. Download the package from the project website, unzip it somewhere on your local disk, add a system variable MAVEN_HOME pointing to where you have installed Maven, and add $MAVEN_HOME/bin to the PATH. You can verify the installation by running mvn -v, which is expected to print the Maven version on the console.

Step 1: Configure an integration test suite
We create a new module, functest, to hold our functional tests. We configure for the following in the functest/pom.xml:

  1. test sources are within src/it
  2. tests are to be compiled with JDK5
  3. tests are to be run during the integration-test phase of the build

Also note that the packaging is set to pom.

<project ..>
  ..
  <packaging>pom</packaging>
  ..
  <build>
    <testSourceDirectory>src/it</testSourceDirectory>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <executions>
          <execution>
            <phase>integration-test</phase>
            <goals>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

To verify that our setup works, run:

steps/step1/functest> mvn integration-test
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building functional-tests
[INFO]    task-segment: [integration-test]
[INFO] ----------------------------------------------------------------------------
[INFO] [compiler:testCompile {execution: default}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [compiler:testCompile {execution: default}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [site:attach-descriptor]
[INFO] [surefire:test {execution: default}]
[INFO] No tests to run.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9 seconds
[INFO] Finished at: Thu Dec 07 22:49:54 IST 2006
[INFO] Final Memory: 4M/10M
[INFO] ------------------------------------------------------------------------

Step 2: Configure TestNG
Next let us configure TestNG to work well with Maven. We change the functest pom.xml to:

  1. add TestNG as a test-scoped dependency
  2. specify the 2.8-SNAPSHOT version of surefire plugin, because that is the one that works well with TestNG
  3. add TestNG-specific configuration for surefire plugin
<project ..>
  ..
  <dependencies>

    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>5.1</version>
      <scope>test</scope>
      <classifier>jdk15</classifier>
    </dependency>
  </dependencies>

  <build>
    <testSourceDirectory>src/it</testSourceDirectory>
    <plugins>
    ..
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        ..
        <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>src/it/testng.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

We also add a test, com.mycompany.app.functest.FirstTest, which is a simple TestNG test. Notice:

  1. the use of Java5 static imports
  2. the @Test annotation that marks a method as a test
package com.mycompany.app.functest;

import static org.testng.Assert.*;
import org.testng.annotations.Test;

public class FirstTest {

  @Test
  public void shouldPass() {
    assertTrue(true);
  }
}

Also notice the functest/src/it/testng.xml file which groups all tests in com.mycompany.app.functest package as functionalTests.

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="seleniumTests">
  <test name="functionalTests">
    <packages>
      <package name="com.mycompany.app.functest" />
    </packages>
  </test>
</suite>

Let us verify that our setup is good; if everything is configured properly you should notice that your simple TestNG test has passed.

steps/step2/functest> mvn integration-test
..
Running functionalTests
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.137 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
..

Step 3: Configure Selenium RC
Next let us configure our tests to use Selenium RC. We add the Selenium RC client driver as a dependency in the functest/pom.xml.

<project ..>
  ..
  <dependencies>
    <dependency>
      <groupId>org.openqa.selenium.client-drivers</groupId>
      <artifactId>selenium-java-client-driver</artifactId>
      <version>0.9.0</version>
      <scope>test</scope>
    </dependency>
  ..
  </dependencies>
  ..
</project>

The Selenium RC client driver is a package that provides an abstraction for a browser window. We change our earlier test to launch a firefox browser window using Selenium RC.

@Test
public void shouldPass() {
  Selenium selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://localhost:8080/");
  selenium.start(); // launch a brower window
  selenium.stop(); // close the browser window
}

To run this test, we need to first start the Selenium RC server. The Selenium RC client driver communicates with the server; the server performs the actual task of launching of the browser and controlling it. Download Selenium RC server 0.9.0 version from OpenQA repository and launch the jar:

> java -jar selenium-server-0.9.0.jar
application/xhtml+xml
Dec 7, 2006 9:56:01 PM org.mortbay.http.HttpServer doStart
INFO: Version Jetty/0.9.0
Dec 7, 2006 9:56:01 PM org.mortbay.util.Container start
INFO: Started HttpContext[/,/]
Dec 7, 2006 9:56:01 PM org.mortbay.util.Container start
INFO: Started HttpContext[/selenium-server,/selenium-server]
Dec 7, 2006 9:56:01 PM org.mortbay.util.Container start
INFO: Started HttpContext[/selenium-server/driver,/selenium-server/driver]
Dec 7, 2006 9:56:01 PM org.mortbay.http.SocketListener start
INFO: Started SocketListener on 0.0.0.0:4444
Dec 7, 2006 9:56:01 PM org.mortbay.util.Container start
INFO: Started org.mortbay.jetty.Server@6672d6

This will launch the Selenium RC server on port 4444.
Note: Make sure that firefox executable is on the PATH of the command window from where Selenium RC server is launched.
Now, in another command window, run:

steps/step3/functest> mvn integration-test

If everything is set up fine, you would be seeing a Firefox browser open and close.

Step 4: Test for the title of the index page
So far we got the browser to launch, but we have not tested if the application is working fine. Now let us write a test which launches a browser, opens the index page of the application, and verifies the title of the index page.

selenium.start();
selenium.open("http://localhost:8080/mywebapp/index.html");
selenium.waitForPageToLoad("5000");
assertEquals(selenium.getTitle(), "My WebWork Application");

Notice the use of Selenium RC client driver API to direct the browser to a particular URL, wait for the page to load, and geting the browser title string.
To run this test we need to start the application. On a new command window, run:

steps/step4/mywebapp> mvn jetty:run

In another command window, run:

steps/step4/functest> mvn integration-test

If everything is fine, you should see a browser open, load the index page, and close. You should also notice that the test passes. To test that this assertion really works, change the assertion, run the test again, and verify that the test fails.
Note: Make sure that the Selenium RC server from step 3 is running.

Step 5: Adding one more test
Now we add another test to click on the link on the index page of the app, and verify that the page with the form comes up. We also refactored the opening and closing of the browser into seperate methods. We annotate these methods – openBrowser & closeBrowser – such that they are run before and after the tests respectively.

@BeforeTest
public void openBrowser() {
  selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://localhost:8080/");
  selenium.start();
}

@AfterTest
public void closeBrowser() {
  selenium.stop();
}

@Test
public void indexPageShouldComeUp() {
  ..
}

@Test
public void converterPageShouldComeUp() {
  ..
}

Verify that our refactoring and new test works by running:

steps/step5/functest> mvn integration-test

Note: Make sure you have the Selenium RC server and Jetty server running still.

Step 6: Starting and stopping Selenium RC server from the test
So far we have had Selenium RC server running in a command window. First step towards true automation start and stop the server from within the test. Firstly, stop the Selenium RC server running. We need to start the Selenium RC server before any tests are run, and we need to shutdown the Selenium RC server after all tests are run. TestNG’s @BeforeSuite and @AfterSuite annotations enable us to do so.

@BeforeSuite
public void startSeleniumServer() throws Exception {
  seleniumServer = new SeleniumServer(4444);
  seleniumServer.start();
}

@AfterSuite
public void stopSeleniumServer() throws Exception {
  seleniumServer.stop();
}

We need to add Selenium RC server as a test-scoped dependency to our functest project.

<project ..>
  ..
  <dependency>
    <groupId>org.openqa.selenium.server</groupId>
    <artifactId>selenium-server</artifactId>
    <version>0.9.0</version>
  </dependency>
  ..
</project>

Run:

steps/step6/functest> mvn integration-test

and verify that this works.
Note: Make sure that you have shutdown the Selenium RC server started earlier.

Step 7: Controlling a Tomcat server from the test
Our tests still need a Tomcat server running. It would be really useful if we could start the Tomcat server, deploy our application onto the server, run the tests and eventually shutdown server. We use Cargo to let us do this – Cargo has a maven plugin which can be configured in functest pom to achieve this. The plugin download Tomcat binary from the web, installs it, deploys our web application onto it. After the tests are run, the plugin stops the Tomcat instance too.

<project ..>
  ..
  <dependencies>

    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>mywebapp</artifactId>
      <version>${project.version}</version>
      <type>war</type>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.openqa.selenium.server</groupId>
      <artifactId>selenium-server</artifactId>
      <version>0.9.0</version>
    </dependency>
    ..
  </dependencies>

  <build>
  ..
    <plugins>
    ..
      <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <version>0.3-SNAPSHOT</version>
        <configuration>
          <wait>false</wait>
          <container>
            <containerId>tomcat5x</containerId>
            <zipUrlInstaller>
              <url>

http://www.apache.org/dist/tomcat/tomcat-5/v5.5.16/bin/apache-tomcat-5.5.16.zip

              </url>
              <installDir>${installDir}</installDir>
            </zipUrlInstaller>
            <output> 
              ${project.build.directory}/tomcat5x.log
            </output>
            <log>${project.build.directory}/cargo.log</log>
          </container>
          <configuration>
            <home>
              ${project.build.directory}/tomcat5x/container
            </home>
            <properties>
              <cargo.logging>high</cargo.logging>
              <cargo.servlet.port>8080</cargo.servlet.port>
            </properties>
          </configuration>
        </configuration>
        <executions>
          <execution>
            <id>start-container</id> 
            <phase>pre-integration-test</phase>
            <goals>
              <goal>start</goal>
              <goal>deploy</goal>
            </goals>
            <configuration>
              <deployer>
                <deployables>
                  <deployable>
                    <groupId>${project.groupId}</groupId>
                    <artifactId>mywebapp</artifactId>
                    <type>war</type>
                    <pingURL>http://localhost:8080/mywebapp/index.html</pingURL>
                    <pingTimeout>300000</pingTimeout>
                    <properties>
                      <context>mywebapp</context>
                    </properties>
                  </deployable>
                </deployables>
              </deployer>
            </configuration>
          </execution>
          <execution>
            <id>stop-container</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>stop</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Notice that we added our web application as a dependency to functest project.
Close the Tomcat server that was started earlier, and run the tests once again:

steps/step7/functest> mvn integration-test

If we have done things alright, tests should pass sucessfully.

Step 8: Running tests on multiple browsers
Right now our tests only run in Firefox. If we want to run it another browser, we need to change the third parameter to constructor of DefaultSelenium. TestNG allows parameters to be passed to @BeforeTest method, so we make use of that.

@BeforeTest
@Parameters({ "browser" })
public void openBrowser(String browser) {
  selenium = new DefaultSelenium("localhost", 4444, "*"  + browser, "http://localhost:8080/");
  selenium.start();
}
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="seleniumTests">
  <test name="IEFunctionalTests">
    <parameter name="browser" value="iexplore"/>
    <packages>
      <package name="com.mycompany.app.functest" />
    </packages>
  </test>
  <test name="FireFoxFunctionalTests">
    <parameter name="browser" value="firefox"/>
    <packages> 
      <package name="com.mycompany.app.functest" />
    </packages>
  </test>
</suite>

We add one more test, which checks if the basic convertion works

@Test
public void zeroCelsiusShouldBeEqualTo32Fahrenheit() {
  assertEquals(convertToFahrenheit(0.0), 32.0);
}       
private double convertToFahrenheit(double f) {
  selenium.open("http://localhost:8080/mywebapp/index.html");
  selenium.waitForPageToLoad(TIMEOUT);
  selenium.click("id=converter");
  selenium.waitForPageToLoad(TIMEOUT);
  selenium.type("//input[1]", Double.toString(f));
  selenium.select("id=temperature_convertTo", "label=fahrenheit");
  selenium.click("id=temperature_0");
  selenium.waitForPageToLoad(TIMEOUT);

  String result = selenium.getText("//p[1]");
  String expectation = f + "C converts to ";
  assertTrue(result.startsWith(expectation));

  result = result.substring(expectation.length());
  result = result.substring(0, result.length() - 1);
  return Double.valueOf(result);
}

Notice that we abstracted the form submision into a private method – this enables us to use the code that performs the actual form submit in many tests.

Thats it! :-) We can use this setup in a Continuous Integration server. It will download Tomcat from the web (only once!), install it, deploy our web application onto it, start Selenium RC server, open a browser window, test drive the application on the browser, close the browser window, stops Selenium RC server and eventually stops Tomcat server.

About these ads
Categories: tech
  1. December 11, 2006 at 12:49 am | #1

    Have you by chance figured out how to run this headless on linux? e.g. without a xserver running.

  2. December 11, 2006 at 4:14 am | #2

    Nope. I have tried this only on Windows PCs. On the Selenium RC Wiki page http://wiki.openqa.org/display/SRC/Selenium-RC+and+Continuous+Integration
    they mention:

    “Use Xvfb (X Windows Virtual Frame Buffer): If you want to run Selenium on a Unix server- without an X Windows display- or if you just don’t want to see the web browser windows popping up, use xvfb. This is an X server that just runs in memory, without a display.”

  3. Dennis
    December 12, 2006 at 3:52 pm | #3

    Very good, and very helpful. Well done.

    What I was wondering: Do you have any experience in setting the database in an initial state?

    Also, I have some problems with existing tomcat configurations. To be more precise. I’d like to deploy my container and then copy some configuration (property files) to the tomcat/conf folder and put some jars (like log4j) in my tomcat/common/lib folder. How can I do this with Cargo?

  4. December 13, 2006 at 9:42 am | #4

    Thank you, Dennis.

    > Do you have any experience in setting the database
    > in an initial state?
    We use a simple mechanism right now. We use Hibernate for ORM, and we use Hibernate utilities to recreate the schema based on our entities. We have our seed data defined in a bunch of excel files – one file per functional area. Each of these files have many worksheets. The name of the worksheet needs to be the name of the DB table; the first row of the sheet is the name of the columns in that table; all other rows contain data. We use DBUnit to populate the database with these Excel files. We invoke the Hibernate and DBUnit utilities with the appropriate DataSource – and once they are executed our (test) database is ready to be used.

    A migration framework would have been better, but we haven’t yet reached the need for it, and hence havent integrated one into the application. Some approaches that can be used are discussed at http://www.infoq.com/news/ruby-migrations-java.

    Please let me know your thoughts on this.

    > I’d like to deploy my container and then copy some
    > configuration (property files) to the tomcat/conf folder
    > and put some jars (like log4j) in my tomcat/common/lib
    > folder. How can I do this with Cargo?

    I don’t think Cargo supports this.

  5. December 15, 2006 at 2:17 am | #5

    Dennis,

    I use a baseline database to run my tests against. We use oracle but I know you can use an export of mysql as a baseline.

    I would recommend a scripted approach for your need at this time.

    -Doyle

  6. kristof
    January 4, 2007 at 9:46 am | #6

    Hi,

    the maven eclipse plugin does not generate eclipse project files for pom modules (in this case the functest module). My workaround is to set the packaging to jar, then generate the project files, then reset packaging to pom. Did you use eclipse? Any better way to do this?

  7. January 4, 2007 at 10:26 am | #7

    Yes, I used Eclipse to create those projects and I also ran into the same issue. :-) My workaround was the same as yours – comment out the pom element, run mvn eclipse:eclipse, and then uncomment the element.

  8. Bashar A.J
    January 29, 2007 at 9:39 pm | #8

    Good job, I have a few comments though:

    1- Your integration-test phase should exclude any tests that might run in the test phase or you will end up running your unit tests again in the integration-test phase.
    2- Same goes for your test-phase, it should exclude any integration tests.
    3- You don’t have to use cargo m2 plugin to start and stop your tomcat server, you can achieve the same result using Cargo Java API and put the code in your @BeforeSuite method.
    4- I implemented something similar to what you did using JUnit as a testing framework. I had to use JUnit as it was a requirement, but I agree with you that using TestNG is much cleaner (and easier to implement).

  9. January 30, 2007 at 3:00 am | #9

    Thanks Bashar!
    1 & 2: I have assumed that the functest module contains only integration tests. This module is a sibling of the webapp module. All unit tests would be put in the webapp module.
    3: Agreed. If I can start the Selenium RC server from code, there really is no good reason to insist on starting Tomcat with the Cargo plugin. :-) But I would have preferred to start both SRC and TC using a Maven plugin.

  10. Zlukacs
    February 1, 2007 at 7:25 pm | #10

    This rocks, dude!

  11. Bashar AJ
    February 5, 2007 at 4:29 pm | #11
  12. vata
    March 20, 2007 at 4:22 am | #12

    FIrst, sorry for my pool english.
    I’m just trying to follow your steps and currently in step 3 and found an error message:
    ===========================================
    $ java -jar selenium-server-0.9.0.jar
    application/xhtml+xml
    Mar 20, 2007 11:37:57 AM org.mortbay.http.HttpServer doStart
    INFO: Version Jetty/0.9.0
    Mar 20, 2007 11:37:57 AM org.mortbay.util.Container start
    INFO: Started HttpContext[/selenium-server/driver,/selenium-server/driver]
    Mar 20, 2007 11:37:57 AM org.mortbay.util.Container start
    INFO: Started HttpContext[/selenium-server,/selenium-server]
    Mar 20, 2007 11:37:57 AM org.mortbay.util.Container start
    INFO: Started HttpContext[/,/]
    Mar 20, 2007 11:37:57 AM org.mortbay.http.SocketListener start
    INFO: Started SocketListener on 0.0.0.0:4444
    Mar 20, 2007 11:37:57 AM org.mortbay.util.Container start
    INFO: Started org.mortbay.jetty.Server@156ee8e
    Mar 20, 2007 11:39:31 AM org.mortbay.util.FileResource
    INFO: Checking Resource aliases
    GET: cmd=getNewBrowserSession&1=*firefox&2=http%3A%2F%2Flocalhost%3A9090%2F
    customProfileDir = c:\temp\customProfileDir971859
    Extracting /customProfileDirCUSTFF to c:\temp\customProfileDir971859
    Preparing Firefox profile…
    Mar 20, 2007 11:39:53 AM org.mortbay.http.HttpConnection exception
    WARNING: GET /selenium-server/driver/?cmd=getNewBrowserSession&1=*firefox&2=http
    %3A%2F%2Flocalhost%3A9090%2F HTTP/1.1
    java.lang.RuntimeException: Firefox refused shutdown while preparing a profile
    at org.openqa.selenium.server.browserlaunchers.FirefoxCustomProfileLaunc
    her.waitForFullProfileToBeCreated(FirefoxCustomProfileLauncher.java:261)
    at org.openqa.selenium.server.browserlaunchers.FirefoxCustomProfileLaunc
    her.launch(FirefoxCustomProfileLauncher.java:135)
    at org.openqa.selenium.server.browserlaunchers.AbstractBrowserLauncher.l
    aunchRemoteSession(AbstractBrowserLauncher.java:24)
    at org.openqa.selenium.server.SeleniumDriverResourceHandler.getNewBrowse
    rSession(SeleniumDriverResourceHandler.java:470)
    at org.openqa.selenium.server.SeleniumDriverResourceHandler.doCommand(Se
    leniumDriverResourceHandler.java:316)
    at org.openqa.selenium.server.SeleniumDriverResourceHandler.handleComman
    dRequest(SeleniumDriverResourceHandler.java:296)
    at org.openqa.selenium.server.SeleniumDriverResourceHandler.handle(Selen
    iumDriverResourceHandler.java:129)
    at org.mortbay.http.HttpContext.handle(HttpContext.java:1530)
    at org.mortbay.http.HttpContext.handle(HttpContext.java:1482)
    at org.mortbay.http.HttpServer.service(HttpServer.java:909)
    at org.mortbay.http.HttpConnection.service(HttpConnection.java:816)
    at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:982)
    at org.mortbay.http.HttpConnection.handle(HttpConnection.java:833)
    at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:
    244)
    at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
    at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
    Caused by: org.openqa.selenium.server.browserlaunchers.FirefoxCustomProfileLaunc
    her$FileLockRemainedException: Lock file still present! c:\temp\customProfileDir
    971859\parent.lock
    at org.openqa.selenium.server.browserlaunchers.FirefoxCustomProfileLaunc
    her.waitForFileLockToGoAway(FirefoxCustomProfileLauncher.java:219)
    at org.openqa.selenium.server.browserlaunchers.FirefoxCustomProfileLaunc
    her.waitForFullProfileToBeCreated(FirefoxCustomProfileLauncher.java:259)
    … 15 more
    GET: cmd=testComplete
    Got result: ERROR: No launcher found for sessionId null on session null

    ============================
    I am just new using this framework, and I’ve tried to search in selenium forums about this error and found nothing.

    My environment: I run on windowsXP SP2, and I can run firefox from the command console(I expected this approve that I have added firefox in my local PATH).

    If you could give a little enlightment, I would be thankful

  13. vata
    March 20, 2007 at 4:37 am | #13

    Sorry, I found that it works on firefox 1.x but mine is 2.x. I think it was all about the uncompatible version. CMIIW

  14. March 20, 2007 at 5:57 am | #14

    Vata,

    When FF2 came out, I did notice some Selenium functionality breaking. But Selenium folks had fixed it soon too. So, I think you should either user FF1.5 or upgrade to a later version of Selenium.

    With Maven upgrading should be real easy – just change the version number in the pom.xml.

    org.openqa.selenium.client-drivers
    selenium-java-client-driver
    0.9.1-SNAPSHOT
    test

    org.openqa.selenium.server
    selenium-server
    0.9.1-SNAPSHOT

    ..

    0.9.1-SNAPSHOT was the latest version I could find in OpenQA Maven Repository at http://maven.openqa.org/org/openqa/selenium/.

  15. May 24, 2007 at 3:56 pm | #15

    binil,

    can you explain me how your tests are structured. In my case, I try to do a class for each scenario. I will have multiple scenarios for testing all my application. Do you declare a Selenium object by scenario so you have to connect and deconnect for each one ?

    Can we talk about this by mail ?

    Regards.

  16. Dhrubo
    May 28, 2007 at 9:39 pm | #16

    This article really helped me. It is the only place where i could find solutions and get my TESTNG+MAVEN+SUREFIRE the deadliest combination to work

  17. selniumtester
    June 1, 2007 at 10:53 pm | #17

    Any body having memory issues with running multiple instances of selenium testsuites?

    my scripts are using lot of memory, what option do i have to use for garbage collection

  18. Tatyana
    October 11, 2007 at 10:27 pm | #18

    We have unit tests launch an in-memory HSQL DB and run the tests against them
    jdbc:hsqldb:${jboss.server.data.dir}${/}hypersonic${/}localDB

    org.hsqldb.jdbcDriver

    and I have problem configuring the datasource,
    EntityManagerFactory emf = Persistence.createEntityManagerFactory(“XXXXXXXXXXXXX”);
    EntityManager em = emf.createEntityManager();
    Please help.

  19. Tony
    November 20, 2007 at 10:04 pm | #19

    Here’s one way you can start and stop the Selenium Server automatically when using TestNG.
    It uses one test class: IReporterSeleniumTest.class and includes a test listener: ISeleniumTestListener. If you do it this way, you don’t even need a testng.xml file.

    import org.testng.*;
    import org.openqa.selenium.server.SeleniumServer;

    class foo{
    public static void main(String[] Args) {
    //Start Selenium Server
    SeleniumServer ss = null;
    try{
    ss = new SeleniumServer();
    ss.start();
    }catch(Exception e){
    //TODO: handle exception
    }

    //Run testNG
    ISeleniumTestListener listener = new ISeleniumTestListener();
    TestNG testng = new TestNG();
    testng.setTestClasses(new Class[] { IReporterSeleniumTest.class });
    testng.addListener(listener);
    testng.run();

    //Stop Selenium Server
    if(ss != null){
    ss.stop();
    }
    }
    }

  20. Rusty
    March 6, 2008 at 11:53 pm | #20

    Thats a wonderful article… Great job!!

  21. Shyla
    May 16, 2008 at 5:44 pm | #21

    I have a question on the step7 where we try to integrate tomcat in maven build. I tried to do that and I am getting this error during build. For me web-3.1-SNAPSHOT.war is built after this build is finished. So, I think I am having a chicken and egg situation. How can I avoid that?

    [INFO] ————————————————————————
    [ERROR] BUILD ERROR
    [INFO] ————————————————————————
    [INFO] Failed to resolve artifact.

    Missing:
    ———-
    1) com.sn.esearch:esearch:war:3.1-SNAPSHOT

    Try downloading the file manually from the project website.

    Then, install it using the command:
    mvn install:install-file -DgroupId=com.sn.esearch -DartifactId=esearch \
    -Dversion=3.1-SNAPSHOT -Dpackaging=war -Dfile=/path/to/file

    Path to dependency:
    1) com.sn.esearch:web:war:3.1-SNAPSHOT
    2) com.sn.esearch:esearch:war:3.1-SNAPSHOT

    ———-
    1 required artifact is missing.

    for artifact:
    com.sn.esearch:web:war:3.1-SNAPSHOT

  22. May 16, 2008 at 6:39 pm | #22

    Shyla,

    From what you wrote I gather that you need to deploy the WAR onto Tomcat *before* the WAR is even built! A moments reflection will convince you that this is next to impossible. Is there reason why you want it this way? Are you doing this to ensure that the war you build is always a “good one” that passes some smoke test? If so, you could order the dependency to build the war first, then deploy it. The build succeeds if and only if the war is built properly *and* it is deployable onto TC.

    Thanks,
    Binil

  23. Shyla
    May 16, 2008 at 8:45 pm | #23

    Yes.. I am doing this to ensure that the war you build is always a “good one” that passes some smoke test. I haven’t used/done POM with dependency to build first and then deploy. I will look into it. But meanwhile, if you have any samples like that, can you send that to me?

    Thanks,
    Shyla

  24. Shyla
    May 19, 2008 at 2:36 pm | #24

    Please ignore my last comment. One of my colleague found a way to do that in a different project. I am trying that now.

    Thanks,
    Shyla.

  25. July 13, 2008 at 3:12 am | #25

    A very informative article. I also enjoyed your other article on taking automated screenshots with Selenium.
    BTW: Why did you choose TestNG over JUnit?

  26. July 19, 2008 at 8:46 pm | #26

    Angsuman, when I first developed this technique JUnit 4 was not yet available. I needed features like @BeforeTest, so I chose TestNG.

  27. Behrang
    August 4, 2008 at 7:29 am | #27

    Nice article. Thanks.

  28. Andre
    December 3, 2008 at 8:22 pm | #28

    Thanks for showing how to automate SeleniumServer!

  29. Andre
    December 3, 2008 at 8:44 pm | #29

    BTW, have you ever seen the automated SeleniumServer cause a system to slow down? My test runs great with a SeleniumServer command line, but speed degrades quite quickly if I start the server per your method above.

  30. December 3, 2008 at 9:01 pm | #30

    Andre, Selenium in general is sluggish, but I have not noticed the method above being slower than the command line option. One thing you might have to investigate is the heap size of the Maven JVM – check if the VM is thrashing memory (set MAVEN_OPTS=-Xmx.. to control the heap size).

  31. ramu
    January 12, 2009 at 6:36 pm | #31

    Is there a way we can automate the capturing of the console log when maven commands run. This is very important when we want to automate the tests and run attended?

    Basically, the question is, is there a plug-in feature which automatically log stdout and stderr to a log file configured in the plug-in section?

  32. Keith
    January 13, 2009 at 5:20 pm | #32

    Hi,

    We are doing almost all of this – not smoke, but using Selenium, testng, tomcat, and maven to do integration tests (we are slowly expanding to do the entire build and release process)

    Looking at adding Hudson to the process – but running into problems and I’m not really up on a lot of this – we need to stop tomcat and clear the database before tests are run, but the app we are testing (not currently deployed by Maven, but will be) locks onto the db and does not allow manipulation while running. Our solution is to uses the exec plug in to stop Tomcat, drop and recreate an empty database (or import a backup file with the db we want to test with) then restart tomcat.

    Because Hudson runs as a tomcat app – which captures the output log files BTW to answer Ramu’s question in comment 34 – I’m looking at cargo as a way to just stop our app, and not tomcat. Currently our set up works ok as command line or from eclipse, but the point where tomcat is stopped kills Hudson which kills Maven.

    One solution is to have a second instance of Tomcat running on different ports to handle Hudson, but I was wondering what was required in Maven to stop and restart one Tomcat application.

    Help such as pointing to a link with this info would be very appreciated.

  33. Jamel
    February 26, 2009 at 12:06 am | #33

    Hi!
    A very helpfull article.

    Please, could you upload the source used in your article.

    I’m not able to download the pdf file.

    Thanks.

    Jamel

  34. Wendy Dou
    April 22, 2009 at 7:52 pm | #34

    Hi Binil,

    I download your source code, and following the instructions, I am running following errors on step 2 when issuing the command mvn integration-test:

    Project ID: null:maven-surefire-plugin:maven-plugin:2.8-20060902.220413-5

    Reason: Cannot find parent: org.apache.maven.plugins:maven-plugins for project:
    null:maven-surefire-plugin:maven-plugin:2.8-20060902.220413-5 for project null:m
    aven-surefire-plugin:maven-plugin:2.8-20060902.220413-5

    I look at the url of http://howardlewisship.com/repository/org/apache/maven/plugins/maven-surefire-plugin/2.8-SNAPSHOT/, it does have the 2.8-20060902.220413-5 jar file we needed.

    I am getting blocked, any suggestion to fix this issue?

    Thanks,
    Wendy

  35. April 24, 2009 at 4:55 am | #35

    Wendy,

    Commenting out the 2.8-SNAPSHOT in steps/step2/functest/pom.xml should fix it. You will have to make this change forward to other steps too.

    Thanks,
    Binil

    • Sreesha
      February 23, 2012 at 10:27 am | #36

      Hi Binil, i need some sort of help from you on automation testing, how i can contact you directly?

  36. rdekleijn
    August 14, 2009 at 10:22 am | #37

    Hi,

    Is it also possible to pass some parameters with junit?
    I use a testing framework which can only handle junit.

    I also want to run the test in multiple browsers, on such way. Can somebody confirm if it’s possible? and how I do that?

    I really appreciate that!

    ~~
    Roy

  37. ABC
    October 14, 2009 at 9:23 am | #38

    Hi~

    i got the following errors for Step 8

    Firefox can run smoothly and no error while IE cannot.

    This is my log

    ——————————————————————————-
    Test set: IEFunctionalTests
    ——————————————————————————-
    Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 30.386 sec <<< FAILURE!
    indexPageShouldComeUp Time elapsed: 30.339 sec <<< FAILURE!
    com.thoughtworks.selenium.SeleniumException: Timed out after 30000ms
    at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:73)
    at com.thoughtworks.selenium.DefaultSelenium.open(DefaultSelenium.java:214)
    at com.mycompany.app.functest.FirstTest.indexPageShouldComeUp(FirstTest.java:37)

    How can i solve this problem? Thx u~~

    • August 5, 2010 at 7:30 am | #39

      @ABC Can you describe your environment please.

      @rdekleijn Yes you can run the tests in multiple browsers using Selenium RC. . Do you mean multiple browser types for example (IE6, IE7, FF3) or multiple instances of the same type for example (3x IE6).

  38. December 31, 2009 at 5:27 pm | #40

    Amazing, I didn’t heard about this topic until now. Thanx!

  39. Serge
    February 1, 2010 at 8:37 am | #41

    Hi!
    When I run this command:

    >mvn test-mail

    I get an error:
    >Missing:
    >———-
    >1) org.openqa.selenium.server:selenium-server:jar:1.0.1

    • Herk
      April 26, 2011 at 2:01 pm | #42

      Replace the org.openqa.selenium.server dependency in the pom.xml to this:

      org.seleniumhq.selenium
      selenium-server
      2.0b3

  40. Linda
    December 15, 2010 at 6:36 am | #43

    I am begginer, Please guide me form where to start and from where can I get notes to start with selenium automation.

  41. amit
    March 3, 2011 at 11:15 pm | #44

    Thanks for explaining each and every step so nicely.

  42. amit
    March 17, 2011 at 10:42 pm | #45

    Thanks a lot!!

  43. Sreesha
    February 28, 2012 at 5:16 am | #46

    Hey, I need some sort of help from you on automation testing, how i can contact you via email or SN?

  1. December 22, 2006 at 5:24 pm | #1
  2. October 8, 2007 at 2:40 pm | #2
  3. November 5, 2008 at 3:22 pm | #3
  4. June 25, 2010 at 4:03 pm | #4
  5. July 12, 2010 at 4:59 pm | #5
  6. October 11, 2010 at 11:46 am | #6

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: