运行数据驱动的测试代码时出现log4j错误

时间:2016-03-03 12:05:28

标签: java junit log4j

我正在运行以下数据驱动的测试代码,但收到以下错误:

log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. 

任何人都可以帮我解决这个问题

import java.io.File;
import java.io.FileInputStream;

import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class DataDriven_Ex {

    static WebElement searchbox;
    public static void main(String[] args) {
        FirefoxDriver driver = new FirefoxDriver();
        driver.get("http://www.amazon.in");
        WebElement searchbox = driver.findElement(By.xpath("//*[@id='twotabsearchtextbox']"));
    }

    @Test
    public void test() throws Exception {

        File file = new File("F://Selenium excel//DataDriven.xlsx");
        FileInputStream fs = new FileInputStream(file);
        XSSFWorkbook wb = new XSSFWorkbook(fs);
        XSSFSheet sh = wb.getSheet("Sheet1");

        int rowcount = sh.getLastRowNum();

        for (int i = 0; i<=rowcount;i++)
        {   
            String keyword = sh.getRow(i).getCell(0).getStringCellValue();
            searchbox.sendKeys(keyword);

            searchbox.submit();      
        }
    }   
}

1 个答案:

答案 0 :(得分:0)

正如警告信息中所述,您应该在http://logging.apache.org/log4j/1.2/faq.html#noconfig看到完整的说明。您必须检查是否提供log4j.propertieslog4j.xml作为运行时类路径的一部分(即可在运行时从Classloader访问)。