Apache Ant:java.lang.ClassNotFoundException:

时间:2014-02-14 19:37:37

标签: java selenium ant junit

我正在尝试使用Apache Ant运行用java编写的selenium测试用例文件。要设置此配置,请按this tutorial.

下面的

是我在build.xml中的ant配置

<?xml version="1.0" encoding="UTF-8"?> 
   <project name="Hello World Project" default="info">
   <target name="info"> 
  <junit printsummary="yes" haltonfailure="yes">
    <classpath>  
      <pathelement path="lib\junit-4.10.jar" />
    </classpath> 
    <test name="com.lo.test.selenium.AssignCampaignTestCase"  haltonfailure="no" outfile="result"> 
      <formatter type="plain"/>
      <formatter type="xml"/> 
    </test> 
  </junit>
</target>
</project>

但它显示的错误如下:

          Testsuite: com.lo.test.selenium.AssignCampaignTestCase
    Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 sec
        Caused an ERROR
    com.lo.test.selenium.AssignCampaignTestCase
    java.lang.ClassNotFoundException: com.lo.test.selenium.AssignCampaignTestCase
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:270)

AssignCampaignTestCase.java中的测试用例代码

    package com.lo.test.selenium; 
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.Properties;
import java.util.ResourceBundle;

import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import javax.mail.Store; 
import javax.ws.rs.core.MediaType;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
import com.sun.jersey.multipart.FormDataMultiPart;
import com.sun.jersey.multipart.impl.MultiPartWriter;


/**
 * @author Ashutosh
 *
 */
 public class AssignCampaignTestCase {
     private static ResourceBundle rb = ResourceBundle.getBundle("global-messages");
    static WebDriver driver = new FirefoxDriver();  //Make it static in order to make one instance of this class(helps to avoid opening of 2 browsers at once)
    @Test
    public void campaignEmailTestCase() throws InterruptedException { 
        AssignCampaignTestCase emTesObj=new AssignCampaignTestCase();  
        // CommonMethods commonMethods=new CommonMethods();
        String fName="test LO";
        Integer LeadId=570903;
        String campaignName="2GetMoreLeads"; 
        String SubjName="Welcome to your 5-day challenge and tips";   //NOTE: No problem,Type without double quotes. It will work for you 
        doLogin(driver); 
        emTesObj.goToLeadsListPage();
        emTesObj.searchByFirstName(fName);//without this also,it will work but Gives you the correct navigation on UI
        emTesObj.waitBeforePageLoads(LeadId.toString()); //pass the Id attribute which you aspect to see after the page is loaded
        emTesObj.assignCampaign(LeadId, campaignName);  
        emTesObj.readRecentEmail(SubjName);  
    }


     //shows you the leads List Page     
     public void goToLeadsListPage(){ 
         driver.get("http://www.xxxxx.com/orderManagement/xxxx.action");
     }
       .................
       .................
       .................

这是我的项目结构::::

enter image description here

请帮我用Ant运行我的项目。

1 个答案:

答案 0 :(得分:0)

尝试在类路径中添加selenium jar文件。目前你只添加了junit。