Skip to content

Commit c6641f7

Browse files
authored
Merge pull request #9 from AutomateThePlanet/bellatrix-extras
Added extras project, added Services hooks and added onError listener for all hooks
2 parents 2f43318 + 9a0425b commit c6641f7

File tree

75 files changed

+616
-149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+616
-149
lines changed

@bellatrix/appium/tsconfig.json

-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
"baseUrl": "src",
44
"rootDir": "src",
55
"outDir": "lib",
6-
"paths": {
7-
"*": [ "@bellatrix/appium/*" ],
8-
"@bellatrix/core/*": [ "../../core/src/*" ]
9-
},
106
"lib": [ "ESNext" ],
117
"module": "esnext",
128
"target": "esnext",
@@ -24,9 +20,6 @@
2420
"forceConsistentCasingInFileNames": true,
2521
"allowJs": false
2622
},
27-
"references": [
28-
{ "path": "../core" }
29-
],
3023
"include": ["**/*.ts"],
3124
"exclude": ["node_modules"]
3225
}

@bellatrix/core/src/types/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export type BellatrixConfigurationOverride = BellatrixConfiguration
4545
// "delayBeforeAction": 0
4646
// },
4747
// "executionSettings": {
48-
// "browserAutomationTool": "playwright", // selenium, cypress
48+
// "browserController": "playwright", // selenium, cypress
4949
// "browser": "chrome", // firefox, safari, edge
5050
// "headless": false,
5151
// "executionType": "local" // remote

@bellatrix/extras/package-lock.json

+79
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

@bellatrix/extras/package.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "@bellatrix/extras",
3+
"version": "0.0.1",
4+
"type": "module",
5+
"exports": {
6+
"./hooks": "./src/hooks/index.ts",
7+
"./plugins": "./src/plugins/index.ts"
8+
},
9+
"dependencies": {
10+
"@bellatrix/core": "file:../core",
11+
"@bellatrix/web": "file:../web"
12+
},
13+
"peerDependencies": {
14+
"typescript": "^5.0.0"
15+
}
16+
}

@bellatrix/web/src/components/hooks/DefaultWebComponentHooks.ts renamed to @bellatrix/extras/src/hooks/ExtraWebHooks.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { WebComponentHooks } from '@bellatrix/web/components/utilities';
22
import { Anchor, Button, CheckBox, ColorInput, DateInput, DateTimeInput, EmailField, FileInput, MonthInput, NumberInput, PasswordField, PhoneField, RangeInput, SearchField, Select, TextArea, TextField, TimeInput, UrlField, WebComponent, WeekInput } from '@bellatrix/web/components';
33

