【问题标题】:Getting log4j error while running data driven testing code运行数据驱动测试代码时出现 log4j 错误
【发布时间】:2016-03-03 12:05:28
【问题描述】:

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

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();      
        }
    }   
}

【问题讨论】:

    标签: java junit log4j


    【解决方案1】:

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

    【讨论】:

    • 我该怎么做。你能详细解释一下吗
    • @Priyanka 在您的测试方法开始时添加以下说明可能会解决您的问题:org.apache.log4j.BasicConfigurator.configure();
    • 我如何提供 log4j.properties 作为运行时类路径的一部分
    • @priyanka 通常,您可以使用系统属性 log4j.configuration 告诉 log4j 您的 log4j.properties 文件在哪里。例如,将 -Dlog4j.configuration=./config/log4j.properties 选项添加到运行测试的 JVM。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-29
    • 1970-01-01
    • 1970-01-01
    • 2014-05-13
    • 1970-01-01
    相关资源
    最近更新 更多