Skip to content

Commit

Permalink
feat: multi-locales support
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkenos committed Dec 8, 2023
1 parent 4b279f3 commit 66643bc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- gherkin statements that can be used out of the box
- page and element expected conditions
- generic classes for page objects support
- multiple locale support
- internal polling and retries
- reporters:
- [built-in cucumber reporter plugins](https://cucumber.io/docs/cucumber/reporting/?sbsearch=reporting&lang=javascript)
Expand Down
5 changes: 3 additions & 2 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ export function configure(overrides?: Partial<Config>) {
const debug = process.env.DEBUG === "true" || overrides?.debug || false;
const downloadsDir = path.join(baseDir, process.env.DOWNLOADS_DIR || overrides?.downloadsDir || "downloads/");
const headless = process.env.HEADLESS === "true" || overrides?.headless || false;
const locale = process.env.LOCALE || overrides?.locale || undefined;
const logLevel = process.env.LOG_LEVEL || overrides?.logLevel || "info";
const pages = (overrides?.pages || ["fixtures/pages/**/*.page.ts"]).map(i => path.join(baseDir, i));
const pages = (overrides?.pages || ["fixtures/pages/**/*.page{,.*}.ts"]).map(i => path.join(baseDir, i));
const resultsDir = path.join(baseDir, process.env.RESULTS_DIR || overrides?.resultsDir || "results/");
const snapshotsDir = path.join(baseDir, process.env.SNAPSHOTS_DIR || overrides?.snapshotsDir || "snapshots/");
const timeout = +process.env.TIMEOUT || overrides?.timeout || 30000;
Expand All @@ -46,7 +47,7 @@ export function configure(overrides?: Partial<Config>) {
fs.removeSync(snapshots[key].diffDir);
fs.mkdirsSync(snapshots[key].expectedDir);
});
const custom = { baseDir, baseURL, browser, browserOptions, contextOptions, debug, downloadsDir, headless, logLevel, pages, resultsDir, snapshots, timeout };
const custom = { baseDir, baseURL, browser, browserOptions, contextOptions, debug, downloadsDir, headless, locale, logLevel, pages, resultsDir, snapshots, timeout };

// cucumber options defaults
const config = {
Expand Down
2 changes: 2 additions & 0 deletions src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export interface Config extends Omit<IConfiguration, "publish" | "publishQuiet">
/** Custom: Directory to store browser downloads in, relative to the config file */
downloadsDir: string;
headless: boolean;
/** Custom: The active locale. Used as primary context for reading page object classes */
locale: string;
/** Custom: Level of logging verbosity */
logLevel: "trace" | "debug" | "info" | "warn" | "error" | "silent";
/** Custom: Array of globs pointing to your page object files, relative to the config file */
Expand Down
7 changes: 4 additions & 3 deletions src/core/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ export abstract class World<ParametersType = any> extends CucumberAllureWorld {
}


findPageObject(page: string, persist = false) {
const file = this.pageObjects.find(i => path.basename(i).split(".")[0].toLowerCase() === page.toLowerCase());
findPageObject<T = PageObject>(page: string, persist = false) {
const files = this.pageObjects.filter(i => path.basename(i).split(".")[0].toLowerCase() === page.toLowerCase());
const file = files.find(i => path.basename(i).includes(`.page.${this.config.locale}`)) || files[0];

if (!file) {
throw new Error(`\n Unable to resolve "${page}" from any of the available page object files:
Expand All @@ -73,7 +74,7 @@ export abstract class World<ParametersType = any> extends CucumberAllureWorld {
this.pageObject = pageObject;
}

return pageObject;
return pageObject as T;
}

findPageObjectLocator(page: string, element: string, index?: number) {
Expand Down

0 comments on commit 66643bc

Please sign in to comment.