【发布时间】:2018-04-06 17:50:55
【问题描述】:
我正在编写一个带有测试用例的 selenium 项目,这里有一个 link 我之前关于它的帖子以获取更多信息。这是我的项目结构:
SeleniumTestSuite
+-- Properties
+-- References
+-- Pages
| +-- BasePage.cs
+-- App.config
+-- HomePageTest.cs
+-- packages.config
我正在使用 common-logging 来实现我的日志记录。这是BasePage.cs里面的代码
using Common.Logging;
using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SeleniumTestSuite.pages
{
class BasePage
{
private static readonly ILog log = LogManager.GetLogger("BasePage");
private IWebDriver driver;
private By banner = By.ClassName("banner");
public BasePage(IWebDriver driver)
{
this.driver = driver;
}
public bool isBannerVisible()
{
log.Info("Testing default page body");
return driver.FindElement(banner).Displayed;
}
}
}
但是当我运行我的测试用例时:
public void testBasePage()
{
basePage = new BasePage(driver);
Assert.IsTrue(basePage.isBannerVisible());
}
我只是在输出窗口中得到以下内容:
------ Discover test started ------
========== Discover test finished: 1 found (0:00:00.1990199) ==========
------ Run test started ------
========== Run test finished: 1 run (0:00:07.3237323) ==========
我没有看到任何日志信息。这是我的App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
<arg key="level" value="INFO" />
<arg key="showLogName" value="true" />
<arg key="showDateTime" value="true" />
<arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
</factoryAdapter>
</logging>
</common>
</configuration>
这里有什么问题?
【问题讨论】:
-
GAC 中是否安装了 Common.Logging 库?如果是,则需要指定程序集的完全限定名称,包括 Version、PublicKeyToken 等
-
你试过
log.Debug而不是log.Info吗?
标签: c# .net selenium logging visual-studio-2015