If you don’t know how to report a bug either anybody whose doesn’t know, you have to share this post about the art of reporting bugs from Cartoon Tester website:
Source http://cartoontester.blogspot.com.br/2012/02/art-of-bug-reporting.html
One more time I’m here talking about Selenium and tests. As I talked in the last post Functional Tests with Selenium 2.0 and cargo-maven-plugin, there was a problem if you want implement a new Selenium Test and execute it, you must to execute all Selenium tests, but it’s not efficient.
So, to resolve this problem we will be able to execute a specific test using maven in command line or in Eclipse IDE, which is very productive, and I’ll show how to do that as a simple JUnit or TestNG test.
First of all, we’ll create an abstract class that contain all necessary classes to execute Selenium tests in Eclipse IDE, and our tests must to extends this abstract class. In this class will have, for example, configurations to start/stop the application server that will deploy our application and configuration for create an instance of Selenium server and it engines start.
To help the manager the application server’s classes we’ll use Cargo and the application server will be Tomcat 6x. After that, It’ll necessary to add Cargo and Selenium dependencies with test scope for both. They can be add by Eclipse IDE or maven configuration file(pom.xml), but in this example it added in pom.xml file as below:
<dependency> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-core-container-tomcat</artifactId> <version>1.0.6</version> <scope>test</scope> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium</artifactId> <version>2.0a4</version> <scope>test</scope> </dependency>
After that, we’ll create a method to recover a local Tomcat instance:
/**
* Method responsable to set all init tomcat's configuration
*/
private TomcatExistingLocalConfiguration InitTomcatConfig() {
String tomcatHome = System.getenv("TOMCAT_HOME");
if (tomcatHome == null) {
throw new IllegalArgumentException("The system property TOMCAT_HOME must be defined.");
}
TomcatExistingLocalConfiguration localTomcatConfiguration = new TomcatExistingLocalConfiguration(tomcatHome);
return localTomcatConfiguration;
}
The method will find a local Tomcat instance by environment variable called TOMCAT_HOME and it’ll create an instance represented by TomcatExistingLocalConfiguration class.
And now we’ll create a method which start the application server Tomcat before start a test’s suite as below:
// Method execute before all suite tests
@BeforeSuite
public void setUp() {
LocalConfiguration tomcatConfiguration = InitTomcatConfig();
// Containers configuration utilizado("tomcat6x") and war path
war = new DefaultDeployableFactory().createDeployable("tomcat6x", "target/example.war",
DeployableType.WAR);
tomcatConfiguration.addDeployable(war);
// Tomcat configurations
container = new Tomcat6xInstalledLocalContainer(tomcatConfiguration);
container.setHome(tomcatConfiguration.getHome());
// Start o container
container.start();
}
After that, our Selenium tests’s classes must to extends this abstract class and execute with our favorite test engines. In my example, it was TestNG.
That it! To make code more maintainable, create tests and become the refactoring and maintainability of the applications less painful.
Sorry about my english. If you have any question or some difficult, contact me.
Tags: Cargo, container, eclipse, maven, pom.xml, selenium, tests, tomcat
As tester evangelist one more time I’m talking about tests, especifically unit tests. The better frameworks which I use is TestNG and I consider the best.
I’ve worked in legacies projects which used JUnit test frameworks, but I always suggest change to TestNG because of advantages in relation to JUnit.
I wrote a post that I talked about TestNG framework and example project showing some annotations usages.
There is an eclipse plugin to execute the TestNG tests. There are a lot of features, but one of them is convert tests developed with JUnit3 and JUnit4 to TestNG.
To do that, you just install the plugin, click the right mouse button in your test: TestNG > Converter to TestNG. As you can see in this picture below:

