@@ -13,6 +13,11 @@ import { BasePage } from "./base-page";
1313import { Edit } from "../utils/types/json-edit.types" ;
1414import { SpecEditorPage } from "./spec-editor-page" ;
1515
16+ export type ExampleEntry = {
17+ name : string ;
18+ rawPath : string ;
19+ responseCode : number ;
20+ } ;
1621
1722export class ExampleGenerationPage extends BasePage {
1823 readonly openApiTabPage : OpenAPISpecTabPage ;
@@ -34,7 +39,6 @@ export class ExampleGenerationPage extends BasePage {
3439 private readonly specTabLocator : Locator ;
3540 private readonly specEditorHelper : SpecEditorPage ;
3641
37-
3842 constructor ( page : Page , testInfo : TestInfo , eyes : any , specName : string ) {
3943 super ( page , testInfo , eyes , specName ) ;
4044 this . specTree = page . locator ( "#spec-tree" ) ;
@@ -69,7 +73,6 @@ export class ExampleGenerationPage extends BasePage {
6973 this . specEditorHelper = new SpecEditorPage ( page ) ;
7074 }
7175
72-
7376 private async openExampleGenerationTab ( ) {
7477 console . log ( "Opening Example Generation tab" ) ;
7578 return this . openApiTabPage . openExampleGenerationTab ( ) ;
@@ -158,16 +161,14 @@ export class ExampleGenerationPage extends BasePage {
158161 withVisualValidation = true ,
159162 ) {
160163 const iframe = await this . waitForExamplesIFrame ( ) ;
161- const rowXpath = `//tr[@data-raw-path="/${ endpoint } " and .//td[@class='response-cell']/p[text()="${ responseCode } "]]` ;
162- const endpointPrefix = endpoint . replace ( / \/ ( \( [ ^ / ] + \) ) / g, "" ) ;
163- const fileNameSpanXpath = `${ rowXpath } //td/span[contains(text(), '${ endpointPrefix } ') and contains(text(), '${ responseCode } ')]` ;
164+ const rowXpath = `//tr[contains(@data-raw-path, "/${ endpoint } ") and .//td[@class='response-cell']//p[contains(normalize-space(.), "${ responseCode } ")]]` ;
165+ const fileNameSpanXpath = `${ rowXpath } //td/span[contains(., '${ responseCode } ')]` ;
164166 console . log (
165167 `\t\tLooking for example file name span with XPath: ${ fileNameSpanXpath } ` ,
166168 ) ;
167169 const fileNameSpan = iframe . locator ( fileNameSpanXpath ) ;
168170 await expect ( fileNameSpan ) . toBeVisible ( { timeout : 4000 } ) ;
169171 const fileNameText = ( await fileNameSpan . textContent ( ) ) ?. trim ( ) ;
170- expect ( fileNameText ) . toContain ( endpointPrefix ) ;
171172 expect ( fileNameText ) . toContain ( String ( responseCode ) ) ;
172173 await takeAndAttachScreenshot (
173174 this . page ,
@@ -925,33 +926,42 @@ export class ExampleGenerationPage extends BasePage {
925926 } ) ;
926927 }
927928
928- async getGeneratedExampleNames ( ) : Promise < string [ ] > {
929+ async getGeneratedExampleNames ( ) : Promise < ExampleEntry [ ] > {
929930 return await test . step ( `Get generated example names` , async ( ) => {
930931 console . log ( `Getting generated example names from Examples tab` ) ;
931932 const iframe = await this . waitForExamplesIFrame ( ) ;
932933 const exampleRows = await iframe
933934 . locator ( "tr[data-example-relative-path]" )
934935 . all ( ) ;
935936
936- const exampleNames : string [ ] = [ ] ;
937+ const entries : ExampleEntry [ ] = [ ] ;
937938 for ( const row of exampleRows ) {
938939 const relativePath = await row . getAttribute (
939940 "data-example-relative-path" ,
940941 ) ;
942+ const rawPath = await row . getAttribute ( "data-raw-path" ) ;
943+ const responseCodeText = await row
944+ . locator ( "td.response-cell p" )
945+ . first ( )
946+ . textContent ( ) ;
947+
941948 if ( relativePath ) {
942949 const match = relativePath . match ( / _ e x a m p l e s \/ ( .+ ) \. j s o n $ / ) ;
943950 if ( match ) {
944- exampleNames . push ( match [ 1 ] ) ;
951+ entries . push ( {
952+ name : match [ 1 ] ,
953+ rawPath : rawPath ?? "" ,
954+ responseCode : responseCodeText
955+ ? parseInt ( responseCodeText . trim ( ) , 10 )
956+ : 0 ,
957+ } ) ;
945958 }
946959 }
947960 }
948961
949- console . log (
950- `Found ${ exampleNames . length } generated examples:` ,
951- exampleNames ,
952- ) ;
962+ console . log ( `Found ${ entries . length } generated examples:` , entries ) ;
953963 await takeAndAttachScreenshot ( this . page , `generated-example-names` ) ;
954- return exampleNames ;
964+ return entries ;
955965 } ) ;
956966 }
957967
@@ -1140,7 +1150,9 @@ export class ExampleGenerationPage extends BasePage {
11401150 await expect ( editorContext . content ) . toBeVisible ( { timeout : 15000 } ) ;
11411151 await editorContext . content . click ( ) ;
11421152
1143- await this . specEditorHelper . loadFullEditorDocument ( editorContext . scroller ) ;
1153+ await this . specEditorHelper . loadFullEditorDocument (
1154+ editorContext . scroller ,
1155+ ) ;
11441156 await editorContext . scroller . evaluate ( ( el ) => {
11451157 el . scrollTop = 0 ;
11461158 } ) ;
@@ -1151,16 +1163,14 @@ export class ExampleGenerationPage extends BasePage {
11511163 : [ `${ exampleName } _response` ] ;
11521164
11531165 for ( const searchTerm of targets ) {
1154- const foundByEditorApi = await this . specEditorHelper . focusTermUsingCodeMirrorApi (
1155- editorContext . content ,
1156- searchTerm ,
1157- ) ;
1166+ const foundByEditorApi =
1167+ await this . specEditorHelper . focusTermUsingCodeMirrorApi (
1168+ editorContext . content ,
1169+ searchTerm ,
1170+ ) ;
11581171 const foundByWindowFind = foundByEditorApi
11591172 ? true
1160- : await this . findTermUsingWindowFind (
1161- editorContext . frame ,
1162- searchTerm ,
1163- ) ;
1173+ : await this . findTermUsingWindowFind ( editorContext . frame , searchTerm ) ;
11641174
11651175 if ( ! foundByWindowFind ) {
11661176 await this . specEditorHelper . scrollEditorToFindTerm (
@@ -1169,8 +1179,10 @@ export class ExampleGenerationPage extends BasePage {
11691179 editorContext . lines ,
11701180 searchTerm ,
11711181 ) ;
1172- // Click the matched line for visual cursor placement
1173- const match = editorContext . lines . filter ( { hasText : searchTerm } ) . first ( ) ;
1182+
1183+ const match = editorContext . lines
1184+ . filter ( { hasText : searchTerm } )
1185+ . first ( ) ;
11741186 if ( ( await match . count ( ) ) > 0 ) {
11751187 await match . scrollIntoViewIfNeeded ( ) ;
11761188 await match . click ( ) ;
0 commit comments