我已经开发了一个关键字驱动的框架,并且可以使用dataprovider在硒网格上并行运行它(我已将其配置为将所有测试用例读入dataprovider,然后使用属性parallel = true和data-provider -testng中的线程计数)。
我正在使用log4j2进行日志记录。以下是log4j2配置文件。
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Properties>
<Property name="basePath">./logs</Property>
</Properties>
<Appenders>
<RollingFile name="File" fileName="${basePath}/output.log" filePattern="${basePath}/output-%d{yyyy-MM-dd}.log">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
<SizeBasedTriggeringPolicy size="50000" />
</RollingFile>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="File"/>
</Root>
</Loggers>
</Configuration>
但是当我并行运行测试时,创建的日志文件正在逐个显示两个测试的日志。例如,我有两个测试,我想分别为两个测试创建日志,但是将每个测试的日志合并在一起,很难理解哪个日志步骤属于哪个测试。
03:24:45.036 [TestNG-PoolService-0] INFO utility.LogUtilities - ****************************************************************************************
03:24:45.036 [TestNG-PoolService-1] INFO utility.LogUtilities - ****************************************************************************************
03:24:45.043 [TestNG-PoolService-0] INFO utility.LogUtilities - ****************************************************************************************
03:24:45.043 [TestNG-PoolService-0] INFO utility.LogUtilities - $$$$$$$$$$$$$$$$$$$$$ TC01 $$$$$$$$$$$$$$$$$$$$$$$$$
03:24:45.043 [TestNG-PoolService-0] INFO utility.LogUtilities - ****************************************************************************************
03:24:45.044 [TestNG-PoolService-0] INFO utility.LogUtilities - ****************************************************************************************
03:24:45.045 [TestNG-PoolService-1] INFO utility.LogUtilities - ****************************************************************************************
03:24:45.045 [TestNG-PoolService-1] INFO utility.LogUtilities - $$$$$$$$$$$$$$$$$$$$$ TC02 $$$$$$$$$$$$$$$$$$$$$$$$$
03:24:45.045 [TestNG-PoolService-1] INFO utility.LogUtilities - ****************************************************************************************
03:24:45.045 [TestNG-PoolService-1] INFO utility.LogUtilities - ****************************************************************************************
03:24:45.630 [TestNG-PoolService-0] INFO utility.LogUtilities - -------- Starting WebDriver --------
03:24:45.680 [TestNG-PoolService-1] INFO utility.LogUtilities - -------- Starting WebDriver --------
03:24:51.669 [TestNG-PoolService-1] INFO utility.LogUtilities - -------- Starting: adminopenhomepage -----------
03:24:51.669 [TestNG-PoolService-1] INFO utility.LogUtilities - ---------------- Opening Adming Home Page --------
03:24:52.893 [TestNG-PoolService-1] INFO utility.LogUtilities - ---------------- Admin Home Page is opened successfully --------
03:24:52.894 [TestNG-PoolService-1] INFO utility.LogUtilities - -------- Starting: adminenterusername -----------
03:24:52.894 [TestNG-PoolService-1] INFO utility.LogUtilities - ------------ Finding the admin username --------
03:24:52.971 [TestNG-PoolService-1] INFO utility.LogUtilities - ------------ Admin username found successfully --------
03:24:52.971 [TestNG-PoolService-1] INFO utility.LogUtilities - ---------------- Entering data into username filed --------
03:24:53.138 [TestNG-PoolService-1] INFO utility.LogUtilities - ---------------- Data entered into username filed --------
03:24:53.138 [TestNG-PoolService-1] INFO utility.LogUtilities - -------- Starting: adminenterpassword -----------
如果您看到以上内容,则将TC01和TC02的日志合并在一起,很难找出哪个日志消息属于哪个测试用例。
那么,如何配置xml文件以根据线程数将日志写入不同的文件,或者是否还有其他方法可以分别打印日志?
谢谢。