【问题标题】:How to fetch the specific values in the html file using shell script如何使用 shell 脚本获取 html 文件中的特定值
【发布时间】:2021-01-16 22:19:08
【问题描述】:

我有一个将基于测试套件执行生成的 html 文件。它包含测试运行详细信息,例如在特定运行中通过和失败的测试用例数量。我对 shell 脚本非常陌生,不知道如何从 jenkins $Workspace 中生成的 .html 中提取值。

HTML sn-p :(仅复制特定标签,而不是复制整个 .html 文件):

<ul class="quick-summary--list---2_80W">
    <li class="quick-summary--item---bfSQ0 quick-summary--passes---3IjYH" title="Passed">
       <button type="button">
           <i class="material-icons quick-summary--icon---TW1oG quick-summary--circle-icon---1HDS7"></i>
             9
      </button>
    </li>
   <li class="quick-summary--item---bfSQ0 quick-summary--failures---14s29" title="Failed">
       <button type="button">
          <i class="material-icons quick-summary--icon---TW1oG quick-summary--circle-icon---1HDS7"></i>
              0
       </button>    
    </li>
</ul>

在上面的示例 .html 文件中,我正在查看以下 xpath 中的数字:

.//*[@title='Passed']/button  // It should return 9 

.//*[@title='Failed']/button  // It should return 0

如何从在上述特定 XPATH 中生成值的 html 文件中获取这些数字。

请帮助我实现这一目标。

更新:

尝试低于一个,但它返回空:

$ xmllint --html  --xpath "//*[@title='Passed']/button" result.html
XPath set is empty

【问题讨论】:

  • 应该有一种方法可以以更简单的解析格式导出测试结果。 HTML 通常是供人类读取结果的,而不是供机器解析的。查看测试框架的文档以获取更多信息。

标签: shell jenkins xmllint


【解决方案1】:

问题似乎是由于您的 html sn-p 中&lt;i&gt;nodes 中的不寻常字符(不确定这是什么)。

绕过角色的一种有点复杂的方法是:

xmllint --html  --xpath "substring-after(normalize-space(//li[@title='Passed']/button),' ')"   result.html

和

xmllint --html  --xpath "substring-after(normalize-space(//li[@title='Failed']/button),' ')"   result.html

输出确实是9 和0。

【讨论】:

    猜你喜欢
    • 2019-10-15
    • 1970-01-01
    • 2022-12-05
    • 2019-09-19
    • 2020-04-17
    • 1970-01-01
    • 2022-11-14
    • 2013-03-25
    相关资源
    最近更新 更多