webtests reloaded - webtest with selenium, testng, groovy and maven

Post on 13-May-2015

2.911 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

The most difficult part to test is the WebUI. This part of an application only manually tested. With Selenium you are able to test WebUIs on a simple way. In this article we shows you how to automating the test process.

TRANSCRIPT

Thorsten Kamann

Software-Architekt, Coach

25.05.2009

Webtest? Tools Setup & Run

Pitfalls

Automatic Tests

Only manual Tests

Click-Through Testing

Different Browser?

Only new/changed pageswill be tested

Execute Test „anywhere andanytime“

Repeatable Tests

Avoid the factor „Forgotten“

Old Feature are always tested

Non-breakable Features

Usable for direct testing of Web-UIs

Selenium RemoteControl starts thecommands direct in the browser

No Java-Implementation of a Browser-Engine

Create tests with the Selenium-IDE

Export the Testskripts withJavaScript in any target language

Dynamic language for theJava-Platform

Seamless Integration withjUnit and TestNG

Powerful Syntax

Easy Learning

Toolsupport (Eclipse, Maven, Ant, …)

Testframework forIntegrationstesting

Annotation-basedConfiguration

Parameterized Tests

Datasource-Support forcreation of testdata

Toolsupport (Eclipse, Maven, Ant, …)

Buildtool

Supports automaticallytesting

Integration of Testframeworks

Deklarative

Toolsupport(Eclipse, Netbeans, IntelliJ, Konsole)

Architecture

Usecases

Projectsetup

Execution of Tests

Extensions

HS

QL

DB

Tomcat

petclinic.war

Selenium

Compile

StartTomcat

DeployWebapp

Start Selenium

Run Tests

Usecase-driven Tests

Definition of every User-Action

Definition of Inputdata

Definition of Return Values

Recording with Selenium-IDE

m2Eclipse

GroovyIDE

TestNG

Java-Project

Maven DM

Groovy

DM: Groovy

DM: TestNG

<dependency>

<groupId>org.codehaus.groovy</groupId>

<artifactId>groovy-all</artifactId>

<version>1.5.6</version>

</dependency>

<dependency>

<groupId>org.testng</groupId>

<artifactId>testng</artifactId>

<version>5.5</version>

<classifier>jdk15</classifier>

<optional>true</optional>

<scope>test</scope>

</dependency>

Groovy

TestNG

with JDK5 Annotation-Support

testsuite.xml

• Packages

• Groups

• Include/Excludes

Grouping of Tests

Definition of Parameter

<suite name=„webtest-reloaded">

<test name=„firefox-tests" annotations="JDK">

<parameter name="browser" value="firefox"/>

<groups>

<run>

<include name="it-test"></include>

</run>

</groups>

<packages>

<package name="selenium.groovy.testng"/>

</packages>

</test>

</suite>

Parameter

Groups

Packages

Export of Testcases

PHP, C#, Java

JavaScript for Export Language

Any Target Language issupported

function assertTrue(expression) {

return

"AssertJUnit.assertTrue(" + expression.toString() + ")";

}

function assignToVariable(type, variable, expression) {

return type + " " + variable + (expression)? " = "

+ expression.toString(): "";

}

public class NewTest {

Selenium selenium

String baseUrl = "ENTER_BASEURL_HERE"

@BeforeClass(groups=["it-test"])

public void beforeClass(){…}

@BeforeMethod(groups=["it-test"])

public void startSelenium(){…}

@AfterMethod(groups=["it-test"])

public void stopSelenium(){…}

@Test(groups=["it-test"])

public void executeIntegrationTest {

}

}

Maven Surefire-Plugin

• Deactivate Lifecycle test

• Activate Lifecycle integration-test

• Integrate TestNG‘s testsuite.xml

<plugin>

<artifactId>maven-surefire-plugin</artifactId>

<configuration>

<skip>true</skip>

</configuration>

<executions>

<execution>

<phase>integration-test</phase>

<configuration>

<skip>false</skip>

<suiteXmlFiles>

<suiteXmlFile>src/test/config/it-suite.xm</suiteXmlFile>

</suiteXmlFiles>

</configuration>

</execution>

</executions>

</plugin>

Deactivate

Lifecycle test

Activate

Lifecycle integration-test

Integrate

testsuite

Start TomcatDeploy

Webapp

pre-integration-test

UndeployWebapp

Stop Tomcat

post-integration-test

<<Sourcecode too long…

please see the sample project>>

start-serverOptional:Prepare

Firexox profile

pre-integration-test

stop-server

post-integration-test

<plugin>

<artifactId>selenium-maven-plugin</artifactId>

<executions>

<execution>

<phase>pre-integration-test</phase>

<goals>

<goal>start-server</goal>

</goals>

<configuration>

<background>true</background>

<firefoxProfileTemplate>

</firefoxProfileTemplate>

</configuration>

</execution>

</executions>

</plugin>

Start

Selenium-Server

Prepared Firefox

Profile

mvn –e clean integration-test

mvn –e surefire-report:report-only

Start Selenium Standalone

Run As -> TestNG Test

Different Browser

Different OS

Virtualizing

SpringAOP

Performance ofMethods

Performance ofViews

Stresstests

http://selenium.openqa.org/

http://testng.org/

http://groovy.codehaus.org/

http://maven.apache.org/

http:/www.thorsten-kamann.de/weblog/publications/webtests-reloaded-webtests-mit-selenium-testng-groovy-und-maven

top related