【问题标题】:Selenium test log.Info not visibleSelenium 测试日志。信息不可见
【发布时间】: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


【解决方案1】:

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

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

最后,我将完整的日志附加到 Visual Studio Online 上的测试用例中

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-15
    • 1970-01-01
    • 1970-01-01
    • 2017-02-08
    • 2019-06-05
    相关资源
    最近更新 更多