1- """Wishlist test suite: add and remove products via various flows ."""
1+ """Wishlist test suite: add and remove products via data-driven CSV ."""
22
33import pytest
44
88from actions .accountpageaction import AccountPageAction
99from utils .excelReader import get_data
1010from utils .loggerCreator import get_logger
11+ from utils .csvDataProvider import CsvDataProvider as CS
1112
1213LOGIN_DATA_PATH = "data_provider/DataProvider.xlsx"
1314LOGIN_DATA_SHEET = "loginDataValid"
14-
15- PRODUCT_IMAC = "iMac"
16- PRODUCT_APPLE_CINEMA = "Apple Cinema 30"
17- PRODUCT_IPOD_NANO = "iPod Nano"
18- PRODUCT_IPOD_SHUFFLE = "iPod Shuffle"
15+ WISHLIST_CSV_PATH = "data_provider/wishlist_data.csv"
1916
2017SUCCESS_KEYWORD = "Success"
2118MODIFIED_KEYWORD = "modified"
2219
2320logger = get_logger (__name__ )
2421
2522
23+ def log_csv_data (data ):
24+ """Log CSV row data."""
25+ logger .info ("CSV test data loaded successfully" )
26+
27+ for key , value in data .items ():
28+ logger .info ("%s = %s" , key , value )
29+
30+
2631@pytest .fixture
2732def setup (driver ):
28- """Log in and return ( driver, wait, wishlist_actions) for each test ."""
33+ """Log in and return driver, wait, and wishlist actions ."""
2934 drv , wait = driver
3035
3136 wishlist_actions = WishListActions (drv )
3237
3338 assert "route=common/home" in drv .current_url
3439 logger .info ("Landed on home page: %s" , drv .current_url )
3540
36- username , password = get_data (LOGIN_DATA_PATH , LOGIN_DATA_SHEET )[0 ]
37- logger .info ("Using credentials for user: %s" , username )
41+ login_data = get_data (LOGIN_DATA_PATH , LOGIN_DATA_SHEET )
42+
43+ logger .info (
44+ "Loaded %d login record(s) from Excel file '%s' sheet '%s'" ,
45+ len (login_data ),
46+ LOGIN_DATA_PATH ,
47+ LOGIN_DATA_SHEET ,
48+ )
49+
50+ username , password = login_data [0 ]
51+ logger .info ("Selected login username: %s" , username )
3852
3953 home_page_action = HomePageAction (drv )
4054 home_page_action .click_myAcc ()
41- logger .info ("Clicked ' My Account' link" )
55+ logger .info ("Clicked My Account link" )
4256
4357 login_page_action = LoginPageAction (drv )
4458 login_page_action .enter_login_credentials (username , password )
4559 logger .info ("Submitted login credentials" )
4660
4761 account_page_action = AccountPageAction (drv )
4862 login_ok = account_page_action .success_login ()
63+
4964 assert login_ok is True
5065 logger .info ("Login successful: %s" , login_ok )
5166
@@ -56,156 +71,239 @@ def setup(driver):
5671
5772
5873def _assert_success_message (message ):
74+ """Validate wishlist add success message."""
5975 logger .info ("Wishlist success message: %s" , message )
76+
6077 assert message
6178 assert SUCCESS_KEYWORD in message
6279
6380
6481def _assert_removal_message (message ):
82+ """Validate wishlist remove success or modified message."""
6583 logger .info ("Wishlist removal message: %s" , message )
84+
6685 assert message
6786 assert SUCCESS_KEYWORD in message or MODIFIED_KEYWORD in message
6887
6988
7089def _ensure_product_in_wishlist (wishlist_actions , product_name , scroll_method ):
90+ """Add product to wishlist if it is not already present."""
7191 if not wishlist_actions .is_product_present_in_wishlist (product_name ):
72- logger .info ("'%s' not in wishlist, adding it now" , product_name )
92+ logger .info ("Product '%s' not found in wishlist. Adding now." , product_name )
93+
7394 scroll_method ()
7495 wishlist_actions .add_product_to_wishlist_by_name (product_name )
96+
97+ logger .info ("Product '%s' added to wishlist" , product_name )
98+
7599 wishlist_actions .navigate_to_wishlist_via_account ()
76100 wishlist_actions .wait_for_wishlist_page ()
101+
102+ logger .info ("Returned to wishlist page after adding product" )
77103 else :
78- logger .info ("'%s' already present in wishlist" , product_name )
104+ logger .info ("Product '%s' already present in wishlist" , product_name )
79105
80106
81107@pytest .mark .Prasanna
82- def test_add_single_product_to_wishlist (setup ):
83- """Adding a single product from the home page shows it in the wishlist."""
108+ @pytest .mark .parametrize (
109+ "data" ,
110+ CS .get_csv_data_by_test_name (
111+ WISHLIST_CSV_PATH ,
112+ "test_add_single_product_to_wishlist" ,
113+ ),
114+ )
115+ def test_add_single_product_to_wishlist (setup , data ):
116+ """Add a single product from home page to wishlist."""
84117 _ , _ , wishlist_actions = setup
85118
86- logger .info ("Starting test: add single product '%s' to wishlist" , PRODUCT_IMAC )
119+ log_csv_data (data )
120+
121+ product_name = data ["product_name" ]
122+ expected_page = data ["expected_page" ]
123+
124+ logger .info ("Starting test: add single product '%s'" , product_name )
87125
88126 wishlist_actions .scroll_to_top_products ()
89- wishlist_actions .hover_and_click_wishlist_button (PRODUCT_IMAC )
90- logger .info ("Clicked wishlist button for '%s'" , PRODUCT_IMAC )
127+ logger .info ("Scrolled to top products section" )
128+
129+ wishlist_actions .hover_and_click_wishlist_button (product_name )
130+ logger .info ("Clicked wishlist button for '%s'" , product_name )
91131
92- _assert_success_message (wishlist_actions .get_wishlist_success_message_generic ())
132+ _assert_success_message (
133+ wishlist_actions .get_wishlist_success_message_generic ()
134+ )
93135
94136 wishlist_actions .click_wishlist_link_from_popup ()
95137 wishlist_actions .wait_for_wishlist_page ()
96- logger .info ("Navigated to wishlist page via popup link " )
138+ logger .info ("Navigated to wishlist page from success popup " )
97139
98140 page_title = wishlist_actions .get_current_page_title ()
99141 logger .info ("Wishlist page title: %s" , page_title )
100- assert "My Wish List" in page_title
142+
143+ assert expected_page in page_title
101144
102145 product_names = wishlist_actions .get_all_wishlist_product_names ()
103- logger .info ("Products currently in wishlist: %s" , product_names )
104- assert product_names
105- assert any (PRODUCT_IMAC in name for name in product_names )
146+ logger .info ("Wishlist products: %s" , product_names )
106147
107- logger .info ("Test passed: '%s' found in wishlist" , PRODUCT_IMAC )
148+ assert any (product_name in name for name in product_names )
149+
150+ logger .info ("Test passed: '%s' found in wishlist" , product_name )
108151
109152
110153@pytest .mark .Prasanna
111- def test_add_multiple_products_to_wishlist (setup ):
112- """Adding multiple products from the top collection shows all of them in the wishlist."""
154+ @pytest .mark .parametrize (
155+ "data" ,
156+ CS .get_csv_data_by_test_name (
157+ WISHLIST_CSV_PATH ,
158+ "test_add_multiple_products_to_wishlist" ,
159+ ),
160+ )
161+ def test_add_multiple_products_to_wishlist (setup , data ):
162+ """Add multiple products from top collection to wishlist."""
113163 _ , _ , wishlist_actions = setup
114164
115- products = [PRODUCT_APPLE_CINEMA , PRODUCT_IPOD_NANO ]
116- logger .info ("Starting test: add multiple products %s to wishlist" , products )
165+ log_csv_data (data )
166+
167+ product_name = data ["product_name" ]
168+
169+ logger .info ("Starting test: add product '%s' from top collection" , product_name )
117170
118171 wishlist_actions .scroll_to_top_collection ()
172+ logger .info ("Scrolled to top collection section" )
119173
120- for product_name in products :
121- wishlist_actions .add_product_to_wishlist_by_name (product_name )
122- logger .info ("Added '%s' to wishlist" , product_name )
123- _assert_success_message (wishlist_actions .get_wishlist_success_message_generic ())
174+ wishlist_actions .add_product_to_wishlist_by_name (product_name )
175+ logger .info ("Added '%s' to wishlist" , product_name )
176+
177+ _assert_success_message (
178+ wishlist_actions .get_wishlist_success_message_generic ()
179+ )
124180
125181 wishlist_actions .navigate_to_wishlist_via_account ()
126182 wishlist_actions .wait_for_wishlist_page ()
127183 logger .info ("Navigated to wishlist page via account" )
128184
129185 product_names = wishlist_actions .get_all_wishlist_product_names ()
130- logger .info ("Products currently in wishlist : %s" , product_names )
186+ logger .info ("Wishlist products : %s" , product_names )
131187
132- for product_name in products :
133- assert any (product_name in name for name in product_names )
188+ assert any (product_name in name for name in product_names )
134189
135- logger .info ("Test passed: all products %s found in wishlist" , products )
190+ logger .info ("Test passed: '%s' found in wishlist" , product_name )
136191
137192
138193@pytest .mark .Prasanna
139- def test_add_product_via_search (setup ):
140- """Adding a product found via search shows it in the wishlist."""
194+ @pytest .mark .parametrize (
195+ "data" ,
196+ CS .get_csv_data_by_test_name (
197+ WISHLIST_CSV_PATH ,
198+ "test_add_product_via_search" ,
199+ ),
200+ )
201+ def test_add_product_via_search (setup , data ):
202+ """Add product to wishlist using search flow."""
141203 _ , _ , wishlist_actions = setup
142204
143- logger .info ("Starting test: add product '%s' via search" , PRODUCT_IPOD_SHUFFLE )
205+ log_csv_data (data )
206+
207+ product_name = data ["product_name" ]
144208
145- wishlist_actions .search_for_product (PRODUCT_IPOD_SHUFFLE )
146- logger .info ("Searched for product: %s" , PRODUCT_IPOD_SHUFFLE )
209+ logger .info ("Starting test: add product '%s' via search" , product_name )
147210
148- wishlist_actions .click_product_from_search_results (PRODUCT_IPOD_SHUFFLE )
149- logger .info ("Opened product page for: %s" , PRODUCT_IPOD_SHUFFLE )
211+ wishlist_actions .search_for_product (product_name )
212+ logger .info ("Searched product: %s" , product_name )
213+
214+ wishlist_actions .click_product_from_search_results (product_name )
215+ logger .info ("Opened product from search results: %s" , product_name )
150216
151217 wishlist_actions .click_heart_button_on_product_page ()
152- logger .info ("Clicked wishlist ( heart) button on product page" )
218+ logger .info ("Clicked wishlist heart button on product page" )
153219
154- _assert_success_message (wishlist_actions .get_wishlist_success_message_generic ())
220+ _assert_success_message (
221+ wishlist_actions .get_wishlist_success_message_generic ()
222+ )
155223
156224 wishlist_actions .navigate_to_wishlist_via_account ()
157225 wishlist_actions .wait_for_wishlist_page ()
158226 logger .info ("Navigated to wishlist page via account" )
159227
160228 product_names = wishlist_actions .get_all_wishlist_product_names ()
161- logger .info ("Products currently in wishlist: %s" , product_names )
162- assert any (PRODUCT_IPOD_SHUFFLE in name for name in product_names )
229+ logger .info ("Wishlist products: %s" , product_names )
163230
164- logger .info ("Test passed: '%s' found in wishlist" , PRODUCT_IPOD_SHUFFLE )
231+ assert any (product_name in name for name in product_names )
232+
233+ logger .info ("Test passed: '%s' found in wishlist" , product_name )
165234
166235
167236@pytest .mark .Prasanna
168- def test_remove_single_product_from_wishlist (setup ):
169- """Removing a single product from the wishlist shows a success/modified message."""
237+ @pytest .mark .parametrize (
238+ "data" ,
239+ CS .get_csv_data_by_test_name (
240+ WISHLIST_CSV_PATH ,
241+ "test_remove_single_product_from_wishlist" ,
242+ ),
243+ )
244+ def test_remove_single_product_from_wishlist (setup , data ):
245+ """Remove a single product from wishlist."""
170246 _ , _ , wishlist_actions = setup
171247
172- logger .info ("Starting test: remove single product '%s' from wishlist" , PRODUCT_IMAC )
248+ log_csv_data (data )
249+
250+ product_name = data ["product_name" ]
251+
252+ logger .info ("Starting test: remove single product '%s'" , product_name )
173253
174254 wishlist_actions .navigate_to_wishlist_via_account ()
175255 wishlist_actions .wait_for_wishlist_page ()
176256 logger .info ("Navigated to wishlist page" )
177257
178258 _ensure_product_in_wishlist (
179- wishlist_actions , PRODUCT_IMAC , wishlist_actions .scroll_to_top_products
259+ wishlist_actions ,
260+ product_name ,
261+ wishlist_actions .scroll_to_top_products ,
180262 )
181263
182- wishlist_actions .remove_product_from_wishlist (PRODUCT_IMAC )
183- logger .info ("Clicked remove button for '%s'" , PRODUCT_IMAC )
264+ wishlist_actions .remove_product_from_wishlist (product_name )
265+ logger .info ("Clicked remove button for '%s'" , product_name )
184266
185- _assert_removal_message (wishlist_actions .get_removal_success_message ())
267+ _assert_removal_message (
268+ wishlist_actions .get_removal_success_message ()
269+ )
186270
187- logger .info ("Test passed: '%s' removed from wishlist" , PRODUCT_IMAC )
271+ logger .info ("Test passed: '%s' removed from wishlist" , product_name )
188272
189273
190274@pytest .mark .Prasanna
191- @pytest .mark .parametrize ("product_name" , [PRODUCT_APPLE_CINEMA , PRODUCT_IPOD_NANO ])
192- def test_remove_multiple_products_from_wishlist (setup , product_name ):
193- """Removing each product from the wishlist shows a success/modified message."""
275+ @pytest .mark .parametrize (
276+ "data" ,
277+ CS .get_csv_data_by_test_name (
278+ WISHLIST_CSV_PATH ,
279+ "test_remove_multiple_products_from_wishlist" ,
280+ ),
281+ )
282+ def test_remove_multiple_products_from_wishlist (setup , data ):
283+ """Remove multiple products from wishlist using CSV data."""
194284 _ , _ , wishlist_actions = setup
195285
196- logger .info ("Starting test: remove product '%s' from wishlist" , product_name )
286+ log_csv_data (data )
287+
288+ product_name = data ["product_name" ]
289+
290+ logger .info ("Starting test: remove product '%s'" , product_name )
197291
198292 wishlist_actions .navigate_to_wishlist_via_account ()
199293 wishlist_actions .wait_for_wishlist_page ()
200294 logger .info ("Navigated to wishlist page" )
201295
202296 _ensure_product_in_wishlist (
203- wishlist_actions , product_name , wishlist_actions .scroll_to_top_collection
297+ wishlist_actions ,
298+ product_name ,
299+ wishlist_actions .scroll_to_top_collection ,
204300 )
205301
206302 wishlist_actions .remove_product_from_wishlist (product_name )
207303 logger .info ("Clicked remove button for '%s'" , product_name )
208304
209- _assert_removal_message (wishlist_actions .get_removal_success_message ())
305+ _assert_removal_message (
306+ wishlist_actions .get_removal_success_message ()
307+ )
210308
211309 logger .info ("Test passed: '%s' removed from wishlist" , product_name )
0 commit comments