@@ -9,52 +9,38 @@ import { HUB_PAGE_URL, RSV_PAGE_URL, RSV_PREGNANCY_PAGE_URL } from "../constants
99test . describe ( "E2E" , ( ) => {
1010 let page : Page ;
1111 let projectName : string ;
12- let fileName : string ;
12+ let testFileName : string ;
1313
1414 test . beforeAll ( async ( { browser } , testInfo : TestInfo ) => {
1515 testInfo . setTimeout ( 60000 ) ;
1616 page = await login ( browser , users . Default . email ) ;
1717 projectName = testInfo . project . name ;
18- fileName = testInfo . file . split ( "/" ) . pop ( ) ! ;
18+ testFileName = testInfo . file . split ( "/" ) . pop ( ) ! ;
1919
2020 await page . mouse . move ( 0 , 0 ) ;
2121 } ) ;
2222
23- test ( "Page Snapshots" , async ( ) => {
24- let screenshotFileName : string ;
25- let customScreenshotPath : string ;
26-
27- screenshotFileName = "default-hub.png" ;
28- customScreenshotPath = pathForCustomScreenshots ( fileName , screenshotFileName , projectName ) ;
29- await page . goto ( HUB_PAGE_URL ) ;
23+ const testPageSnapshot = async ( snapshotFileName : string , pageRoute : string ) => {
24+ const screenshotPath : string = pathForCustomScreenshots ( testFileName , snapshotFileName , projectName ) ;
25+ await page . goto ( pageRoute ) ;
3026 await page . screenshot ( {
31- path : customScreenshotPath ,
27+ path : screenshotPath ,
3228 fullPage : true ,
3329 } ) ;
34- await expect . soft ( page ) . toHaveScreenshot ( screenshotFileName , {
30+ await expect . soft ( page ) . toHaveScreenshot ( snapshotFileName , {
3531 fullPage : true ,
3632 } ) ;
33+ } ;
3734
38- screenshotFileName = "default-rsv.png" ;
39- customScreenshotPath = pathForCustomScreenshots ( fileName , screenshotFileName , projectName ) ;
40- await page . goto ( RSV_PAGE_URL ) ;
41- await page . screenshot ( {
42- path : customScreenshotPath ,
43- fullPage : true ,
44- } ) ;
45- await expect . soft ( page ) . toHaveScreenshot ( screenshotFileName , {
46- fullPage : true ,
47- } ) ;
35+ const PathsToSnapshots = [
36+ { snapshotFilename : "default-hub.png" , pageRoute : HUB_PAGE_URL } ,
37+ { snapshotFilename : "default-rsv.png" , pageRoute : RSV_PAGE_URL } ,
38+ { snapshotFilename : "default-rsv-pregnancy.png" , pageRoute : RSV_PREGNANCY_PAGE_URL } ,
39+ ] ;
4840
49- screenshotFileName = "default-rsv-pregnancy.png" ;
50- customScreenshotPath = pathForCustomScreenshots ( fileName , screenshotFileName , projectName ) ;
51- await page . goto ( RSV_PREGNANCY_PAGE_URL ) ;
52- await page . screenshot ( {
53- path : customScreenshotPath ,
54- fullPage : true ,
55- } ) ;
56- await expect . soft ( page ) . toHaveScreenshot ( screenshotFileName , {
57- fullPage : true ,
41+ PathsToSnapshots . forEach ( ( { snapshotFilename, pageRoute } ) => {
42+ test ( `Testing snapshot for ${ pageRoute } ` , async ( ) => {
43+ await testPageSnapshot ( snapshotFilename , pageRoute ) ;
5844 } ) ;
5945 } ) ;
6046} ) ;
0 commit comments