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

39 lines (29 loc) 1.15 kB
import * as fs from 'fs'; import * as path from 'path'; // @ts-ignore import * as yaml from 'js-yaml'; export class FileUtility { public static readFileSyncFromRelativePath(relativePath: string): string { const filePath: string = path.join(process.cwd(), relativePath); const file = fs.readFileSync(filePath, 'utf8'); return file; } public static readFileSyncFromAbsolutePath(filePath: string): string { const file = fs.readFileSync(filePath, 'utf8'); return file; } /* --- yaml --- */ public static readYamlSyncFromRelativePath<T>(relativePath: string): T[] { const file: string = FileUtility.readFileSyncFromRelativePath(relativePath); const yamlObject: T[] = yaml.safeLoad(file); return yamlObject; } public static readYamlSyncFromAbsolutePath<T>(filePath: string): T[] { const file: string = FileUtility.readFileSyncFromRelativePath(filePath); const yamlObject: T[] = yaml.safeLoad(file); return yamlObject; } public static checkIfFileExists(filePath: string) { return fs.existsSync(filePath); } }