All the annotations and imports classes will be convert to TestNG classes. Now enjoy all advantages and hands-on.
nice testing.
Sonar is a open source web-based application to manage code quality which covers seven axes of code quality as: Architecture and design, comments, duplications, unit tests, complexity, potential bugs and coding rules. Developed in Java and can be cover projects in Java, Flex, PHP, PL/SQL, Cobol and Visual Basic 6.
It’s very efficient to navigate, offering visual reporting and you can follow metrics evolution of your project and combine them.
There is an online project called Nemo dedicated to open source projects, as you can see projects like Jetty, Apache Lucene and Apache Tomcat.
So, let’s config Sonar to work together with maven. First of all set Sonar server and others configurations adding in settings.xml file of maven:
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.jdbc.url>jdbc:postgresql://localhost/sonar</sonar.jdbc.url>
<sonar.jdbc.driver>org.postgresql.Driver</sonar.jdbc.driver>
<sonar.jdbc.username>user</sonar.jdbc.username>
<sonar.jdbc.password>password</sonar.jdbc.password>
<!-- SERVER ON A REMOTE HOST -->
<sonar.host.url>http://localhost:9000</sonar.host.url>
</properties>
</profile>
You must to have a Sonar server running and define it in sonar.host.url parameter. In this example I’m using the default Sonar URL http://localhost:9000 and you must set user and password of your database. To install local Sonar Server you can see this link.
After that, to executes code analysers and save results in Sonar database just execute mvn sonar:sonar. You can config Sonar to execute in your CI (Continuous Integration) application as Hudson which are perfect match, because there is a Sonar plugin for it.
See the final result below:


