Sunday, January 24, 2010

Canon Dslr Leather Bag

Selenium functional tests

HQ Selenium is a framework that automates functional testing of web applications. It consists of several tools used to define and automate these tests. Specifically, let's see:
  • Selenium IDE: This is a Firefox plugin that lets you define a test of a web application keeping in a script the actions executed by the user on the browser. This script can be re-run after every time you want.
  • Selenium RC (Remote Control) : Allows you to automate testing of web applications based on defined scripts using Selenium IDE.
We will now see an example of functional testing a web application.

First we descarganos Firefox plugin Selenium IDE . We can do it from this page . This will download the Selenium IDE plugin and install it in your browser. Then it will restart to complete installation.

Now let's do a test of a web application. In this case it is an application that stores all items of interest from magazines that I buy, and the proof is to introduce a new article.

First, we Tools-> Selenium IDE . This opens a window that lets you record the script with the test to be performed:

From this point all we do is recorded on your browser in the script. At this point introduce a new article called "New " and title "New ." Once entered, click on the red button on the Selenium IDE window to stop recording the script. Prove that it has introduced the item.

Now repeat the test by clicking the green triangle in the top right of the window Selenium IDE. This repeats the previous run and therefore, in the list of products we now have 2 items with the name "New ."

can save this test from File-> Save E. Test Cas But more interesting for us will option File-> Export Test Case As -> Java (JUnit) Selenium RC to export this script to a test case for JUnit we will use later to automate this test:
 com.example.tests package; 
com.thoughtworks.selenium
import .*;
import java.util.regex.Pattern;

public class Test {
SeleneseTestCase extends public void setUp () throws Exception {setUp
( http://change-this-to-the-site-you-are-testing/ "," * chrome ");}

testPrueba public void () throws Exception {
selenium.open (" / RevisteroMyFacesWeb / ") ;
selenium.click ("link = New Item");
selenium.waitForPageToLoad ("30000");
selenium.type (j_id_jsp_815202587_1: nombreArticulo "," New ");
selenium.type (j_id_jsp_815202587_1: descripcionArticulo" "New");
selenium.click (j_id_jsp_815202587_1: j_id_jsp_815202587_35 ");
selenium.waitForPageToLoad (" 30000 ");
}}

Once we defined the test now to automate. We will use JUnit tool and Selenium RC (Remote Control) . We will also use plugin Maven Selenium to , which starts the server Selenium RC when running the tests.

Create a Maven project with the following pom.xml :
 \u0026lt;project xmlns = "http://maven.apache.org/POM/4.0.0" 
xmlns: xsi = "http: / / www.w3.org/2001/XMLSchema-instance "
xsi: schemaLocation =" http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0. xsd ">
\u0026lt;modelVersion> 4.0.0 \u0026lt;/ modelVersion>
\u0026lt;groupId> com.roldan \u0026lt;/ groupId>
\u0026lt;artifactId> RevisteroPruebasSelenium \u0026lt;/ artifactId>
\u0026lt;version> 0.0.1-snapshot \u0026lt;/ version>
\u0026lt;dependencies>
\u0026lt;dependency>
\u0026lt;groupId> Junit \u0026lt;/ groupId>
\u0026lt;artifactId> Junit \u0026lt;/ artifactId>
\u0026lt;version> 3.8 .2 \u0026lt;/ version>
\u0026lt;scope> test \u0026lt;/ scope>
\u0026lt;/ dependency>
\u0026lt;dependency>
\u0026lt;groupId> org.seleniumhq.selenium.client-drivers \u0026lt;/ groupId>
\u0026lt;artifactId> selenium-java-client-driver \u0026lt;/ artifactId>
\u0026lt;version> 1.0.1 \u0026lt;/ version>
\u0026lt;scope> test \u0026lt;/ scope>
\u0026lt;/ dependency>
\u0026lt;/ dependencies>
\u0026lt;build>
\u0026lt;plugins>
\u0026lt;plugin>
\u0026lt;groupId> org.codehaus.mojo \u0026lt;/ groupId>
\u0026lt;artifactId> selenium-maven-plugin \u0026lt;/ artifactId>
\u0026lt;executions>
\u0026lt;execution>
\u0026lt;phase> process-test-classes \u0026lt;/ phase>
\u0026lt;goals>
\u0026lt;goal> start-server \u0026lt;/ goal>
\u0026lt;/ goals>
\u0026lt;configuration>
\u0026lt;background> ; true \u0026lt;/ background>
\u0026lt;/ configuration>
\u0026lt;/ execution>
\u0026lt;/ executions>
\u0026lt;/ plugin>
\u0026lt;/ plugins>
\u0026lt;/ build>
\u0026lt;/ project>

We also configure the Maven plugin for Selenium to start the Selenium server in the phase preceding the test ( process-test-classe s) defines two units, JUnit and Java client driver for Selenium , which allows running the tests set up from Selenium IDE . We will adapt

test class generated from Selenium IDE to make use of the Java driver for Selenium:
 com.roldan.selenium package; 
com.thoughtworks.selenium
import .*;
CrearNuevoArticuloTest
public class extends SeleneseTestCase {

protected DefaultSelenium createSeleniumClient(String url) throws Exception {
return new DefaultSelenium("localhost", 4444, "*firefox", url);
}

public void testCrearNuevoArticulo() throws Exception {
DefaultSelenium selenium = createSeleniumClient("http://localhost:8080/");
selenium.start();

selenium.open("/RevisteroMyFacesWeb/");
selenium.click("link=Nuevo Artículo");
selenium.waitForPageToLoad("30000");
selenium.type("j_id_jsp_815202587_1:nombreArticulo", "Nuevo");
selenium.type("j_id_jsp_815202587_1:descripcionArticulo", "New");
selenium.click (j_id_jsp_815202587_1: j_id_jsp_815202587_35 ");
selenium.waitForPageToLoad (" 30000 ");

selenium.stop ();

}}

The difference is that now at the beginning of create a test client Selenium and final test closes this client.

If the test is now released for this project with mvn test , will receive a browser that repeats the test set, and has been recorded yet another article.

References: Selenium
HQ Web
Turorial of Workaholics
on Selenium IDE Turorial of Workaholics on Selenium RC Tutorial
Two sequential tests Ideas on Selenium and JUnit
Web Selenium plugin for Maven

0 comments:

Post a Comment