@specter-automation/test 1.0.160 → 1.0.162
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/specter-client.d.ts +9 -1
- package/dist/core/specter-client.js +8 -0
- package/dist/core/specter-matcher-report.d.ts +1 -1
- package/dist/core/specter-matcher-report.js +1 -1
- package/dist/matchers/widget-matchers.d.ts +27 -0
- package/dist/matchers/widget-matchers.js +107 -3
- package/package.json +1 -1
|
@@ -38,7 +38,15 @@ export declare enum SpecterEventType {
|
|
|
38
38
|
GameplayTag = "GameplayTag",
|
|
39
39
|
DiagnosticWarning = "DiagnosticWarning",
|
|
40
40
|
/** An AI's logic moved, a blackboard key changed, or its tree started or finished (the AI trail) */
|
|
41
|
-
AIState = "AIState"
|
|
41
|
+
AIState = "AIState",
|
|
42
|
+
/** A moment the game marked itself with the Mark Timeline Event node ("Action!", "Take 2") */
|
|
43
|
+
GameMarker = "GameMarker",
|
|
44
|
+
/** An actor spawned or destroyed while the test ran (`newValue`: "spawned" or "destroyed") */
|
|
45
|
+
ActorLifecycle = "ActorLifecycle",
|
|
46
|
+
/** A screen shown or hidden, or a button clicked (`newValue`: "shown", "hidden" or "clicked") */
|
|
47
|
+
UIEvent = "UIEvent",
|
|
48
|
+
/** A warning or error in the engine log (`newValue`: "Warning" or "Error") */
|
|
49
|
+
EngineLog = "EngineLog"
|
|
42
50
|
}
|
|
43
51
|
export interface SpecterTimelineEvent {
|
|
44
52
|
timestamp: number;
|
|
@@ -22,6 +22,14 @@ var SpecterEventType;
|
|
|
22
22
|
SpecterEventType["DiagnosticWarning"] = "DiagnosticWarning";
|
|
23
23
|
/** An AI's logic moved, a blackboard key changed, or its tree started or finished (the AI trail) */
|
|
24
24
|
SpecterEventType["AIState"] = "AIState";
|
|
25
|
+
/** A moment the game marked itself with the Mark Timeline Event node ("Action!", "Take 2") */
|
|
26
|
+
SpecterEventType["GameMarker"] = "GameMarker";
|
|
27
|
+
/** An actor spawned or destroyed while the test ran (`newValue`: "spawned" or "destroyed") */
|
|
28
|
+
SpecterEventType["ActorLifecycle"] = "ActorLifecycle";
|
|
29
|
+
/** A screen shown or hidden, or a button clicked (`newValue`: "shown", "hidden" or "clicked") */
|
|
30
|
+
SpecterEventType["UIEvent"] = "UIEvent";
|
|
31
|
+
/** A warning or error in the engine log (`newValue`: "Warning" or "Error") */
|
|
32
|
+
SpecterEventType["EngineLog"] = "EngineLog";
|
|
25
33
|
})(SpecterEventType || (exports.SpecterEventType = SpecterEventType = {}));
|
|
26
34
|
var specter_math_1 = require("./specter-math");
|
|
27
35
|
Object.defineProperty(exports, "VectorUtils", { enumerable: true, get: function () { return specter_math_1.VectorUtils; } });
|
|
@@ -31,7 +31,7 @@ export type SpecterMatcherName = keyof GasMatchers | keyof ActorMatchers | keyof
|
|
|
31
31
|
* Every Specter matcher. The compile-time check below fails the build if a
|
|
32
32
|
* matcher is added to one of the matcher interfaces but not to this list.
|
|
33
33
|
*/
|
|
34
|
-
export declare const SPECTER_MATCHER_NAMES: readonly ["toHaveAttributeValue", "toHaveAttributeChange", "toHaveGameplayTag", "toHaveGameplayEffect", "toHaveAppliedGameplayEffect", "toHaveGameplayAbility", "toHaveAbilityCooldown", "toHaveGameplayEffectStackCount", "toHaveGameplayEffectLevel", "toHaveAttributeBaseValue", "toBeExecutingAbility", "toHaveActivatedAbility", "toHaveGameplayTagCount", "toHaveAnyGameplayTags", "toHaveAllGameplayTags", "toHaveMovedFurtherThan", "toHaveLocation", "toHaveRotation", "toBeFacing", "toHaveInputMappingContext", "toHaveInputActionValue", "toHavePlayerScore", "toBeNiagaraActive", "toHaveNiagaraAsset", "toBeAudioPlaying", "toHaveSoundAsset", "toBePhysicsSimulating", "toBePhysicsAsleep", "toHaveVelocity", "toHaveCameraFOV", "toBeCameraShaking", "toHaveCameraViewTarget", "toBeAINavigating", "toHaveTeamId", "toBeHostileTowards", "toBePossessed", "toBePlayerControlled", "toBeLocallyControlled", "toHaveController", "toBeFalling", "toBeSwimming", "toBeFlying", "toBeCrouching", "toBeMovingOnGround", "toHaveMovementMode", "toBeVisible", "toBeHidden", "toHavePropertyValue", "toBeInViewport", "toBeDestroyed", "toHaveCount", "toHaveText", "toHaveValue", "toContainText", "toBeEnabled", "toBeDisabled", "toHaveMaterialScalarParameter", "toHaveMaterialVectorParameter", "toHaveMaterial", "toBeDynamicMaterial", "toHaveMaterialTextureParameter", "toHaveBlackboardValue", "toHaveAIState", "toBeMovingTowards", "toBeMovingAwayFrom", "toBeWithinDistance", "toBeFollowing", "toHaveLineOfSightTo", "toBeRunningBehaviorTree", "toBeInState", "toHaveBlackboardChange", "toHaveVisitedState", "toHaveFPS", "toHaveMinFPS", "toHaveFrameTimeBelow", "toHaveMemoryBelow", "toMaintainPerformanceBudget", "toHaveFrameTimeP95Below", "toHaveFrameTimeP99Below", "toHaveAverageFrameTimeBelow", "toHaveAverageFPSAbove", "toHaveOnePercentLowFPSAbove", "toHaveNoHitchesOver", "toHavePeakMemoryBelow", "toHaveMemoryGrowthBelow", "toHaveDrawCallsBelow"];
|
|
34
|
+
export declare const SPECTER_MATCHER_NAMES: readonly ["toHaveAttributeValue", "toHaveAttributeChange", "toHaveGameplayTag", "toHaveGameplayEffect", "toHaveAppliedGameplayEffect", "toHaveGameplayAbility", "toHaveAbilityCooldown", "toHaveGameplayEffectStackCount", "toHaveGameplayEffectLevel", "toHaveAttributeBaseValue", "toBeExecutingAbility", "toHaveActivatedAbility", "toHaveGameplayTagCount", "toHaveAnyGameplayTags", "toHaveAllGameplayTags", "toHaveMovedFurtherThan", "toHaveLocation", "toHaveRotation", "toBeFacing", "toHaveInputMappingContext", "toHaveInputActionValue", "toHavePlayerScore", "toBeNiagaraActive", "toHaveNiagaraAsset", "toBeAudioPlaying", "toHaveSoundAsset", "toBePhysicsSimulating", "toBePhysicsAsleep", "toHaveVelocity", "toHaveCameraFOV", "toBeCameraShaking", "toHaveCameraViewTarget", "toBeAINavigating", "toHaveTeamId", "toBeHostileTowards", "toBePossessed", "toBePlayerControlled", "toBeLocallyControlled", "toHaveController", "toBeFalling", "toBeSwimming", "toBeFlying", "toBeCrouching", "toBeMovingOnGround", "toHaveMovementMode", "toBeVisible", "toBeHidden", "toHavePropertyValue", "toBeInViewport", "toBeDestroyed", "toHaveCount", "toHaveText", "toHaveValue", "toContainText", "toBeEnabled", "toBeDisabled", "toOverlap", "toHaveMaterialScalarParameter", "toHaveMaterialVectorParameter", "toHaveMaterial", "toBeDynamicMaterial", "toHaveMaterialTextureParameter", "toHaveBlackboardValue", "toHaveAIState", "toBeMovingTowards", "toBeMovingAwayFrom", "toBeWithinDistance", "toBeFollowing", "toHaveLineOfSightTo", "toBeRunningBehaviorTree", "toBeInState", "toHaveBlackboardChange", "toHaveVisitedState", "toHaveFPS", "toHaveMinFPS", "toHaveFrameTimeBelow", "toHaveMemoryBelow", "toMaintainPerformanceBudget", "toHaveFrameTimeP95Below", "toHaveFrameTimeP99Below", "toHaveAverageFrameTimeBelow", "toHaveAverageFPSAbove", "toHaveOnePercentLowFPSAbove", "toHaveNoHitchesOver", "toHavePeakMemoryBelow", "toHaveMemoryGrowthBelow", "toHaveDrawCallsBelow"];
|
|
35
35
|
export declare function isSpecterMatcher(name: string): boolean;
|
|
36
36
|
/**
|
|
37
37
|
* Parses Playwright's expect step title, e.g. `Expect "soft not toHaveGameplayTag"`.
|
|
@@ -26,7 +26,7 @@ exports.SPECTER_MATCHER_NAMES = [
|
|
|
26
26
|
// locator-matchers
|
|
27
27
|
'toBeVisible', 'toBeHidden', 'toHavePropertyValue', 'toBeInViewport', 'toBeDestroyed', 'toHaveCount',
|
|
28
28
|
// widget-matchers
|
|
29
|
-
'toHaveText', 'toHaveValue', 'toContainText', 'toBeEnabled', 'toBeDisabled',
|
|
29
|
+
'toHaveText', 'toHaveValue', 'toContainText', 'toBeEnabled', 'toBeDisabled', 'toOverlap',
|
|
30
30
|
// material-matchers
|
|
31
31
|
'toHaveMaterialScalarParameter', 'toHaveMaterialVectorParameter', 'toHaveMaterial',
|
|
32
32
|
'toBeDynamicMaterial', 'toHaveMaterialTextureParameter',
|
|
@@ -37,6 +37,20 @@ declare global {
|
|
|
37
37
|
toBeDisabled(options?: {
|
|
38
38
|
timeout?: number;
|
|
39
39
|
}): T extends WidgetLocator ? Promise<R> : never;
|
|
40
|
+
/**
|
|
41
|
+
* Asserts that the widget overlaps another on screen. Mostly used negated, to catch one panel drawn
|
|
42
|
+
* over another:
|
|
43
|
+
* - `await expect(selectionBar).not.toOverlap(toolbar)`: these two don't overlap;
|
|
44
|
+
* - `await expect(selectionBar).not.toOverlap()`: it overlaps nothing. "Anything" is every visible widget
|
|
45
|
+
* that draws (text, images, buttons, borders), except the widget's own contents and the panels it sits in.
|
|
46
|
+
*
|
|
47
|
+
* Compares rectangles in screen pixels. A widget that isn't visible overlaps nothing; touching edges don't count.
|
|
48
|
+
* - `threshold`: how much of the smaller widget must be covered to count, in percent (default 0: any overlap).
|
|
49
|
+
* - `ignore` (no other widget): names, classes or owning widgets meant to be underneath, as text or patterns.
|
|
50
|
+
* Auto-retries for up to `timeout` ms (default: 5000). With no other widget, needs a plugin with GetOverlappingWidgets.
|
|
51
|
+
*/
|
|
52
|
+
toOverlap(other?: WidgetLocator, options?: OverlapOptions): T extends WidgetLocator ? Promise<R> : never;
|
|
53
|
+
toOverlap(options?: OverlapOptions): T extends WidgetLocator ? Promise<R> : never;
|
|
40
54
|
}
|
|
41
55
|
}
|
|
42
56
|
}
|
|
@@ -56,6 +70,15 @@ export interface WidgetMatchers {
|
|
|
56
70
|
toBeDisabled(options?: {
|
|
57
71
|
timeout?: number;
|
|
58
72
|
}): Promise<void>;
|
|
73
|
+
toOverlap(other?: WidgetLocator, options?: OverlapOptions): Promise<void>;
|
|
74
|
+
toOverlap(options?: OverlapOptions): Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
export interface OverlapOptions {
|
|
77
|
+
/** How much of the smaller widget must be covered to count as overlapping, in percent. Default 0: any overlap. */
|
|
78
|
+
threshold?: number;
|
|
79
|
+
/** With no other widget: names, classes or owning widgets to leave out (backgrounds meant to be underneath) */
|
|
80
|
+
ignore?: Array<string | RegExp>;
|
|
81
|
+
timeout?: number;
|
|
59
82
|
}
|
|
60
83
|
export declare const widgetExpect: import("playwright/test").Expect<{
|
|
61
84
|
toHaveText(this: import("playwright/test").ExpectMatcherState, locator: WidgetLocator, expectedText: string, options?: {
|
|
@@ -88,6 +111,10 @@ export declare const widgetExpect: import("playwright/test").Expect<{
|
|
|
88
111
|
pass: boolean;
|
|
89
112
|
message: () => string;
|
|
90
113
|
}>;
|
|
114
|
+
toOverlap(this: import("playwright/test").ExpectMatcherState, locator: WidgetLocator, otherOrOptions?: WidgetLocator | OverlapOptions, maybeOptions?: OverlapOptions): Promise<{
|
|
115
|
+
pass: boolean;
|
|
116
|
+
message: () => string;
|
|
117
|
+
}>;
|
|
91
118
|
toBeDisabled(this: import("playwright/test").ExpectMatcherState, locator: WidgetLocator, options?: {
|
|
92
119
|
timeout?: number;
|
|
93
120
|
}): Promise<{
|
|
@@ -3,9 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.widgetExpect = void 0;
|
|
4
4
|
const test_1 = require("@playwright/test");
|
|
5
5
|
const instrument_1 = require("./instrument");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const widget_locator_1 = require("../core/locators/widget-locator");
|
|
7
|
+
/** A widget's rectangle in screen pixels. `pixelSize` comes from newer plugins; older ones give the centre, which is enough. */
|
|
8
|
+
async function screenRect(locator) {
|
|
9
|
+
const geometry = await locator.getGeometry();
|
|
10
|
+
const width = geometry.pixelSize?.width ?? 2 * (geometry.center.x - geometry.position.x);
|
|
11
|
+
const height = geometry.pixelSize?.height ?? 2 * (geometry.center.y - geometry.position.y);
|
|
12
|
+
return {
|
|
13
|
+
left: geometry.position.x,
|
|
14
|
+
top: geometry.position.y,
|
|
15
|
+
right: geometry.position.x + width,
|
|
16
|
+
bottom: geometry.position.y + height,
|
|
17
|
+
visible: geometry.isVisible !== false && geometry.isRendered !== false,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function describeRect(rect) {
|
|
21
|
+
return `(${Math.round(rect.left)}, ${Math.round(rect.top)}) to (${Math.round(rect.right)}, ${Math.round(rect.bottom)})`;
|
|
22
|
+
}
|
|
9
23
|
async function poll(fn, check, timeout) {
|
|
10
24
|
const startTime = Date.now();
|
|
11
25
|
let last = undefined;
|
|
@@ -71,6 +85,96 @@ exports.widgetExpect = test_1.expect.extend((0, instrument_1.instrumentMatchers)
|
|
|
71
85
|
};
|
|
72
86
|
})();
|
|
73
87
|
},
|
|
88
|
+
async toOverlap(locator, otherOrOptions, maybeOptions) {
|
|
89
|
+
const isNot = this.isNot;
|
|
90
|
+
const other = otherOrOptions instanceof widget_locator_1.WidgetLocator ? otherOrOptions : undefined;
|
|
91
|
+
const options = (otherOrOptions instanceof widget_locator_1.WidgetLocator ? maybeOptions : otherOrOptions) ?? {};
|
|
92
|
+
const timeout = options.timeout ?? 5000;
|
|
93
|
+
const threshold = Math.max(0, options.threshold ?? 0);
|
|
94
|
+
const ignore = options.ignore ?? [];
|
|
95
|
+
// How much of the smaller widget is covered, in percent: a small badge fully under a big panel is 100
|
|
96
|
+
const percentCovered = (a, b, overlapX, overlapY) => {
|
|
97
|
+
const smaller = Math.min((a.right - a.left) * (a.bottom - a.top), (b.right - b.left) * (b.bottom - b.top));
|
|
98
|
+
return smaller > 0 ? (100 * overlapX * overlapY) / smaller : 0;
|
|
99
|
+
};
|
|
100
|
+
const counts = (overlapX, overlapY, percent) => overlapX > 0 && overlapY > 0 && percent > threshold;
|
|
101
|
+
const thresholdText = threshold > 0 ? ` (counting overlaps over ${threshold}% of the smaller widget)` : '';
|
|
102
|
+
if (other) {
|
|
103
|
+
const read = async () => {
|
|
104
|
+
const [a, b] = await Promise.all([screenRect(locator), screenRect(other)]);
|
|
105
|
+
const overlapX = Math.min(a.right, b.right) - Math.max(a.left, b.left);
|
|
106
|
+
const overlapY = Math.min(a.bottom, b.bottom) - Math.max(a.top, b.top);
|
|
107
|
+
const percent = percentCovered(a, b, overlapX, overlapY);
|
|
108
|
+
const overlaps = a.visible && b.visible && counts(overlapX, overlapY, percent);
|
|
109
|
+
return { a, b, overlapX, overlapY, percent, overlaps };
|
|
110
|
+
};
|
|
111
|
+
const { passed, last } = await poll(read, reading => isNot ? !reading.overlaps : reading.overlaps, timeout);
|
|
112
|
+
const names = `${locator.toString()} and ${other.toString()}`;
|
|
113
|
+
return {
|
|
114
|
+
pass: isNot ? !passed : passed,
|
|
115
|
+
message: () => {
|
|
116
|
+
if (!last) {
|
|
117
|
+
return `Couldn't read the geometry of ${names} (do both exist?).`;
|
|
118
|
+
}
|
|
119
|
+
const where = `\n ${locator.toString()}: ${describeRect(last.a)}${last.a.visible ? '' : ' (not visible)'}` +
|
|
120
|
+
`\n ${other.toString()}: ${describeRect(last.b)}${last.b.visible ? '' : ' (not visible)'}`;
|
|
121
|
+
return last.overlaps
|
|
122
|
+
? `Expected ${names} not to overlap${thresholdText}, but they overlap by ${Math.round(last.overlapX)} x ${Math.round(last.overlapY)} px ` +
|
|
123
|
+
`(${Math.round(last.percent)}% of the smaller one).${where}`
|
|
124
|
+
: `Expected ${names} to overlap${thresholdText}, but they don't.${where}`;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
// No other widget: anything visible on screen that isn't the widget's own contents or the panels it sits in
|
|
129
|
+
const isIgnored = (entry) => ignore.some(pattern => [entry.name, entry.className, entry.in].some(text => !!text && (typeof pattern === 'string' ? text.includes(pattern) : pattern.test(text))));
|
|
130
|
+
const read = async () => {
|
|
131
|
+
const response = await locator.evaluate("GetOverlappingWidgets", {}, undefined, true);
|
|
132
|
+
if (response?.status && response.status !== 'success') {
|
|
133
|
+
throw new Error(response.error ?? 'GetOverlappingWidgets failed');
|
|
134
|
+
}
|
|
135
|
+
const data = response?.data ?? {};
|
|
136
|
+
if (!data.isVisible || !data.rect) {
|
|
137
|
+
return { visible: false, hits: [] };
|
|
138
|
+
}
|
|
139
|
+
const rect = { ...data.rect, visible: true };
|
|
140
|
+
const hits = (data.overlaps ?? [])
|
|
141
|
+
.filter(entry => !isIgnored(entry))
|
|
142
|
+
.map(entry => ({ ...entry, percent: percentCovered(rect, { ...entry.rect, visible: true }, entry.overlapWidth, entry.overlapHeight) }))
|
|
143
|
+
.filter(entry => counts(entry.overlapWidth, entry.overlapHeight, entry.percent))
|
|
144
|
+
.sort((x, y) => y.percent - x.percent);
|
|
145
|
+
return { visible: true, rect, hits };
|
|
146
|
+
};
|
|
147
|
+
let readError;
|
|
148
|
+
const { passed, last } = await poll(async () => {
|
|
149
|
+
try {
|
|
150
|
+
return await read();
|
|
151
|
+
}
|
|
152
|
+
catch (e) {
|
|
153
|
+
readError = e;
|
|
154
|
+
throw e;
|
|
155
|
+
}
|
|
156
|
+
}, reading => isNot ? reading.hits.length === 0 : reading.hits.length > 0, timeout);
|
|
157
|
+
return {
|
|
158
|
+
pass: isNot ? !passed : passed,
|
|
159
|
+
message: () => {
|
|
160
|
+
if (!last) {
|
|
161
|
+
const why = readError?.message?.includes('Unknown command')
|
|
162
|
+
? 'this needs a newer Specter plugin (GetOverlappingWidgets)'
|
|
163
|
+
: (readError?.message ?? 'does it exist?');
|
|
164
|
+
return `Couldn't check what ${locator.toString()} overlaps: ${why}.`;
|
|
165
|
+
}
|
|
166
|
+
if (!isNot) {
|
|
167
|
+
return `Expected ${locator.toString()} to overlap another widget${thresholdText}, but it ${last.visible ? "doesn't" : "isn't visible"}.`;
|
|
168
|
+
}
|
|
169
|
+
const lines = last.hits.slice(0, 8).map(hit => ` - ${hit.name} (${hit.className}${hit.in ? ` in ${hit.in}` : ''}): ${Math.round(hit.overlapWidth)} x ${Math.round(hit.overlapHeight)} px, ` +
|
|
170
|
+
`${Math.round(hit.percent)}% of the smaller widget, at ${describeRect({ ...hit.rect, visible: true })}`);
|
|
171
|
+
const more = last.hits.length > 8 ? `\n ...and ${last.hits.length - 8} more` : '';
|
|
172
|
+
return `Expected ${locator.toString()} not to overlap anything${thresholdText}, but it overlaps ${last.hits.length} widget(s).\n` +
|
|
173
|
+
` ${locator.toString()}: ${describeRect(last.rect)}\n${lines.join('\n')}${more}\n` +
|
|
174
|
+
` (Leave out widgets that are meant to be underneath with { ignore: ["WBP_Background", /Vignette/] }.)`;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
},
|
|
74
178
|
async toBeDisabled(locator, options) {
|
|
75
179
|
const isNot = this.isNot;
|
|
76
180
|
const timeout = options?.timeout ?? 5000;
|