我们正在针对生产网站运行 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/