Use Selenium/ant to do Web application Remote Automation testing

Source: Internet
Author: User
Tags mkdir sleep

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           &nbsp ...            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}"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.