@@ -4,6 +4,10 @@ import config from "../../config.js";
4
4
interface SelectorMapping {
5
5
originalSelector : string ;
6
6
healedSelector : string ;
7
+ context : {
8
+ before : string ;
9
+ after : string ;
10
+ } ;
7
11
}
8
12
9
13
export async function getSelfHealSelectors ( sessionId : string ) {
@@ -24,20 +28,40 @@ export async function getSelfHealSelectors(sessionId: string) {
24
28
}
25
29
26
30
function extractHealedSelectors ( logText : string ) : SelectorMapping [ ] {
27
- // Pattern to match SELFHEAL entries with healed selectors
31
+ // Split log text into lines for easier context handling
32
+ const logLines = logText . split ( "\n" ) ;
33
+
34
+ // Pattern to match successful SELFHEAL entries only
28
35
const selfhealPattern =
29
- / S E L F H E A L \s * { \s * " s t a t u s " : " t r u e " , \s * " d a t a " : \s * { \s * " u s i n g " : " c s s s e l e c t o r " , \s * " v a l u e " : " ( .* ?) " } / g ;
36
+ / S E L F H E A L \s * { \s * " s t a t u s " : " t r u e " , \s * " d a t a " : \s * { \s * " u s i n g " : " c s s s e l e c t o r " , \s * " v a l u e " : " ( .* ?) " } / ;
30
37
31
38
// Pattern to match preceding selector requests
32
39
const requestPattern =
33
40
/ P O S T \/ s e s s i o n \/ [ ^ / ] + \/ e l e m e n t .* ?" u s i n g " : " c s s s e l e c t o r " , " v a l u e " : " ( .* ?) " / g;
34
41
35
- // Find all healed selectors
36
- const healedSelectors : string [ ] = [ ] ;
37
- let healedMatch ;
38
- while ( ( healedMatch = selfhealPattern . exec ( logText ) ) !== null ) {
39
- healedSelectors . push ( healedMatch [ 1 ] ) ;
40
- }
42
+ // Find all successful healed selectors with their line numbers and context
43
+ const healedSelectors : Array < {
44
+ selector : string ;
45
+ lineNumber : number ;
46
+ context : { before : string ; after : string } ;
47
+ } > = [ ] ;
48
+
49
+ logLines . forEach ( ( line , index ) => {
50
+ const match = line . match ( selfhealPattern ) ;
51
+ if ( match ) {
52
+ const beforeLine = index > 0 ? logLines [ index - 1 ] : "" ;
53
+ const afterLine = index < logLines . length - 1 ? logLines [ index + 1 ] : "" ;
54
+
55
+ healedSelectors . push ( {
56
+ selector : match [ 1 ] ,
57
+ lineNumber : index ,
58
+ context : {
59
+ before : beforeLine ,
60
+ after : afterLine ,
61
+ } ,
62
+ } ) ;
63
+ }
64
+ } ) ;
41
65
42
66
// Find all selector requests
43
67
const selectorRequests : string [ ] = [ ] ;
@@ -53,7 +77,8 @@ function extractHealedSelectors(logText: string): SelectorMapping[] {
53
77
for ( let i = 0 ; i < minLength ; i ++ ) {
54
78
healedMappings . push ( {
55
79
originalSelector : selectorRequests [ i ] ,
56
- healedSelector : healedSelectors [ i ] ,
80
+ healedSelector : healedSelectors [ i ] . selector ,
81
+ context : healedSelectors [ i ] . context ,
57
82
} ) ;
58
83
}
59
84
0 commit comments