4-
export class DefaultWebComponentHooks {
4+
// TODO: maybe decouple it in different web-extras plugin so extras does not import @bellatrix/web too?
5+
export class ExtraWebHooks {
56
static addComponentBDDLogging(): void {
6-
const locale = Intl.DateTimeFormat().resolvedOptions().locale;// TODO: make it configurable
7-
const shouldObfuscatePassword = true; // TODO: add as option in configuration
7+
const locale = Intl.DateTimeFormat().resolvedOptions().locale; // TODO: add locale option in the config
88

99
WebComponentHooks.addListenerTo(Anchor).before('click', (anchor) => console.log(`clicking ${anchor.componentName}`));
1010
WebComponentHooks.addListenerTo(Button).before('click', (button) => console.log(`clicking ${button.componentName}`));
@@ -17,7 +17,7 @@ export class DefaultWebComponentHooks {
1717
WebComponentHooks.addListenerTo(FileInput).before('upload', (fileInput, filePath) => console.log(`uploading '${filePath}' into ${fileInput.componentName}`));
1818
WebComponentHooks.addListenerTo(MonthInput).before('setMonth', (monthInput, year, month) => console.log(`setting ${monthInput} to ${new Date(year, month - 1).toLocaleDateString(locale, { month: 'long', year: 'numeric' })}`));
1919
WebComponentHooks.addListenerTo(NumberInput).before('setNumber', (numberInput, number) => console.log(`setting ${numberInput.componentName} to ${number}`));
20-
WebComponentHooks.addListenerTo(PasswordField).before('setPassword', (passwordField, password) => console.log(`typing ${shouldObfuscatePassword ? '********' : password} into ${passwordField.componentName}`));
20+
WebComponentHooks.addListenerTo(PasswordField).before('setPassword', (passwordField, _) => console.log(`typing '********' into ${passwordField.componentName}`));
2121
WebComponentHooks.addListenerTo(PhoneField).before('setPhone', (phoneField, phone) => console.log(`typing '${phone}' into ${phoneField.componentName}`));
2222
WebComponentHooks.addListenerTo(RangeInput).before('setValue', (rangeInput, value) => console.log(`setting ${rangeInput.componentName} to ${value}`));
2323
WebComponentHooks.addListenerTo(SearchField).before('setSearch', (searchField, search) => console.log(`typing '${search}' into ${searchField.componentName}`));
@@ -29,7 +29,8 @@ export class DefaultWebComponentHooks {
2929
WebComponentHooks.addListenerTo(TimeInput).before('setTime', (timeInput, hours, minutes, seconds) => console.log(`setting ${timeInput.componentName} to ${[hours, minutes, seconds].map(n => String(n ?? 0).padStart(2, '0')).join(':')}`));
3030
WebComponentHooks.addListenerTo(UrlField).before('setUrl', (urlField, url) => console.log(`typing '${url}' into ${urlField.componentName}`));
3131
WebComponentHooks.addListenerTo(WeekInput).before('setWeek', (weekInput, year, weekNumber) => console.log(`setting ${weekInput.componentName} to ${year}-W${weekNumber.toString().padStart(2, '0')}`));
32-
WebComponentHooks.addListenerTo(WebComponent).before('scrollToVisible', (component) => console.log(`scrolling ${component} into view`));
33-
WebComponentHooks.addListenerTo(WebComponent).before('hover', (component) => console.log(`hovering ${component}`)); // TODO: add focus method?
32+
WebComponentHooks.addListenerTo(WebComponent).before('scrollIntoView', (component) => console.log(`scrolling ${component} into view`));
33+
WebComponentHooks.addListenerTo(WebComponent).before('hover', (component) => console.log(`hovering ${component}`));
34+
WebComponentHooks.addListenerTo(WebComponent).before('focus', (component) => console.log(`focusing ${component}`));
3435
}
3536
}

@bellatrix/extras/src/hooks/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './ExtraWebHooks';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Plugin } from '@bellatrix/core/infrastructure';
2+
import { TestMetadata } from '@bellatrix/core/test/props';
3+
4+
export class LogLifecyclePlugin extends Plugin {
5+
override async preBeforeTest(testMetadata: TestMetadata): Promise<void> {
6+
console.log('\n==================================================================================\n' +
7+
`starting test: ${testMetadata.suiteClass.name} > ${testMetadata.testMethod.name}\n`);
8+
}
9+
10+
override async postAfterTest(_: TestMetadata): Promise<void> {
11+
console.log('\n==================================================================================\n');
12+
}
13+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './LogLifecyclePlugin';

@bellatrix/extras/tsconfig.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": "src",
4+
"rootDir": "src",
5+
"outDir": "lib",
6+
"lib": [ "ESNext", "DOM" ],
7+
"module": "esnext",
8+
"target": "esnext",
9+
"moduleResolution": "bundler",
10+
"moduleDetection": "force",
11+
"noImplicitOverride": true,
12+
"experimentalDecorators": true,
13+
"emitDecoratorMetadata": true,
14+
"composite": true,
15+
"sourceMap": true,
16+
"strict": true,
17+
"downlevelIteration": true,
18+
"skipLibCheck": true,
19+
"allowSyntheticDefaultImports": true,
20+
"forceConsistentCasingInFileNames": true,
21+
"allowJs": false
22+
},
23+
"include": ["**/*.ts"],
24+
"exclude": ["node_modules"]
25+
}

@bellatrix/web/package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
"./infrastructure": "./src/infrastructure/index.ts",
1212
"./pages": "./src/pages/index.ts",
1313
"./pages/decorators": "./src/pages/decorators/index.ts",
14-
"./infrastructure/browserautomationtools/core": "./src/infrastructure/browserautomationtools/core/index.ts",
15-
"./infrastructure/browserautomationtools/playwright": "./src/infrastructure/browserautomationtools/playwright/index.ts",
16-
"./infrastructure/browserautomationtools/selenium": "./src/infrastructure/browserautomationtools/selenium/index.ts",
14+
"./infrastructure/browsercontroller/core": "./src/infrastructure/browsercontroller/core/index.ts",
15+
"./infrastructure/browsercontroller/playwright": "./src/infrastructure/browsercontroller/playwright/index.ts",
16+
"./infrastructure/browsercontroller/selenium": "./src/infrastructure/browsercontroller/selenium/index.ts",
1717
"./services": "./src/services/index.ts",
18+
"./services/decorators": "./src/services/decorators/index.ts",
19+
"./services/utilities": "./src/services/utilities/index.ts",
1820
"./plugins": "./src/plugins/index.ts",
1921
"./test": "./src/test/index.ts",
2022
"./types": "./src/types/index.ts",

@bellatrix/web/src/components/core/ComponentsList.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { BrowserAutomationTool } from '@bellatrix/web/infrastructure/browserautomationtools/core';
1+
import { BrowserController } from '@bellatrix/web/infrastructure/browsercontroller/core';
2+
import { resolveParentElement } from '@bellatrix/web/components/decorators';
23
import { FindStrategy } from '@bellatrix/web/findstrategies';
34
import { ServiceLocator } from '@bellatrix/core/utilities';
4-
import { resolveParentElement } from '../decorators/BellatrixWebComponent';
55
import { ShadowRootContext, WebComponent } from '.';
66

77
import type { Ctor } from '@bellatrix/core/types';
@@ -11,11 +11,11 @@ export class ComponentsList<T extends WebComponent> {
1111
private _foundAll: boolean = false;
1212
private _type: Ctor<T, ConstructorParameters<typeof WebComponent>>;
1313
private _findStrategy: FindStrategy;
14-
private _driver: BrowserAutomationTool;
14+
private _driver: BrowserController;
1515
private _parentComponent?: WebComponent | ShadowRootContext;
1616
private _componentName?: string;
1717

18-
constructor(type: Ctor<T, ConstructorParameters<typeof WebComponent>>, findStrategy: FindStrategy, driver: BrowserAutomationTool, parentComponent?: WebComponent | ShadowRootContext, componentName?: string) {
18+
constructor(type: Ctor<T, ConstructorParameters<typeof WebComponent>>, findStrategy: FindStrategy, driver: BrowserController, parentComponent?: WebComponent | ShadowRootContext, componentName?: string) {
1919
this._type = type;
2020
this._findStrategy = findStrategy;
2121
this._driver = driver;
@@ -31,7 +31,7 @@ export class ComponentsList<T extends WebComponent> {
3131
async get(index: number): Promise<T>;
3232
async get(index?: number): Promise<T | T[]> {
3333
if (index === undefined && !this._foundAll) {
34-
const searchContext = this._parentComponent ? await resolveParentElement(this._parentComponent) : ServiceLocator.resolve(BrowserAutomationTool);
34+
const searchContext = this._parentComponent ? await resolveParentElement(this._parentComponent) : ServiceLocator.resolve(BrowserController);
3535
const elements = await searchContext.findElements(this._findStrategy.convert());
3636
const components = elements.map((element, index) => {
3737
const findStrategy = this.cloneFindStrategyWithUpdatedIndex(this._findStrategy, index);

@bellatrix/web/src/components/core/ShadowRootContext.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { BrowserAutomationTool, WebElement } from '@bellatrix/web/infrastructure/browserautomationtools/core';
1+
import { BrowserController, WebElement } from '@bellatrix/web/infrastructure/browsercontroller/core';
22
import { ComponentService } from '@bellatrix/web/services';
33

44
import type { Ctor } from '@bellatrix/core/types';
55
import { WebComponent } from '.';
66

77
export class ShadowRootContext<DOMType extends ShadowRoot = ShadowRoot> {
88
private _cachedElement: WebElement;
9-
private _driver: BrowserAutomationTool;
9+
private _driver: BrowserController;
1010
private _parentComponent: WebComponent | ShadowRootContext;
1111

12-
constructor(driver: BrowserAutomationTool, parentComponent: WebComponent | ShadowRootContext, cachedElement: WebElement) {
12+
constructor(driver: BrowserController, parentComponent: WebComponent | ShadowRootContext, cachedElement: WebElement) {
1313
this._driver = driver;
1414
this._parentComponent = parentComponent;
1515
this._cachedElement = cachedElement;

@bellatrix/web/src/components/core/WebComponent.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BrowserAutomationTool, WebElement } from '@bellatrix/web/infrastructure/browserautomationtools/core';
1+
import { BrowserController, WebElement } from '@bellatrix/web/infrastructure/browsercontroller/core';
22
import { Validator, StringValidator, NumberValidator, UnknownValidator, BooleanValidator } from '@bellatrix/web/validators';
33
import { BellatrixWebComponent } from '@bellatrix/web/components/decorators';
44
import { FindStrategy } from '@bellatrix/web/findstrategies';
@@ -9,21 +9,21 @@ import type { Ctor, MethodNamesStartingWith } from '@bellatrix/core/types';
99
import type { HtmlAttribute } from '@bellatrix/web/types';
1010

1111
@BellatrixWebComponent
12-
export class WebComponent<HTMLType extends Element = Element> {
12+
export class WebComponent<HTMLType extends HTMLElement = HTMLElement> {
1313
private _cachedElement!: WebElement;
1414
private _wait: ComponentWaitService;
1515
private _findStrategy: FindStrategy;
16-
private _driver: BrowserAutomationTool;
16+
private _driver: BrowserController;
1717
private _parentComponent?: WebComponent | ShadowRootContext;
1818
private _componentName?: string;
1919

20-
constructor(findStrategy: FindStrategy, driver: BrowserAutomationTool, parentComponent?: WebComponent | ShadowRootContext, cachedElement?: WebElement, componentName?: string) {
20+
constructor(findStrategy: FindStrategy, driver: BrowserController, parentComponent?: WebComponent | ShadowRootContext, cachedElement?: WebElement, componentName?: string) {
2121
this._findStrategy = findStrategy;
2222
this._driver = driver;
2323
this._parentComponent = parentComponent;
2424
this._cachedElement = cachedElement!;
2525
this._componentName = componentName;
26-
this._wait = new ComponentWaitService(this);
26+
this._wait = new ComponentWaitService(driver, this);
2727
};
2828

2929
get wrappedElement(): WebElement {
@@ -50,6 +50,10 @@ export class WebComponent<HTMLType extends Element = Element> {
5050
await this.wrappedElement.hover();
5151
}
5252

53+
async focus(): Promise<void> {
54+
await this.wrappedElement.focus();
55+
}
56+
5357
async getAttribute(name: HtmlAttribute): Promise<string> {
5458
return await this.wrappedElement.getAttribute(name);
5559
}
@@ -66,8 +70,8 @@ export class WebComponent<HTMLType extends Element = Element> {
6670
return await this.wrappedElement.isClickable();
6771
}
6872

69-
async scrollToVisible(): Promise<void> { // TODO: maybe rename to scrollIntoView?
70-
return await this.wrappedElement.scrollToVisible();
73+
async scrollIntoView(): Promise<void> {
74+
return await this.wrappedElement.scrollIntoView();
7175
}
7276

7377
async getOuterHtml(): Promise<string> {

0 commit comments

Comments
 (0)