Selenium测试log.Info不可见

时间:2017-02-01 17:29:11

标签: c# .net selenium logging visual-studio-2015

我正在编写一个包含测试用例的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>

这里有什么问题?

1 个答案:

答案 0 :(得分:1)

我使用XUnit从我的测试程序集运行Selenium测试,输出数据相当简单:

https://xunit.github.io/docs/capturing-output.html

最后,我在Visual Studio Online上附加了测试用例的完整日志