Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
-
Upload
thorsten-kamann -
Category
Technology
-
view
2.917 -
download
3
description
Transcript of Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
![Page 1: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/1.jpg)
Thorsten Kamann
Software-Architekt, Coach
25.05.2009
![Page 2: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/2.jpg)
Webtest? Tools Setup & Run
![Page 3: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/3.jpg)
Pitfalls
Automatic Tests
![Page 4: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/4.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/5.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/6.jpg)
![Page 7: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/7.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/8.jpg)
![Page 9: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/9.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/10.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/11.jpg)
Buildtool
Supports automaticallytesting
Integration of Testframeworks
Deklarative
Toolsupport(Eclipse, Netbeans, IntelliJ, Konsole)
![Page 12: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/12.jpg)
Architecture
Usecases
Projectsetup
Execution of Tests
Extensions
![Page 13: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/13.jpg)
HS
QL
DB
Tomcat
petclinic.war
Selenium
![Page 14: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/14.jpg)
![Page 15: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/15.jpg)
Compile
StartTomcat
DeployWebapp
Start Selenium
Run Tests
![Page 16: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/16.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/17.jpg)
![Page 18: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/18.jpg)
![Page 19: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/19.jpg)
![Page 20: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/20.jpg)
m2Eclipse
GroovyIDE
TestNG
![Page 21: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/21.jpg)
Java-Project
Maven DM
Groovy
![Page 22: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/22.jpg)
DM: Groovy
DM: TestNG
![Page 23: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/23.jpg)
<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](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/24.jpg)
testsuite.xml
• Packages
• Groups
• Include/Excludes
Grouping of Tests
Definition of Parameter
![Page 25: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/25.jpg)
<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](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/26.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/27.jpg)
![Page 28: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/28.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/29.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/30.jpg)
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](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/31.jpg)
<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](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/32.jpg)
Start TomcatDeploy
Webapp
pre-integration-test
UndeployWebapp
Stop Tomcat
post-integration-test
![Page 33: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/33.jpg)
<<Sourcecode too long…
please see the sample project>>
![Page 34: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/34.jpg)
start-serverOptional:Prepare
Firexox profile
pre-integration-test
stop-server
post-integration-test
![Page 35: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/35.jpg)
<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](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/36.jpg)
mvn –e clean integration-test
mvn –e surefire-report:report-only
![Page 37: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/37.jpg)
![Page 38: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/38.jpg)
Start Selenium Standalone
Run As -> TestNG Test
![Page 39: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/39.jpg)
![Page 40: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/40.jpg)
Different Browser
Different OS
Virtualizing
![Page 41: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/41.jpg)
SpringAOP
Performance ofMethods
Performance ofViews
Stresstests
![Page 42: Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven](https://reader033.fdocuments.net/reader033/viewer/2022052523/5552f675b4c90587048b4e29/html5/thumbnails/42.jpg)
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