typescript - 如何在 Protractor ( typescript )中制作更具描述性的错误日志消息

标签 typescript testing error-handling protractor

我们正在针对生产网站运行 Protractor (用 typescript 编写)。有谁知道 Protractor 测试失败时如何输出一些日志消息?我现在所拥有的基本上只是一条是/否消息,如下所示:

10) Query page accuracy test. Comparison of page data to data extracted from excel. Test begins...
  Message:
    Expected false to be truthy.
  Stack:
    Error: Failed expectation
        at C:\xampp\htdocs\kap\frontend\src\app\qa\qa.js:147:103
        at step (C:\xampp\htdocs\kap\frontend\src\app\qa\qa.js:33:23)
        at Object.next (C:\...

等 这是我们测试的行:

expect(htmlValue == excelValue || (htmlValue === "0" && excelValue == "NaN")).toBeTruthy();

如何在测试失败时添加更具描述性的消息?谢谢任何人,我是 Protractor 的新手,但我之前做过 QA 自动化测试。

最佳答案

您可以像这样在 ToBeTruthy 中添加描述:

expect(htmlValue == excelValue || (htmlValue === "0" && excelValue == "NaN")).toBeTruthy("description why I checked this")

如果您愿意,可以像这样显示失败的测试值:

expect(
  htmlValue == excelValue || (htmlValue === '0' && excelValue == 'NaN'),
).toBeTruthy(
  `HTML differ form Excel. HTML: ${htmlValue}; Excel: ${excelValue}`,
);

几乎所有 jasmine Matchers 都接受一个 expectationFailOuput 参数:

toBe(expected: any, expectationFailOutput?: any): Promise<void>;
toEqual(expected: any, expectationFailOutput?: any): Promise<void>;
toMatch(expected: string | RegExp | Promise<string | RegExp>, expectationFailOutput?: any): Promise<void>;
toBeDefined(expectationFailOutput?: any): Promise<void>;
toBeUndefined(expectationFailOutput?: any): Promise<void>;
toBeNull(expectationFailOutput?: any): Promise<void>;
toBeTruthy(expectationFailOutput?: any): Promise<void>;
toBeFalsy(expectationFailOutput?: any): Promise<void>;
toContain(expected: any, expectationFailOutput?: any): Promise<void>;
toBeLessThan(expected: number | Promise<number>, expectationFailOutput?: any): Promise<void>;
toBeLessThanOrEqual(expected: number | Promise<number>, expectationFailOutput?: any): Promise<void>;
toBeGreaterThan(expected: number | Promise<number>, expectationFailOutput?: any): Promise<void>;
toBeGreaterThanOrEqual(expected: number | Promise<number>, expectationFailOutput?: any): Promise<void>;
toBeCloseTo(expected: number | Promise<number>, precision?: any, expectationFailOutput?: any): Promise<void>;

您将在 jasminewd2 depot 中找到 Matchers 定义

关于typescript - 如何在 Protractor ( typescript )中制作更具描述性的错误日志消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58433284/

相关文章:

javascript - TypeScript:你能根据函数的参数定义一个返回类型结构吗?

reactjs - 测试 MobX 组件

email - GCP错误报告-通知所有者的电子邮件

javascript - 不知道如何用 Jasmine 测试这个异步函数

php - 如果发生错误,通过php重定向到另一个页面?

php - 引用 - 这个错误在 PHP 中意味着什么?

angular - Angular-Cli 中 EventEmitter 与输出装饰器的区别

visual-studio - ts 属性推送在 Angular 代码 VS 中的类型 '{}' 上不存在

angular - MemoizedSelector 不可分配给类型为 'string' 的参数

angularjs - 在使用 karma 进行测试时,**phantom js** 比 **chrome** 有什么用?