1
- import { Page , Locator , expect } from ' @playwright/test' ;
1
+ import { Page , Locator , expect } from " @playwright/test" ;
2
2
3
3
export class ToolBaseGenUIPage {
4
4
readonly page : Page ;
@@ -9,15 +9,17 @@ export class ToolBaseGenUIPage {
9
9
readonly appliedButton : Locator ;
10
10
readonly haikuBlock : Locator ;
11
11
readonly japaneseLines : Locator ;
12
+ readonly mainHaikuDisplay : Locator ;
12
13
13
14
constructor ( page : Page ) {
14
15
this . page = page ;
15
16
this . haikuAgentIntro = page . getByText ( "I'm a haiku generator 👋. How can I help you?" ) ;
16
- this . messageBox = page . getByRole ( ' textbox' , { name : ' Type a message...' } ) ;
17
+ this . messageBox = page . getByRole ( " textbox" , { name : " Type a message..." } ) ;
17
18
this . sendButton = page . locator ( '[data-test-id="copilot-chat-ready"]' ) ;
18
- this . haikuBlock = page . locator ( '[data-testid="haiku-card"]' ) ;
19
- this . applyButton = page . getByRole ( 'button' , { name : 'Apply' } ) ;
20
- this . japaneseLines = page . locator ( '[data-testid="haiku-line"]' ) ;
19
+ this . haikuBlock = page . locator ( ".bg-palette-surface-container.rounded-2xl" ) ;
20
+ this . applyButton = page . getByRole ( "button" , { name : "Apply" } ) ;
21
+ this . japaneseLines = page . locator ( ".font-bold.text-palette-text-primary" ) ;
22
+ this . mainHaikuDisplay = page . locator ( ".bg-palette-surface-main" ) ;
21
23
}
22
24
23
25
async generateHaiku ( message : string ) {
@@ -27,27 +29,33 @@ export class ToolBaseGenUIPage {
27
29
}
28
30
29
31
async checkGeneratedHaiku ( ) {
30
- await this . page . locator ( '[data-testid="haiku-card"]' ) . last ( ) . isVisible ( ) ;
31
- const mostRecentCard = this . page . locator ( '[data-testid="haiku-card"]' ) . last ( ) ;
32
- await mostRecentCard . locator ( '[data-testid="haiku-line"]' ) . first ( ) . waitFor ( { state : 'visible' , timeout : 10000 } ) ;
32
+ await this . page . locator ( ".bg-palette-surface-container.rounded-2xl" ) . last ( ) . isVisible ( ) ;
33
+ const mostRecentCard = this . page . locator ( ".bg-palette-surface-container.rounded-2xl" ) . last ( ) ;
34
+ await mostRecentCard
35
+ . locator ( ".font-bold.text-palette-text-primary" )
36
+ . first ( )
37
+ . waitFor ( { state : "visible" , timeout : 10000 } ) ;
33
38
}
34
39
35
40
async extractChatHaikuContent ( page : Page ) : Promise < string > {
36
41
await page . waitForTimeout ( 3000 ) ;
37
- await page . locator ( '[data-testid="haiku-card"]' ) . first ( ) . waitFor ( { state : 'visible' } ) ;
38
- const allHaikuCards = page . locator ( '[data-testid="haiku-card"]' ) ;
42
+ await page
43
+ . locator ( ".bg-palette-surface-container.rounded-2xl" )
44
+ . first ( )
45
+ . waitFor ( { state : "visible" } ) ;
46
+ const allHaikuCards = page . locator ( ".bg-palette-surface-container.rounded-2xl" ) ;
39
47
const cardCount = await allHaikuCards . count ( ) ;
40
48
let chatHaikuContainer ;
41
49
let chatHaikuLines ;
42
50
43
51
for ( let cardIndex = cardCount - 1 ; cardIndex >= 0 ; cardIndex -- ) {
44
52
chatHaikuContainer = allHaikuCards . nth ( cardIndex ) ;
45
- chatHaikuLines = chatHaikuContainer . locator ( '[data-testid="haiku-line"]' ) ;
53
+ chatHaikuLines = chatHaikuContainer . locator ( ".font-bold.text-palette-text-primary" ) ;
46
54
const linesCount = await chatHaikuLines . count ( ) ;
47
55
48
56
if ( linesCount > 0 ) {
49
57
try {
50
- await chatHaikuLines . first ( ) . waitFor ( { state : ' visible' , timeout : 5000 } ) ;
58
+ await chatHaikuLines . first ( ) . waitFor ( { state : " visible" , timeout : 5000 } ) ;
51
59
break ;
52
60
} catch ( error ) {
53
61
continue ;
@@ -56,36 +64,38 @@ export class ToolBaseGenUIPage {
56
64
}
57
65
58
66
if ( ! chatHaikuLines ) {
59
- throw new Error ( ' No haiku cards with visible lines found' ) ;
67
+ throw new Error ( " No haiku cards with visible lines found" ) ;
60
68
}
61
69
62
70
const count = await chatHaikuLines . count ( ) ;
63
71
const lines : string [ ] = [ ] ;
64
72
65
73
for ( let i = 0 ; i < count ; i ++ ) {
66
74
const haikuLine = chatHaikuLines . nth ( i ) ;
67
- const japaneseText = await haikuLine . locator ( 'p' ) . first ( ) . innerText ( ) ;
75
+ const japaneseText = await haikuLine . innerText ( ) ;
68
76
lines . push ( japaneseText ) ;
69
77
}
70
78
71
- const chatHaikuContent = lines . join ( '' ) . replace ( / \s / g, '' ) ;
79
+ const chatHaikuContent = lines . join ( "" ) . replace ( / \s / g, "" ) ;
72
80
return chatHaikuContent ;
73
81
}
74
82
75
83
async extractMainDisplayHaikuContent ( page : Page ) : Promise < string > {
76
- const mainDisplayLines = page . locator ( '[data-testid="main-haiku-line"]' ) ;
84
+ const carouselItems = page . locator ( '[class*="embla__slide"]' ) ;
85
+ const activeSlide = carouselItems . first ( ) ;
86
+ const mainDisplayLines = activeSlide . locator ( ".font-bold.text-palette-text-primary" ) ;
77
87
const mainCount = await mainDisplayLines . count ( ) ;
78
88
const lines : string [ ] = [ ] ;
79
89
80
90
if ( mainCount > 0 ) {
81
91
for ( let i = 0 ; i < mainCount ; i ++ ) {
82
92
const haikuLine = mainDisplayLines . nth ( i ) ;
83
- const japaneseText = await haikuLine . locator ( 'p' ) . first ( ) . innerText ( ) ;
93
+ const japaneseText = await haikuLine . innerText ( ) ;
84
94
lines . push ( japaneseText ) ;
85
95
}
86
96
}
87
97
88
- const mainHaikuContent = lines . join ( '' ) . replace ( / \s / g, '' ) ;
98
+ const mainHaikuContent = lines . join ( "" ) . replace ( / \s / g, "" ) ;
89
99
return mainHaikuContent ;
90
100
}
91
101
@@ -96,7 +106,7 @@ export class ToolBaseGenUIPage {
96
106
97
107
const mainHaikuContent = await this . extractMainDisplayHaikuContent ( page ) ;
98
108
99
- if ( mainHaikuContent === '' ) {
109
+ if ( mainHaikuContent === "" ) {
100
110
expect ( chatHaikuContent . length ) . toBeGreaterThan ( 0 ) ;
101
111
return ;
102
112
}
@@ -111,4 +121,4 @@ export class ToolBaseGenUIPage {
111
121
expect ( updatedMainContent ) . toBe ( chatHaikuContent ) ;
112
122
}
113
123
}
114
- }
124
+ }
0 commit comments