【问题标题】:How to make lighthouse audit of site from MSTest如何从 MSTest 对站点进行灯塔审计
【发布时间】:2019-09-07 10:27:40
【问题描述】:

我需要以编程方式检查谷歌灯塔审计的结果。 F.e.来自 MSTest(如单元或完整性测试)。

如何从 c# 代码分析我的网站?

【问题讨论】:

    标签: c# .net asp.net-core audit lighthouse


    【解决方案1】:

    您可以使用lighthouse.net 库。

    请注意,它需要在您的机器上安装 Node Js。

    [TestClass]
    public class LighthouseTest
    {
        [TestMethod]
        public async Task ExampleComAudit()
        {
            var lh = new Lighthouse();
            var res = await lh.Run("http://example.com");
            Assert.IsNotNull(res);
            Assert.IsNotNull(res.Performance);
            Assert.IsTrue(res.Performance > 0.5m);
    
            Assert.IsNotNull(res.Accessibility);
            Assert.IsTrue(res.Accessibility > 0.5m);
    
            Assert.IsNotNull(res.BestPractices);
            Assert.IsTrue(res.BestPractices > 0.5m);
    
            Assert.IsNotNull(res.Pwa);
            Assert.IsTrue(res.Pwa > 0.5m);
    
            Assert.IsNotNull(res.Seo);
            Assert.IsTrue(res.Seo > 0.5m);
        }
    }
    

    【讨论】:

    • 回答自己的问题?
    • @RomanDoskoch,是的。见stackoverflow.blog/2011/07/01/…
    • 但是您在自己的存储库中提供了具有相同代码的链接。为什么需要在这里复制它。 Github 还不够吗?
    • @dima_horror 当我在调试模式下对任何 url 运行它时,它永远不会在 lh.Run 行之后返回。它运行了几分钟而没有超时或抛出异常,它永远不会到达下一行。我从 github 下载了您的解决方案并在 NpmTests 中运行了您的 NpmExistTest,我得到了相同的行为,它永远不会到达我在第 17 行放置的断点。我是否缺少一个技巧来让它运行?
    • @RobertCorvus,请在 github 页面上创建一个问题,以便我们与 DM 交流
    猜你喜欢
    • 1970-01-01
    • 2021-02-09
    • 1970-01-01
    • 2019-03-31
    • 2018-08-27
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 2021-01-06
    相关资源
    最近更新 更多