UNPKG

tlc-core-automation-framework-v3-wdio-v9

Version:

Background: - We are following multi-layer automation framework architecture using webdriver.io + cucumber + typescript This core framework has been implemented with generic utility functions and cucumber steps, which can be easily consumed by another fra

121 lines (102 loc) 3.87 kB
import {browser, $, $$, expect} from '@wdio/globals' export class CustomExpect { static defaultExceptionMsg: string = "Exception Message is Missing"; public static expectToBeTruthy(condition: any, failMsg: string = CustomExpect.defaultExceptionMsg) { try { expect(condition).toBeTruthy(); } catch (e) { throw new Error(failMsg); } } public static expectToBeTrue(condition: any, failMsg: string = CustomExpect.defaultExceptionMsg) { try { expect(condition).toBeTruthy(); } catch (e) { throw new Error(failMsg); } } public static expectToBeFalsy(condition: any, failMsg: string = CustomExpect.defaultExceptionMsg) { try { expect(condition).toBeFalsy(); } catch (e) { throw new Error(failMsg); } } public static expectToBeFalse(condition: any, failMsg: string = CustomExpect.defaultExceptionMsg) { try { expect(condition).toBeFalsy(); } catch (e) { throw new Error(failMsg); } } public static expectToMatch(actualValue: any, expectedValue: any, failMsg: string = CustomExpect.defaultExceptionMsg) { try { expect(actualValue).toMatch(expectedValue); } catch (e) { throw new Error(failMsg); } } public static expectNotToMatch(actualValue: any, expectedValue: any, failMsg: string = CustomExpect.defaultExceptionMsg) { try { expect(actualValue).not.toMatch(expectedValue); } catch (e) { throw new Error(failMsg); } } public static expectToEqual(actualValue: any, expectedValue: any, failMsg: string = CustomExpect.defaultExceptionMsg) { try { expect(expectedValue).toEqual(actualValue); } catch (e) { throw new Error(failMsg); } } public static expectNotToEqual(actualValue: any, expectedValue: any, failMsg: string = CustomExpect.defaultExceptionMsg) { try { expect(expectedValue).not.toEqual(actualValue); } catch (e) { throw new Error(failMsg); } } public static expectToContain(mainString: any, substring: any, failMsg: string = CustomExpect.defaultExceptionMsg) { try { expect(mainString).toContain(substring) } catch (e) { throw new Error(failMsg); } } public static expectNotToContain(mainString: any, substring: any, failMsg: string = CustomExpect.defaultExceptionMsg) { try { expect(mainString).not.toContain(substring) } catch (e) { throw new Error(failMsg); } } public static expectToBe(actualValue: any, expectedValue: any, failMsg: string = CustomExpect.defaultExceptionMsg) { try { expect(actualValue).toBe(expectedValue); } catch (e) { throw new Error(failMsg); } } public static expectNotToBe(actualValue: any, expectedValue: any, failMsg: string = CustomExpect.defaultExceptionMsg) { try { expect(actualValue).not.toBe(expectedValue); } catch (e) { throw new Error(failMsg); } } public static expectToHaveLength(inputValue: any, expectedLength: number, failMsg: string = CustomExpect.defaultExceptionMsg) { try { expect(inputValue.length == expectedLength).toBeTruthy(); } catch (e) { throw new Error(failMsg); } } public static expectNotToHaveLength(inputValue: any, expectedLength: number, failMsg: string = CustomExpect.defaultExceptionMsg) { try { expect(inputValue.length == expectedLength).toBeFalsy(); } catch (e) { throw new Error(failMsg); } } }