Self-linking
Recently in Appfuse saw the use of webtest-maven-plugin implementation of Web application integration testing, research, the feeling is very good, for Web application auto-build is very helpful, before the performance test can ensure that the basic functions of the Web application work properly, share to everyone.
Wettest working principle
It is a test tool for Web pages that are based on ant to run. Test all the features provided on the page by running different target. It works by using a more well-known htmlunit to test a page's functionality. Its workflow is to simulate a browser event (page provides the function: can call a URL, you can click on a Button,label, etc., you can assign values to the elements on the page), It then verifies whether the expected result is returned by grabbing the value of the title or element on the returned page.
integrated configuration of wettest and MavenConfiguration of Maven
Introduce Webtest-maven-plugin in the Pom.xml of Web applications, define the integration testing phase to perform the tests, validate the validation phase execution results, and generate reports after the system integration test. Also specify the address of the Web app, the file where the test case is located, the path to the generated file, the log level, and the policy that was taken when the error was encountered. This will automatically execute the WebTest test case during the MAVEN build phase. The specific configuration is as follows:
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>webtest-maven-plugin</artifactId> <version>1.0.0</version& Gt <executions> <execution> <id>webtest-test</ Id> <phase>integration-test</phase> <goals > <goal>test</goal> </goals> </execution> <execution> <id >webtest-verify</id> <phase>verify</phase> <goals> <goal>verify-result</goal> </goals> </execution> <execution> <id>webtest-report-html</id> <phase>post-integration-t Est</phase> <goals> <goal>report</g Oal> </goals> </execution> </executions> <configuration> webtest use case file (web-tests.xml) configuration? xml version= "1.0" encoding= "UTF-8"? ><pre name= "code" class= "HTML" ><!--import Config & login XMLF-
<! DOCTYPE Project [<! ENTITY config SYSTEM "./config.xmlf" > <! ENTITY login SYSTEM "./LOGIN.XMLF" >]>
<pre name= "code" class= "HTML" ><!--define the default run of target--
<project basedir= "." default= "run-all-tests" ><!--Introducing WebTest tags in ant--
<taskdef resource= "webtesttaskdefs.properties"/> <!--Introducing Regular expressions: Allows to build a message string WI Th parameter replacement: "User {0} successfully created"--<taskdef resource= "net/sf/antcontrib/ Antcontrib.properties "/> <!--web System many are multi-lingual, do page verification when also need multi-language support, the second cannot find other languages when the default language--<property file=". /.. /.. /target/classes/applicationresources_${user.language}.properties "/> <property file=". /.. /.. /target/classes/applicationresources.properties "/> <!--definition runs all targets, dependent on each function module in the system, login, logout, user action-< Target Name= "run-all-tests" depends= "login,logout,usertests" description= "call and executes all test cases (targets)"/& Gt <!--definition runs user-related Tests,rud, the system does not exist user create function--<target name= "usertests" depends= "Edituser,searchuser , Saveuser "description=" Call and executes all user test cases (targets) "> <echo>successfully ran all user UI test S!</echo> </target> <!--login test, login to the application-<target name= "Login" description= "Runs login test and verifies Home s Title" > &NBS P
<!--define the webtest details of the landing test-<webtest name= "Login" >
<pre name= "code" class= "HTML" > <!--First perform webtest configuration--
&config; <!--specific test steps from Login.xml to <steps> &login; </steps> </webtest> </target> <!--Logout of the application--and <target name= "Logout" Descrip tion= "Runs logout test and verifies Login s Title" > <webtest name= "logout" > &config; <steps> &login; <invoke description= "Get Logout page" url= "/j_security_logout"/> <verifytitle description= "We should see the Login title "text=". *${system}.* "regex=" true "/> </steps> </webtest> </target> <!--Verify The Edit User screen displays Withou T errors--<target name= "Edituser" description= "Tests selecting the ' Edit profile ' forward ' > <webtest name= ' Edituser "> &config; <steps> &login; <invoke description= "Click Edit Profile Button" url= "/userinfo/save"/> <verifytitle description= "We should see The user profile title "text=". *${userprofile.title}.* "regex=" true "/> </steps> </webtest> </target ></project>
because the general test is inseparable from this login interface, so the target of the login to pull out, as well as the connection Server Configuration Config task can also be extracted to put into two separate files.
LOGIN.XMLF: landing Page specific operation
<span style= "color: #3333FF;" ><invoke description= "Get login Page" url= "/"/><verifytitle description= "We should see the login title" text= ". *${system}.*" regex= "true"/><setinputfield description= "set user name" Name= "J_username" value= "admin"/> <setinputfield description= "Set password" name= "J_password" value= "password"/><clickbutton label= "${ Login.submit} "description=" Click the Submit button "/><verifytitle description=" Home Page follows if login OK "text = ". *${welcome}.*" regex= "true"/></span>
Config.xmlf:webtest configuration, use Webtest-maven-plugin as part of the input parameter
<span style= "color: #3333FF;" ><config host= "${host}" port= "${port}" protocol= "http" basepath= "${basepath}" resultpath= "${resultpath}" Saveresponse= "true" resultfile= "Web-tests-result.xml" haltonfailure= "${haltonfailure}" haltonerror= "${ Haltonerror} "summary=" true ">
Attached: Webtest Maven plugin link
WebTest's official link URL
Integrating functional testing with implementing Web Applications-WebTest & Maven