Transcript
Page 1: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

Thorsten Kamann

Software-Architekt, Coach

25.05.2009

Page 2: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

Webtest? Tools Setup & Run

Page 3: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

Pitfalls

Automatic Tests

Page 4: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

Only manual Tests

Click-Through Testing

Different Browser?

Only new/changed pageswill be tested

Page 5: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

Execute Test „anywhere andanytime“

Repeatable Tests

Avoid the factor „Forgotten“

Old Feature are always tested

Non-breakable Features

Page 6: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Page 7: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

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

Page 8: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Page 9: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

Dynamic language for theJava-Platform

Seamless Integration withjUnit and TestNG

Powerful Syntax

Easy Learning

Toolsupport (Eclipse, Maven, Ant, …)

Page 10: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

Testframework forIntegrationstesting

Annotation-basedConfiguration

Parameterized Tests

Datasource-Support forcreation of testdata

Toolsupport (Eclipse, Maven, Ant, …)

Page 11: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

Buildtool

Supports automaticallytesting

Integration of Testframeworks

Deklarative

Toolsupport(Eclipse, Netbeans, IntelliJ, Konsole)

Page 12: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

Architecture

Usecases

Projectsetup

Execution of Tests

Extensions

Page 13: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

HS

QL

DB

Tomcat

petclinic.war

Selenium

Page 14: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Page 15: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

Compile

StartTomcat

DeployWebapp

Start Selenium

Run Tests

Page 16: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

Usecase-driven Tests

Definition of every User-Action

Definition of Inputdata

Definition of Return Values

Recording with Selenium-IDE

Page 17: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Page 18: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Page 19: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Page 20: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

m2Eclipse

GroovyIDE

TestNG

Page 21: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

Java-Project

Maven DM

Groovy

Page 22: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

DM: Groovy

DM: TestNG

Page 23: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

<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

Page 24: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

testsuite.xml

• Packages

• Groups

• Include/Excludes

Grouping of Tests

Definition of Parameter

Page 25: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

<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

Page 26: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

Export of Testcases

PHP, C#, Java

JavaScript for Export Language

Any Target Language issupported

Page 27: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Page 28: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

function assertTrue(expression) {

return

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

}

function assignToVariable(type, variable, expression) {

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

+ expression.toString(): "";

}

Page 29: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

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 {

}

}

Page 30: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

Maven Surefire-Plugin

• Deactivate Lifecycle test

• Activate Lifecycle integration-test

• Integrate TestNG‘s testsuite.xml

Page 31: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

<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

Page 32: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

Start TomcatDeploy

Webapp

pre-integration-test

UndeployWebapp

Stop Tomcat

post-integration-test

Page 33: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

<<Sourcecode too long…

please see the sample project>>

Page 34: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

start-serverOptional:Prepare

Firexox profile

pre-integration-test

stop-server

post-integration-test

Page 35: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

<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

Page 36: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

mvn –e clean integration-test

mvn –e surefire-report:report-only

Page 37: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Page 38: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

Start Selenium Standalone

Run As -> TestNG Test

Page 39: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Page 40: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

Different Browser

Different OS

Virtualizing

Page 41: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

SpringAOP

Performance ofMethods

Performance ofViews

Stresstests

Page 42: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

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