The Source for Java Technology Collaboration
User: Password:



Aditya Dada's Blog

Testing Archives


Selenium-ANT-TestNG (SAT) Framework

Posted by aditya_dada on May 20, 2008 at 10:39 AM | Permalink | Comments (3)


Architecture

This framework is created using ANT, TestNG and Selenium.
Through this framework, a user is able to create an automated test case which can be run later by executing a single command. The uses of different frameworks are as follows:
Selenium: This framework is needed for recording a testcase, exporting it into Java, and executing it on a browser
TestNG: This framework is used to organize different tests, and to report results.
ANT: provides the glue to hold everything together, and execute basic commands.

Pre-requisites:


Basic knowledge of Selenium IDE, Selenium RC, TestNG and ANT.

Setup:


1. Install Selenium IDE on your Firefox browser.
2. Make sure you have ANT installed.
3. Grab the testws.zip file from here. Unzip it into a directory of your choice.

About the sample
There are 2 bundled samples:
1. AdminLoginTest.java: This test logs into the glassfish admin console using the username/password: admin/administrator. It then clicks on the 'Enterprise Applications' link, and tests to see if there are no applications deployed. Else, test will fail.
2. SimpleTest.java: This test accesses http://localhost:8080/ page, and tests whether the term "Glassfish Project" appears or not.

The config directory contains testng.xml file, and is a place holder for configuration files.
The lib directory contains required jar files, and is a place holder for other library jars/zips.
The test directory contains test java files and is a place holder for other test files.
Once the tests are run, build and test-output directories will be created.
The build directory contains compiled classes, and is a volatile directory that is deleted by the target clean in build.xml file.
The test-output directory contains result files, and is generated by TestNG.
Notes:
To run the bundled sample, follow the steps for "Execute your test through ANT" (see below).
Currently, I face some issues running this on IE. I have successfully been able to run tests using Firefox.

How To:


Write a test case
The basic structure that one has to follow to create a test case is:
1. Record a testcase using Selenium IDE (Firefox browser only), Export the test case into Java
2. Edit the test case – java file, and add TestNG annotations
3. Execute the test case using ANT

1. Record test using selenium IDE and export it into Java:
i. Open the website you’d like to test in Firefox browser
ii. Start the selenium IDE from your Firefox browser
iii. Ensure that the Base URL in Firefox is the same as the website you want to test
iv. Start clicking on the website. Selenium will record your actions.
v. When finished, do: File -> Export Test As... -> Java – Selenium RC and save the java file.
seleniumIDE-export.JPG
After exporting, your java test case should look like this:
selenium-java-test.JPG

2. Add TestNG to your test case:
i. Open the java test file you just created in an editor
ii. Add the following:
(a) to the import statements:
import org.testng.annotations.*;
(b) To variable declarations:

private DefaultSelenium selenium;
private static String TIMEOUT_PERIOD ="10000";

(c) To The class:

@BeforeSuite(alwaysRun = true)
public void setUp(String browser) {
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://localhost:8080");
selenium.start();
selenium.open("http://localhost:8080");
}

@AfterSuite(alwaysRun = true)
private void stopTest() {
selenium.stop();
}

(d) After each statement in the test that will take time for a page to load:

selenium.waitForCondition("selenium.browserbot.isNewPageLoaded()", TIMEOUT_PERIOD);

(e) On top of the test method:

@Test(groups = { "<your test group name>" })
e.g. @Test(groups = { "roller" })

(f) Edit page to be opened. Make sure arg to ‘open’ method of selenium points to the right context root e.g. If http://localhost:8080/<context_root> is the correct URL to test, then since we already have tried to open localhost:8080 in setUp, we only need to open the context root page.
e.g.
selenium.open("<context_root>");

iii. Save the test file
(a). (Optional) Update testng.xml file. TestNG uses this file to read which groups to execute and also to pass parameters to the test. This file is only required if build.xml file uses testng.xml file to run the test.
Note: in sample test included, testng.xml is used, and will need to be updated.

iv. Ensure that the test file you created is mentioned in the build.xml compile target.

