【问题标题】:How to assert that image contains required text in Sakuli?如何断言图像包含 Sakuli 中所需的文本?
【发布时间】:2020-09-16 14:23:07
【问题描述】:

我想监控仪表板,示例如下: 我想断言它包含以下指定的文本,会截取一些小屏幕截图,然后断言图像具有以下文本有效吗?还是有更好的方法来做到这一点?

【问题讨论】:

    标签: javascript sahi


    【解决方案1】:

    答案取决于仪表板的实现。知道应该断言哪些文本会很有帮助。

    如果是网络应用程序
    我建议使用assertion API 中的_assertContainsText

    Sakuli V2 示例:

    (async () => {
      const testCase = new TestCase();
      try {
        await _navigateTo("https://stackoverflow.com");
        const contentHeading = await _fetch(_heading1(0, _in(_div("content"))))
        await _highlight(contentHeading)
        await _assertContainsText("We <3 people who code", contentHeading)
      } catch (e) {
        await testCase.handleException(e);
      } finally {
        await testCase.saveResult();
      }
    })();
    
    

    如果是原生 UI 应用程序
    Sakuli 2 目前无法在屏幕上查找文本。它已计划但尚未完成。确实可以断言屏幕上存在部分。

    给定以下图片为needle.png

    (async () => {
      const testCase = new TestCase();
      const url = "https://your-dashboard.com";
      const screen = new Region();
      const env = new Environment();
      try {
        await _navigateTo(url);
        await env.setSimilarity(0.95);
        await screen
          .exists("needle.png", 1)
          .highlight(1);
      } catch (e) {
        await testCase.handleException(e);
      } finally {
        await testCase.saveResult();
      }
    })();
    

    重用这个 sn-p 时,很可能需要创建一个新的针头图像,因为我从您提供的屏幕截图中截取了它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-06
      • 2015-12-29
      • 1970-01-01
      • 2013-10-03
      • 2018-04-28
      • 1970-01-01
      • 1970-01-01
      • 2020-01-16
      相关资源
      最近更新 更多