The client side primarily uses an ant build file to start JUnit's testcase, which in turn launches the test method in TestCase to connect and activate the server side for automated testing. The code for the client-side core test unit is as follows:
Java code package com.tail.p2test; import junit.framework.test; import junit.framework.testcase; import junit.framework.testsuite; import junit.textui.testrunner; import com.thoughtworks.selenium.defaultselenium; import com.thoughtworks.selenium.selenium; public class demotest extends testcase { private Selenium selenium; public void setup () throws exception { string url = "http://localhost:8080/"; selenium = new defaultselenium (" localhost ", 4444, " *chrome ", url);  &NBSp; selenium.start (); } protected void TearDown () throws exception { Selenium.stop (); } public void testnew () throws exception { selenium.settimeout ("100000" ); selenium.open ("/login.action"); selenium.type ("username", "admin"); selenium.type ("password", "123"); selenium.click ("//input[@value= ' log in '] "); selenium.waitforpagetoload ("100000"); thread.sleep (10000); for (int second = 0;; second++) { if (second >= 60) fail ("timeout"); try { if ( Selenium.iselementpresent ("Signlabel")) break; } catch (exception e) {} thread.sleep (1000); } // omit lines   ... selenium.open ("/main.action"); } }
Of course, the app can run directly in eclipse, but in order to be more flexible, we consider using ant script to control the operation of the client, one of the benefits of using an ant script is that it can be easily and quickly output the test report, in this case the report is exported to the reporting directory.
The script for Ant's Build.xml is detailed below:
XML code<?xmlVersion= "1.0"?><projectName= "Portal" default= "JUnit" basedir= "."><propertyName= "Source.dir" value= "src"/><propertyName= "Build.dir" value= "Build"/><propertyName= "Lib.dir" Value= "Lib"/><propertyName= "Classes.dir" value= "${build.dir}/classes"/><propertyName= "Report.dir" value= "Report"/><!--==================================================================--<!--C L E A N -<!--================================================================== -<targetName= "Clean"><deleteDir= "${classes.dir}"/> <mkdirDir= "${classes.dir}"/><deleteDir= "${report.dir}"/><mkdirDir= "${report.dir}"/></target><!--==================================================================--<!--C O M P I L E -<!--================================================================== -<targetName= "Compile" depends= "clean"><!--Local project Jars--<patternsetId= "Lib.includes.compile"><includeName= "*.jar"/></patternset><filesetDir= "${lib.dir}" id= "Lib.compile"><patternsetRefid= "Lib.includes.compile"/></fileset><pathconverttargetos= "Windows" property= "Libs.compile" refid= "Lib.compile"/><!--compile--<javacSrcdir= "${source.dir}" destdir= "${classes.dir}" classpath= "${libs.compile}" includes= "**/*.java" debug= "true"></javac></target><!--==================================================================--<!--J U N I T -<!--================================================================== -<targetName= "JUnit" depends= "compile"><junitPrintsummary= "on" fork= "true" Haltonfailure= "false" failureproperty= "tests.failed" showoutput= "true"><classpath><pathelementPath= "${classes.dir}"/><filesetDir= "${lib.dir}"><includeName= "**/*.jar"/></fileset></classpath><formatterType= "XML"/><batchtestTodir= "${report.dir}"><filesetDir= "${classes.dir}"><includeName= "**/*test.*"/></fileset></batchtest></junit> <junitreportTodir= "${report.dir}"><filesetDir= "${report.dir}"