Skip to content

Commit 7e139b8

Browse files
authored
Merge pull request #7 from AutomateThePlanet/bdd-logging-update
WebComponent BDD Logging Update
2 parents f1af6a7 + a2d2932 commit 7e139b8

File tree

8 files changed

+50
-15
lines changed

8 files changed

+50
-15
lines changed

@bellatrix/runner/bellatrix.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ switch (config.frameworkSettings.testSettings.testFramework) {
175175
const tsPathsEsmLoaderPath = new URL(import.meta.resolve('ts-paths-esm-loader')).pathname;
176176
const cliPath = findFilePath([ 'node_modules/playwright/cli.js' ]);
177177

178-
const cliArgs = [ cliPath, 'test' /* ', --ui' TODO: make it an option */ ];
178+
const cliArgs = [ cliPath, 'test' ];
179179

180180
switch (reporter) {
181181
case 'json': {
@@ -198,6 +198,8 @@ switch (config.frameworkSettings.testSettings.testFramework) {
198198
case 'xunit': throw new Error('Playwright does not have xUnit reporter');
199199
}
200200

201+
// cliArgs.push('--ui'); // TODO: make it an option
202+
201203
spawnSync('node', cliArgs, {
202204
stdio: 'inherit',
203205
env: {

@bellatrix/web/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"./components": "./src/components/index.ts",
77
"./components/decorators": "./src/components/decorators/index.ts",
88
"./components/utilities": "./src/components/utilities/index.ts",
9+
"./components/hooks": "./src/components/hooks/index.ts",
910
"./findstrategies": "./src/findstrategies/index.ts",
1011
"./infrastructure": "./src/infrastructure/index.ts",
1112
"./pages": "./src/pages/index.ts",

@bellatrix/web/src/components/advanced/RangeInput.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { WebComponent } from '@bellatrix/web/components';
33

44
@BellatrixWebComponent
55
export class RangeInput extends WebComponent<HTMLInputElement> {
6-
async getRange(): Promise<number> {
6+
async getValue(): Promise<number> {
77
return this.evaluate(el => el.valueAsNumber);
88
}
99

10-
async setRange(range: number): Promise<void> {
11-
await this.evaluate(el => el.value = `${range}`);
10+
async setValue(value: number): Promise<void> {
11+
await this.evaluate(el => el.value = String(value));
1212
}
1313

1414
async isAutoComplete(): Promise<boolean> {
@@ -38,8 +38,4 @@ export class RangeInput extends WebComponent<HTMLInputElement> {
3838
async getStep(): Promise<number> {
3939
return parseFloat(await this.getAttribute('step'));
4040
}
41-
42-
async getValue(): Promise<string> {
43-
return await this.getAttribute('value');
44-
}
4541
}

@bellatrix/web/src/components/advanced/TimeInput.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export class TimeInput extends WebComponent<HTMLInputElement> {
77
return await this.getValue();
88
}
99

10-
async setTime(hours: number, minutes: number): Promise<void> {
11-
await this.evaluate(el => el.value = `${hours}:${minutes}:00`);
10+
async setTime(hours: number, minutes: number, seconds: number = 0): Promise<void> {
11+
await this.evaluate(el => el.value = `${hours}:${minutes}:${seconds}`);
1212
}
1313

1414
async getMax(): Promise<string> {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class WebComponent<HTMLType extends Element = Element> {
6666
return await this.wrappedElement.isClickable();
6767
}
6868

69-
async scrollToVisible(): Promise<void> {
69+
async scrollToVisible(): Promise<void> { // TODO: maybe rename to scrollIntoView?
7070
return await this.wrappedElement.scrollToVisible();
7171
}
7272

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { WebComponentHooks } from '@bellatrix/web/components/utilities';
2+
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';
3+
4+
export class DefaultWebComponentHooks {
5+
static addComponentBDDLogging(): void {
6+
const locale = Intl.DateTimeFormat().resolvedOptions().locale;// TODO: make it configurable
7+
const shouldObfuscatePassword = true; // TODO: add as option in configuration
8+
9+
WebComponentHooks.addListenerTo(Anchor).before('click', (anchor) => console.log(`clicking ${anchor.componentName}`));
10+
WebComponentHooks.addListenerTo(Button).before('click', (button) => console.log(`clicking ${button.componentName}`));
11+
WebComponentHooks.addListenerTo(ColorInput).before('setColor', (colorInput, color) => console.log(`setting '${color}' into ${colorInput.componentName}`));
12+
WebComponentHooks.addListenerTo(CheckBox).before('check', (checkBox) => console.log(`checking ${checkBox.componentName}`));
13+
WebComponentHooks.addListenerTo(CheckBox).before('uncheck', (checkBox) => console.log(`unchecking ${checkBox.componentName}`));
14+
WebComponentHooks.addListenerTo(DateInput).before('setDate', (dateInput, date) => console.log(`setting ${dateInput.componentName} to ${date.toLocaleDateString(locale)}`));
15+
WebComponentHooks.addListenerTo(DateTimeInput).before('setTime', (dateTimeInput, dateTime) => console.log(`setting ${dateTimeInput.componentName} to ${dateTime.toLocaleString()}`));
16+
WebComponentHooks.addListenerTo(EmailField).before('setEmail', (emailField, email) => console.log(`typing '${email}' into ${emailField.componentName}`));
17+
WebComponentHooks.addListenerTo(FileInput).before('upload', (fileInput, filePath) => console.log(`uploading '${filePath}' into ${fileInput.componentName}`));
18+
WebComponentHooks.addListenerTo(MonthInput).before('setMonth', (monthInput, year, month) => console.log(`setting ${monthInput} to ${new Date(year, month - 1).toLocaleDateString(locale, { month: 'long', year: 'numeric' })}`));
19+
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}`));
21+
WebComponentHooks.addListenerTo(PhoneField).before('setPhone', (phoneField, phone) => console.log(`typing '${phone}' into ${phoneField.componentName}`));
22+
WebComponentHooks.addListenerTo(RangeInput).before('setValue', (rangeInput, value) => console.log(`setting ${rangeInput.componentName} to ${value}`));
23+
WebComponentHooks.addListenerTo(SearchField).before('setSearch', (searchField, search) => console.log(`typing '${search}' into ${searchField.componentName}`));
24+
WebComponentHooks.addListenerTo(Select).before('selectByText', (select, text) => console.log(`selecting '${text}' from ${select.componentName}`));
25+
WebComponentHooks.addListenerTo(Select).before('selectByIndex', (select, index) => console.log(`selecting index ${index} from ${select.componentName}`));
26+
WebComponentHooks.addListenerTo(Select).before('selectByValue', (select, value) => console.log(`selecting value="${value}" from ${select.componentName}`));
27+
WebComponentHooks.addListenerTo(TextArea).before('setText', (textArea, text) => console.log(`typing '${text}' into ${textArea.componentName}`));
28+
WebComponentHooks.addListenerTo(TextField).before('setText', (textField, text) => console.log(`typing '${text}' into ${textField.componentName}`));
29+
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(':')}`));
30+
WebComponentHooks.addListenerTo(UrlField).before('setUrl', (urlField, url) => console.log(`typing '${url}' into ${urlField.componentName}`));
31+
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?
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './DefaultWebComponentHooks';

example/tests/ProductPurchaseTests.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { Test, TestClass } from '@bellatrix/web/test';
22
import { WebTest } from '@bellatrix/web/infrastructure';
3-
import { Anchor, Button } from '@bellatrix/web/components';
3+
import { Button } from '@bellatrix/web/components';
4+
import { DefaultWebComponentHooks } from '@bellatrix/web/components/hooks';
45
import { MainPage, CartPage, CheckoutPage, PurchaseInfo } from '../src/pages';
5-
import { WebComponentHooks } from '@bellatrix/web/components/utilities';
66

77
@TestClass
8-
class ProductPurchaseTests extends WebTest {
8+
export class ProductPurchaseTests extends WebTest {
99
override async configure(): Promise<void> {
1010
await super.configure();
11-
WebComponentHooks.addListenerTo(Button).before('click', button => console.log(`clicking ${button.componentName}`));
11+
DefaultWebComponentHooks.addComponentBDDLogging();
1212
}
1313

1414
override async afterEach() {

0 commit comments

Comments
 (0)