3. Execute your test through ANT
i. Start domain required by your webpage. e.g. asadmin start-domain
ii. Start database if needed (Not needed for bundled sample test)
iii. Start selenium server e.g. cd testws/lib, java -jar selenium-server.jar
iv. Execute the command: “ant run” from ‘testws’. You should see a new firefox browser window open up, and run through your test.
v. Check reports generated by TestNG under ‘testws/test-output’ directory. Open the index.html to see different output from the test.

SAT-html-output.JPG
Console output:

SAT-cmd-output.JPG



The Future of Testing

Posted by aditya_dada on May 12, 2008 at 01:40 PM | Permalink | Comments (4)

On May 7th, 2008, Varun Rupela and I gave a talk on "The Future of Testing: How Community Engagement Is Changing the Rules" at the JavaONE conference in San Francisco.

At Sun's GlassFish Quality Engineering team, we have been seeing a trend for the past few years, ever since GlassFish joined the open source revolution, that more and more features are developed by the community, but these features are not tested by the community. While the burden of additional testing came to rest upon the in-house Quality Organziation, the resources are often not added to meet the additional requirements. So what does a resource-constrained Quality organization such as ours do? We follow project GlassFish, and go open source!

The charter of GlassFish Quality Community is unique - something that gives us leverage in creating a niche for ourselves as an open-source community. We are the only organization under GlassFish, that can offer opportunities to learn latest technologies, interact with industry experts while also making the whole experience rewarding. And it is this strategic placement that helps us create a win-win solution.

We not only attract students and young professionals who would like to get their feet wet with latest GlassFish technologies, but also attract quality engineers from other organizations that are already using GlassFish, and would like to stay on top of the quality status of GlassFish. And, we not only accept all contributions to help improve GlassFish Quality, we also incorporate many of the applciations into our nightly test base. And while young professionals in the field of JavaEE applications improve their skills in developing applications, our customers can get the defects fixed faster, and request new features more efficiently.

This was the idea that was a novelty for many at JavaONE this year, and we won many praises and accolades for taking a step in the right direction.

By the way, for those interested in the slides to our talk, they can be downloaded here (.odp) or here (.pdf).

Finding Bugs Made Easy

Posted by aditya_dada on January 26, 2006 at 10:43 AM | Permalink | Comments (0)

I was introduced to FindBugs™ tool in April 2005. I attended professor Bill Pugh's presentation, and walked out impressed. Some of you may have met him at JavaOne in 2004 after his presentation. While he was visiting Sun Microsystems, Inc. campus in Santa Clara, CA, I had the opportunity to meet him, and discuss with him techniques to integrate FindBugs™ into our processes.
Since then, I've tried to put FindBugs™ to good use by running it against Glassfish. And the results have been surprising.
FindBugs™ is a static analysis tool, that uses bug patterns to search for common problems by analyzing Java byte-code. Its strength is its ability to discover problems like possible infinite recursive loops, impossible casts, possible typos in method names and many more. It catches errors that compilers let pass. It has powerful reporting that points out the defective class, the method and the line of code. The warnings produced can be categorized in many different ways, like:
 * High, Medium or Low
 * Correctness, Malicious Code, Performance or Style
 * Sorted by package or class

Filter patterns may be written to exclude or include matching Classes and/or Warnings.

I found the tools that were bundled with FindBugs™ really easy to use, and powerful. What's more - it helps brush up the core concepts of Java programming, and in using Java more effectively.

Along with its many strengths, FindBugs™ also has some shortcomings. One of them is the inability to process nested jars (which the FindBugs™ team is aware of, and a fix may be available soon). Another is generation of 'False Positives' that may not be real product bugs.

In my experience, the high priority warnings produced by FindBugs™ are best addressed first. The medium priority warnings need a bit of analysis, and the low priority may be ignored.

The strengths of FindBugs™ far outweigh its weaknesses. FindBugs™ provides a low cost way of catching issues and defects. Since FindBugs™ is so easy to install, and requires minimal effort to use, I'd highly recommend using it to improve the quality of your code.



Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds