@@ -13,8 +13,8 @@ export class DetailsPage {
1313
1414 async selectTab ( tabName : string ) {
1515 const tab = this . page . locator ( "button[role='tab']" , { hasText : tabName } ) ;
16- expect ( tab ) . toBeVisible ( ) ;
17- tab . click ( ) ;
16+ await expect ( tab ) . toBeVisible ( ) ;
17+ await tab . click ( ) ;
1818 }
1919
2020 async clickOnPageAction ( actionName : string ) {
@@ -41,36 +41,36 @@ export class DetailsPage {
4141 await expect ( this . page . getByRole ( "tab" , { name : tabName } ) ) . toHaveCount ( 0 ) ;
4242 }
4343
44+ //Wait for Loading Spinner to detach from the DOM
4445 async waitForData ( ) {
45- await expect ( this . page . getByLabel ( "Contents" ) ) . toHaveCount ( 0 , {
46- timeout : 5000 ,
47- } ) ;
46+ const spinner = this . page . getByLabel ( "Contents" ) ;
47+ await spinner . waitFor ( { state : "detached" } ) ;
4848 }
4949
50+ //Verifies the Page loads with data
5051 async verifyDataAvailable ( ) {
51- const rows = await this . page
52- . locator ( "xpath=//div[(.='No data available to be shown here.')]" )
53- . count ( ) ;
54- await expect ( rows , "No data available - Verify the data load" ) . toEqual ( 0 ) ;
52+ await expect (
53+ this . page . locator (
54+ `xpath=//div[(.='No data available to be shown here.')]`
55+ )
56+ ) . toHaveCount ( 0 ) ;
5557 }
5658
59+ //Verifies the Vulnerability counts from summary to table
5760 async verifyVulnerabilityPanelcount ( ) {
58- const pieVulnSevLabel =
59- "xpath=//*[name()='svg']/*[name()='g']//*[name()='tspan']" ;
60- const totalVuln =
61- "xpath=//*[name()='svg']/*[name()='text']//*[name()='tspan'][1]" ;
61+ const pieVulnSevLabel = `xpath=//*[name()='svg']/*[name()='g']//*[name()='tspan']` ;
62+ const totalVuln = `xpath=//*[name()='svg']/*[name()='text']//*[name()='tspan'][1]` ;
6263
6364 const panelVulnSev = await this . getCountFromLabels ( pieVulnSevLabel , ":" ) ;
6465 const sumPanelVulnSev = Object . values ( panelVulnSev ) . reduce (
6566 ( sum , value ) => sum + value ,
6667 0
6768 ) ;
68- const totalVulnPanel = await this . page . locator ( totalVuln ) . innerText ( ) ;
69+ const totalVulnPanel = await this . page . locator ( totalVuln ) . textContent ( ) ;
6970 const tableVulnSev = await this . getCVSSCountFromVulnTable ( ) ;
7071 var mismatch = false ;
71-
7272 await expect (
73- parseInt ( totalVulnPanel , 10 ) ,
73+ parseInt ( totalVulnPanel ! , 10 ) ,
7474 "Total Vulnerabilities count {totalVuln} mismatches with sum of individual {sumOfVulnSev}"
7575 ) . toEqual ( sumPanelVulnSev ) ;
7676
@@ -82,18 +82,25 @@ export class DetailsPage {
8282 }
8383 }
8484 }
85- await expect ( mismatch , "Panel count mismatches to table count" ) ;
85+ await expect ( mismatch , "Panel count mismatches to table count" ) . not . toBe (
86+ true
87+ ) ;
8688 }
8789
90+ /**
91+ * Get all the Elements matching to the @param labelLocator and retrieves the textContext of each element
92+ * Splits the text with @param delimiter
93+ * @returns the mutable object { [key: 0th_element ]: 1st_element }
94+ */
8895 async getCountFromLabels (
8996 labelLocator : string ,
9097 delimiter : string
9198 ) : Promise < { [ key : string ] : number } > {
9299 const elements = await this . page . locator ( labelLocator ) . all ( ) ;
93100 const vulnLabelCount = { } ;
94101 for ( const element of elements ) {
95- const innerText = await element . innerText ( ) ;
96- const labelArr = await innerText ? .split ( delimiter ) ;
102+ const innerText = await element . textContent ( ) ;
103+ const labelArr = await innerText ! . split ( delimiter ) ;
97104 vulnLabelCount [ labelArr [ 0 ] . trim ( ) . toString ( ) ] = parseInt (
98105 labelArr [ 1 ] . trim ( ) ,
99106 10
@@ -102,6 +109,11 @@ export class DetailsPage {
102109 return vulnLabelCount ;
103110 }
104111
112+ /**
113+ * Retrieves the CVSS value from each row of Vulnerability table
114+ * @returns Count of each CVSS type in { [key: severity ]: count }
115+ */
116+
105117 async getCVSSCountFromVulnTable ( ) : Promise < { [ key : string ] : number } > {
106118 var nextPage = true ;
107119 const counts = {
@@ -113,19 +125,21 @@ export class DetailsPage {
113125 Critical : 0 ,
114126 } ;
115127 const nextButton = await this . page . locator (
116- " xpath=(//section[@id='refVulnerabilitiesSection']//button[@data-action='next'])[1]"
128+ ` xpath=(//section[@id='refVulnerabilitiesSection']//button[@data-action='next'])[1]`
117129 ) ;
118130
119- await this . page
120- . getByLabel ( "Vulnerabilities within the" )
121- . locator ( "#pagination-id-top-toggle" )
122- . click ( ) ;
123- await this . page . getByRole ( "menuitem" , { name : "100 per page" } ) . click ( ) ;
131+ const noOfRows = await this . page . locator (
132+ `xpath=//section[@id="refVulnerabilitiesSection"]//button[@id="pagination-id-top-toggle"]`
133+ ) ;
134+ if ( await noOfRows . isEnabled ( ) ) {
135+ noOfRows . click ( ) ;
136+ await this . page . getByRole ( "menuitem" , { name : "100 per page" } ) . click ( ) ;
137+ }
124138
125139 while ( nextPage ) {
126140 const cvssLocator = await this . page
127141 . locator (
128- " xpath=//table[@aria-label='Vulnerability table']//td[@data-label='CVSS']"
142+ ` xpath=//table[@aria-label='Vulnerability table']//td[@data-label='CVSS']`
129143 )
130144 . all ( ) ;
131145 for ( const cvss of cvssLocator ) {
0 commit comments