1
- import { test , expect , chromium , Browser , BrowserContext , Page } from '@playwright/test' ;
2
- import type { TestInfo } from '@playwright/test' ;
3
- const { screenshot } = require ( '../utils' ) ( )
4
- import SearchResultsPage from '../pages/searchResults' ;
5
- import ProductViewPage from '../pages/productView' ;
6
- import ProductSpecsSection from '../pages/sections/productSpecs' ;
7
- import AddedToCartConfirmationPage from '../pages/addedToCart' ;
1
+ import { test , expect } from '../fixtures/swiftie' ;
8
2
9
3
test . describe ( 'T Swift 1989 Album' , async ( ) => {
10
- let browser : Browser ;
11
- let context : BrowserContext ;
12
- let page : Page ;
13
4
let foundName : string ;
14
5
let foundASIN : string ;
15
- let ProductView : ProductViewPage ;
16
- let SearchResults : SearchResultsPage ;
17
- let ProductSpecs : ProductSpecsSection ;
18
- let AddedToCartConfirmation : AddedToCartConfirmationPage ;
19
6
20
- async function newSearch ( searchPhrase : string ) {
21
- ProductView = new ProductViewPage ( page )
22
- await ( await ProductView . searchBox ) . fill ( searchPhrase )
23
- await page . keyboard . press ( 'Enter' )
24
- }
25
-
26
- test . beforeEach ( async ( ) => {
27
- // For Debugging Only: Do not push uncommented
28
- // browser = await chromium.launch({ headless: false });
29
- // For CI
30
- browser = await chromium . launch ( ) ;
31
- context = await browser . newContext ( ) ;
32
- page = await context . newPage ( ) ;
33
- await page . goto ( 'https://www.amazon.com/1989-Taylors-Version-Taylor-Swift/dp/B0CFM76QSG?content-id=amzn1.sym.cb9c3293-7215-4d97-8c71-e1fed9b4d8f1&pd_rd_i=B0CFM76QSG&pd_rd_r=180b3bdc-c298-4f86-bb91-4ef0c80d1cb8&pd_rd_w=tHKD5&pd_rd_wg=kJ0QW&pf_rd_p=cb9c3293-7215-4d97-8c71-e1fed9b4d8f1&pf_rd_r=V7JWQ7ZF2DB34CY3VM1V&ref_=Oct_d_onr_d_5174_2' )
34
- await page . waitForLoadState ( 'domcontentloaded' )
35
- } )
36
-
37
- test . afterEach ( async ( { } , testInfo : TestInfo ) => {
38
- await screenshot ( page , testInfo . title )
39
- await page . close ( )
40
- await context . close ( )
41
- await browser . close ( ) ;
42
- } )
43
-
44
- test ( 'Can find T Swift album by product name and view details page' , async ( ) => {
45
- ProductView = new ProductViewPage ( page )
46
- foundName = await ( await ProductView . productName ) . textContent ( ) ?? ''
47
- await newSearch ( foundName )
7
+ test ( 'Can find T Swift album by product name and view details page' , async ( { page, productViewPage, searchResultsPage } ) => {
8
+ foundName = await ( await productViewPage . productName ) . textContent ( ) ?? ''
9
+ await productViewPage . newSearch ( foundName )
48
10
await page . waitForLoadState ( 'domcontentloaded' )
49
- SearchResults = new SearchResultsPage ( page )
50
- await expect ( await SearchResults . firstResult ) . toHaveText ( SearchResults . firstResultM )
51
- await ( await SearchResults . firstResultLink ) . click ( )
11
+ await expect ( await searchResultsPage . firstResult ) . toHaveText ( searchResultsPage . firstResultM )
12
+ await ( await searchResultsPage . firstResultLink ) . click ( )
52
13
await page . waitForLoadState ( 'domcontentloaded' )
53
- await expect ( await ProductView . productName ) . toHaveText ( ProductView . productNameM )
14
+ await expect ( await productViewPage . productName ) . toHaveText ( productViewPage . productNameM )
54
15
} )
55
16
56
- test ( 'ASIN is correct' , async ( ) => {
57
- ProductView = new ProductViewPage ( page )
58
- ProductSpecs = new ProductSpecsSection ( await ProductView . productSpecs )
59
- foundASIN = await ( await ProductSpecs . asin ) . textContent ( ) ?? ''
60
- expect ( foundASIN ) . toEqual ( ProductSpecs . asinM )
17
+ test ( 'ASIN is correct' , async ( { page, productSpecsSection } ) => {
18
+ foundASIN = await ( await productSpecsSection . asin ) . textContent ( ) ?? ''
19
+ expect ( foundASIN ) . toEqual ( productSpecsSection . asinM )
61
20
} )
62
21
63
- test ( 'Can find T Swift album by ASIN' , async ( ) => {
64
- ProductView = new ProductViewPage ( page )
65
- ProductSpecs = new ProductSpecsSection ( await ProductView . productSpecs )
66
- await newSearch ( foundASIN )
22
+ test ( 'Can find T Swift album by ASIN' , async ( { page, productViewPage, searchResultsPage } ) => {
23
+ await productViewPage . newSearch ( foundASIN )
67
24
await page . waitForLoadState ( 'domcontentloaded' )
68
- SearchResults = new SearchResultsPage ( page )
69
- await expect ( await SearchResults . firstResult ) . toHaveText ( SearchResults . firstResultM )
70
- await ( await SearchResults . firstResultLink ) . click ( )
25
+ await expect ( await searchResultsPage . firstResult ) . toHaveText ( searchResultsPage . firstResultM )
26
+ await ( await searchResultsPage . firstResultLink ) . click ( )
71
27
await page . waitForLoadState ( 'domcontentloaded' )
72
- await expect ( await ProductView . productName ) . toHaveText ( ProductView . productNameM )
28
+ await expect ( await productViewPage . productName ) . toHaveText ( productViewPage . productNameM )
73
29
} )
74
30
75
- test ( 'T Swift album can be added to cart' , async ( ) => {
76
- ProductView = new ProductViewPage ( page )
77
- await expect ( await ProductView . cartCount ) . toHaveText ( '0' )
78
- await ( await ProductView . addToCartBtn ) . click ( )
31
+ test ( 'T Swift album can be added to cart' , async ( { page, productViewPage, addedToCartPage } ) => {
32
+ await expect ( await productViewPage . cartCount ) . toHaveText ( '0' )
33
+ await ( await productViewPage . addToCartBtn ) . click ( )
79
34
await page . waitForLoadState ( 'domcontentloaded' )
80
- AddedToCartConfirmation = new AddedToCartConfirmationPage ( page )
81
- await expect ( await AddedToCartConfirmation . addedToCart ) . toContainText ( AddedToCartConfirmation . addedToCartM )
82
- await expect ( await ProductView . cartCount ) . toHaveText ( '1' )
35
+ await expect ( await addedToCartPage . addedToCart ) . toContainText ( addedToCartPage . addedToCartM )
36
+ await expect ( await productViewPage . cartCount ) . toHaveText ( '1' )
83
37
} )
84
38
} )
0 commit comments