@@ -4,6 +4,7 @@ import type {
44 ScreenshotRef ,
55 UIContext ,
66} from '@midscene/core' ;
7+ import { ScreenshotItem } from '@midscene/core' ;
78import type { AbstractInterface } from '@midscene/core/device' ;
89import {
910 type InputPrimitives ,
@@ -25,9 +26,12 @@ type SerializedStaticScreenshot = {
2526
2627type StaticPageUIContext = Omit <
2728 UIContext ,
28- 'deprecatedDpr' | 'screenshot'
29+ 'deprecatedDpr' | 'screenshot' | 'screenshotSequence'
2930> & {
3031 screenshot : UIContext [ 'screenshot' ] | SerializedStaticScreenshot ;
32+ screenshotSequence ?: Array <
33+ UIContext [ 'screenshot' ] | SerializedStaticScreenshot
34+ > ;
3135} ;
3236
3337function screenshotBase64FromContext (
@@ -50,10 +54,38 @@ function screenshotBase64FromContext(
5054 ) ;
5155}
5256
57+ function screenshotItemFromContext (
58+ screenshot : StaticPageUIContext [ 'screenshot' ] ,
59+ ) : ScreenshotItem {
60+ if ( screenshot instanceof ScreenshotItem ) {
61+ return screenshot ;
62+ }
63+
64+ const capturedAt =
65+ typeof screenshot . capturedAt === 'number'
66+ ? screenshot . capturedAt
67+ : Date . now ( ) ;
68+ return ScreenshotItem . create (
69+ screenshotBase64FromContext ( screenshot ) ,
70+ capturedAt ,
71+ ) ;
72+ }
73+
74+ function normalizeUIContext ( uiContext : StaticPageUIContext ) : UIContext {
75+ return {
76+ ...uiContext ,
77+ screenshot : screenshotItemFromContext ( uiContext . screenshot ) ,
78+ screenshotSequence : uiContext . screenshotSequence ?. map (
79+ screenshotItemFromContext ,
80+ ) ,
81+ } ;
82+ }
83+
5384export default class StaticPage implements AbstractInterface {
5485 interfaceType = 'static' ;
5586
5687 private uiContext : StaticPageUIContext ;
88+ private normalizedUIContext ?: UIContext ;
5789 readonly inputPrimitives : InputPrimitives = {
5890 pointer : {
5991 tap : async ( ) => ThrowNotImplemented ( 'Tap' ) ,
@@ -78,6 +110,11 @@ export default class StaticPage implements AbstractInterface {
78110 this . uiContext = uiContext ;
79111 }
80112
113+ getUIContext ( ) : UIContext {
114+ this . normalizedUIContext ??= normalizeUIContext ( this . uiContext ) ;
115+ return this . normalizedUIContext ;
116+ }
117+
81118 actionSpace ( ) : DeviceAction [ ] {
82119 // Return available actions for static page - they will throw "not implemented" errors when executed
83120 // but need to be available for planning phase
@@ -175,5 +212,6 @@ export default class StaticPage implements AbstractInterface {
175212
176213 updateContext ( newContext : StaticPageUIContext ) : void {
177214 this . uiContext = newContext ;
215+ this . normalizedUIContext = undefined ;
178216 }
179217}
0 commit comments