I prefer Teamcity CI, but there aren’t a stable plugin as you can see in compatibility matrix. To resolve this plugin’s problem, just add sonar:sonar in the maven command executed by Teamcity.
Sonar is an essential tool for your software project to help you evaluating how cohesive are your classes, warning for future problems as complexity code or duplications problems and will help you to have a cleaner code.
Sorry about my english. If you have any question or some difficult, contact me.
Tags: hudson, maven, maven plugins, open source, opensource, sonar, teamcity
It’s a short post, but it’s a very util tip. The eclipse IDE has a ability to run the code interactively, executing an application line by line in a debug mode which you can define a specify point in the code to stop, called breakpoint. As you can see in eclipse documentation:
“A breakpoint suspends the execution of a program at the location where the breakpoint is set“.
But when you are debugging an application, sometimes, you don’t want the application stop everytime in the breakpoint, for example, in a loop block of code with a lot of objects to iterate.
The solution to help you in this situations is condicional breakpoint. You can define a condition for your breakpoint which the application will suspend the execution when it’s true. To set a conditional breakpoint, right-click on mouse in the drawn with a blue circle and click “breakpoint properties..” in eclipse. How you can see in printscreen below:
after that you’ll see the screen:
So you set a condition in a breakpoint to stop at this point when it’s true. In this example, the application will be suspend when the request’s method is “POST”.
There are others options to set a condition in the breakpoint, for example, the count of hit the application.
So, that’s it. Did you know about this tip or a intereting features in eclipse? comment about it.
Sorry about my english. If you have any question, contact me.
The Selenium and Webdriver projects are merged to create a powerfull framework open source project for functional tests based in javascript for testing web applications and sites. The tests can be executed by a browser like Firefox or Chrome or can be executed by a lightweight, super-fast browser emulation based on HtmlUnit treating normal situation you might want test in an application web.
If you want to do some tests just download the .jars and add in your classpath’s project.
In this How-To I’ll use Selenium and Webdriver to execute integration tests in maven life cycle with cargo-maven-plugin.
The cargo-maven-plugin is used to deploy applications using maven. It’s install the container and the dependencies thats required to deploy your application and can be configured by almost containers avaiable as Tomcat, JBoss, Jetty(embedded) or GlashFish. The cargo-maven-plugin will start the container and deploy the application, after that it will execute the tests and stop the container.
For example, I’ll use the “Modelos de Celulares” project developed in the last post and I’ll add the Selenium tests and configuration of cargo-maven-plugin.
First of all lets add the cargo-maven-plugin dependency to start the container to execute the tests in the pre-integration-test maven lifecycle, after that stop the container in the post-integration-test maven lifecycle. The container used in this example was Tomcat 6x installed local and defined in the <home> attribute. It was necessary to add another plugin to execute all tests when the container started. The plugin is maven-surefire-plugin.
See the example of maven-surefire-plugin and cargo-maven-plugin configured in the pom.xml file:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0.6</version>
<configuration>
<wait>false</wait>
<!-- Container configuration -->
<container>
<type>installed</type>
<containerId>tomcat6x</containerId>
<home>${TOMCAT_HOME}</home>
</container>
</configuration>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- Skip the normal tests,
we'll run them in the integration-test phase -->
<skip>true</skip>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
The next step is add the Selenium dependency to implements the functional tests. Just add in the pom.xml file:
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium</artifactId> <version>2.0a4</version> <scope>test</scope> </dependency>
After that, lets create a test class. A way to acess the object browser is through four official drivers: FirefoxDriver, the most mature driver and used in this example project, Internet Explorer Driver, tested in versions IE6, IE7 on windows Vista and XP and compared with others drivers, its relatively slow. The ChromeDriver, it’s newer driver and the HtmlUnit as a lightweight, super-fast browser emulation.
Lets interacting with the browser by FirefoxDriver‘s method class call “findElement” with WebElement parameter and can be recover by By class like in this method tentaCadastrarSemNenhumDado below:
public void tentaCadastrarSemNenhumDado() {
driver.get("http://localhost:8080/CadastroCelular");
driver.findElement(By.id("botaoSubmit")).click();
String mensagemErroNome = driver.findElement(By.id("mensagemErroNome")).getText();
// name required field message
Assert.assertEquals("Campo Nome Obrigatório", mensagemErroNome);
String mensagemErroDescricao = driver.findElement(By.id("mensagemErroDescricao")).getText();
// description required field message
Assert.assertEquals("Campo Descrição Obrigatório", mensagemErroDescricao);
driver.close();
}
This test try to insert a model mobile without fill the required fields and check the messages of required fields.
Through By class is possible recover web elements by links, name, tag html, css or link label. In this version of Selenium there is an annotation call @FindBy which designed to clean up the code specifying the location strategy. The method “tentaCadastrarSemNenhumDado()” example was developed without annotation and see the same method using annotation @FindBy:
@FindBy(id = "botaoSubmit")
private WebElement botaoSubmit;
@FindBy(id = "mensagemErroNome")
private WebElement msgErroNome;
@FindBy(id = "mensagemErroDescricao")
private WebElement msgErroDescricao;
@Test
public void tentaCadastrarSemNenhumDado() {
driver.get("http://localhost:8080/CadastroCelular");
botaoSubmit.click();
// name required field message
Assert.assertEquals("Campo Nome Obrigatório", msgErroNome.getText());
// description required field message
Assert.assertEquals("Campo Descrição Obrigatório", msgErroDescricao.getText());
driver.close();
}
As you can see the code is cleaner and simple to understand. Configuration and implemantion of functional tests are so simples which you don’t have reason to do not it.
Nice coding.
Sorry about my english. If you have any question, contact me.
Tags: cargo-maven-plugin, jboss, maven, selenium, tomcat, webdriver
A way to learn a new program languace or a new framework is do a “Hello World” or a CRUD to start to understand about the tecnology, lifes cycles, dependencies, configurations, limitations and etc.
I had to learn about Spring MVC and Struts Tiles, old struts’s lib and now is a independent project. So I developed a CRUD to pratice and available trying to explain how does Spring MVC and Struts Tiles work.
The project is a CRUD of Mobile Models with two fields. I’ll just explain about Spring MVC and Struts Tiles. The others parts of the application won’t be the focus on this post.
The project connect via JDBC with tests infrastructure of DAO and Controller layer, maven to management the project and Spring framework version 3.0.3.RELEASE.
I used the Spring MVC to treat requests between user interface and controller to refer objects in a web form. It’s like others MVC web frameworks to facilitate the development with the advantage to be totally integrated with Spring Container working with all advantages of Spring’s container.
To start to configure it you must to map the servlet DispatcherServlet in web.xml file in your project. For example:
<web-app> <servlet> <servlet-name>spring-mvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring-mvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
In deploy phase the servlet ‘spring-mvc’ DispatcherServlet will looks for spring-mvc-servlet.xml file ( [Servlet Name]-servlet.xml ) inside of WEB-INF. In the example above all requests will be treat by ‘spring-mvc’ servlet DispatcherServlet.
About the Controllers the Spring have specific types of controllers form-specific controllers, command-based controllers and etc. To define a class as controller just annotate with @Controller like in CelularController class example:
@Controller public class CelularController {
Classes anotated with @Controller will transform the class serves the role of a controller.
In this class CelularController has another annotation called @RequestMapping, where you can map the URL request to acess a specific method by “value” parameter. The parameter “method” is used to define the method request(GET, POST, HEAD, OPTIONS, PUT, DELETE, TRACE). In the classe CelularController there is an example:
3 4 5 6 | @RequestMapping(value = "/cadastro/remove", method = RequestMethod.POST) public String removerModelo(@RequestParam(value = "nome", required = true) String nome, @ModelAttribute Celular celular, WebRequest request) throws Exception { } |
There are another annotation called @ModelAttribute. When you define an attribute with this annotation, the Spring will bind the parameters comes from the request(view) to the objects attributes.
The magic happens when you create a method and set @InitBinder annotation as:
3 4 5 6 7 8 | @InitBinder
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(String.class, new StringTrimmerEditor(false));
binder.setValidator((org.springframework.validation.Validator) this.validator);
} |
@InitBinder annotation identify a method which initialize the WebDataBinder class which is used to bind the attributes comes from form(view) to the object with @ModelAttribute annotation.
To Spring Container detect classes mapped with @Controller, @ModelAttribute or @InitBinder it’s necessary define the package of this classes in spring-mvc-servlet.xml file. In the example:
3 | <context:component-scan base-package="net.valdemarjr" scoped-proxy="targetClass" /> |
To config Struts Tiles integrate with Spring MVC is necessary define two beans in spring-mvc-servlet.xml file:
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver" p:viewClass="org.springframework.web.servlet.view.tiles2.TilesView" /> <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer" />
And the return String in your controller’s methods mapped in tiles.xml file. For example in “processarFormulario”. The method’s return is “cadastro.formulario” which is mapped as:
3 4 | @Controller public class CelularController { |
And the response will redirect to file “formulario.jsp”.
It’s the first time I use Spring MVC and Struts Tiles together and I liked it.
If you want to see de source code, the project is in github and you can download, update and test.
Sorry about my english. If you have any question, contact me.
Tags: maven, Spring, Spring MVC, Struts, Struts Tiles, tiles
I’ll start with a lot of framework’s versions such as adobe flex, maven plugins which in the other day published in InfoQ news about new maven’s release 3.0. But the main subject in this post is a example with adobe flex and Flexunit4. In this example I’ll use Flexmojos4 maven’s plugin which require maven 3.0 version to work.
I’m understending which the java and maven environment are configured. If you have some question about maven’s installation see Installation Instructions here. Just a detail, the flashplayer’s version must be debug version.
So, let’s create a new flex project using Flexmojos4. I’ll use 4.0-alpha-5 version.
Execute the command to create a Application project:
4 5 6 | mvn archetype:generate -DarchetypeRepository=http://repository.sonatype.com/content/groups/flexgroup -DarchetypeGroupId=org.sonatype.flexmojos -DarchetypeArtifactId=flexmojos-archetypes-application -DarchetypeVersion=4.0-alpha-5 |
Maven will download all dependencies required, after that type the groupId (sometimes is the same of inheritance package), artifactId (project’s name), version and the package (inheritance package). The example is done like the image below:

“Y” to confirm, so the project will be create.
In this example I’ll use the flexunit 4.0-beta-2. Edit the file pom.xml and change the dependency version of the flexunit from 0.85 to 4.0-beta-2, like:
1 2 3 4 5 6 7 | <dependency> <groupId>com.adobe.flexunit</groupId> <artifactId>flexunit</artifactId> <version>4.0-beta-2</version> <type>swc</type> <scope>test</scope> </dependency> |
It’s necessary to change class test generated by flexmojos, because this version not use the Flexunit4′s metadata. To do that, just remove the “extends TestCase” and add the metadata “[Test]” upon the method testNothing().
Now execute the command “mvn clean install” to run the test which was create automatically by flexmojos’s plugin. Maven will download all dependencies.
After executed the command, the error will appear on console: Cannot run program “FlashPlayer.exe”. It’s happen because you must to tell the flexmojos plugin the path flashplayer which will be use in the tests. In my case the path is C:\java\Flex Builder 3 Plug-in\Player\10\win\FlashPlayer.exe. This is resolved adding the property flex.flashPlayer.command in the pom.xml’s file:
3 4 5 | <properties> <flex.flashPlayer.command>C:\java\Flex Builder 3 Plug-in\Player\10\win\FlashPlayer.exe</flex.flashPlayer.command> </properties> |
Execute the command “mvn clean install” again and the flashplayer will be execute and the test pass!
The example code can be download on github.
Tags: adobe flex, flexmojos4, flexunit, java, maven, maven3, Test
This week I’ve had a problem. I’d like to work with Adobe Flex using a new eclipse version Helios and Flex Builder 3 eclipse plugin. I realized which the flex perspective didn’t show up. After some researches, I found a incompatibility problem between eclipse Helios and Flex Builder 3 eclipse plugin. But, “googling” I found the solution and post it.
The first thing to verify is try to install eclipse Helios and Flex Builder 3 eclipse plugin. If doesn’t work, we’ll try some alternatives:
- After install Flex Builder 3 eclipse plugin, the directory “links” is created in the eclipse directory root. There is a file “com.adobe.flexbuilder.feature.core.link”. Open it. The file’s content is Flex Builder‘s path. If it doesn’t have the attribute “path=” before Flex Builder‘s path, put it. Save the file and restart the eclipse.
I did some tests and do it resolve the problem. But if it doesn’t work, we must to do one more thing:
- Download ProblemManager patch. Go to “Flex Builder 3 Plug-in\eclipse\plugins\com.adobe.flexbuilder.project_3.0.214193\“ directory. Unpack the class, inside of “zornproject.jar“ file, in the path “com/adobe/flexbuilder/project/compiler/internal“.
Restart the eclipse and in menu go to “Window > Open Perspective > Other” and Voilá!
After some tests, I didn’t find any problems. I think the plugin is working fine.
Valdemar Jr ( Trying to resolve the problems, for a best codification )
Tags: adobe flex, bug, eclipse, flex, flex builder, java
Bugtracking is a kind of application designed to help developers and quality assurance to register and manager bugs. A lot of bugtracking are opensource and used in most of software developer’s company.
One of this is Mantis, developed in PHP and it can be used with postgreSQL, mySQL or MS SQL databases. There is a list of features as:
- Simple User Experience
- Custom Fields
- Email notifications
- Wiki Integration (optional)
- Chat online
- Autentication via LDAP, Active Directory Integration.
If you want to see this features and functionalities you can acess online demo. But if you want to create an environment, in your company for example, there is the Instant Mantis. It’s the way to install and test very quickly, just unpack the files and run.
To install the Instant Mantis you can download here. Unpack the files in HD or in a pen-drive and start the Instant Mantis server by double click the imstart.cmd file and will open a window as below:

Stop the service by double click the imstop.cmd file.
After Instant Mantis is up and running, type in your favorite browser http://localhost:8008 with login administrator and password root.
Enjoy and have fun!
Valdemar Jr (trying to manager and close all bugs in my life)


