1+ import logging
12import os
23import os .path
3- import logging
44
55from base .base import BasePage
66
@@ -33,7 +33,7 @@ class HomePage(BasePage):
3333 CANCEL_UPLOAD_MSG = "//button[normalize-space()='Cancel upload']"
3434 DELETE_BATCH_BTN = "//button[contains(text(),'✕')]"
3535 DELETE_BATCH_HISTORY = "//button[normalize-space()='Delete']"
36-
36+
3737 # Unsupported file validation messages
3838 ERROR_MSG_AUDIO = "//span[.=\" File 'test_audio.wav' is not a valid SQL file. Only .sql files are allowed.\" ]"
3939 ERROR_MSG_DOCX = "//div[.=\" File 'test_doc.docx' is not a valid SQL file. Only .sql files are allowed.\" ]"
@@ -42,14 +42,13 @@ class HomePage(BasePage):
4242 ERROR_MSG_PDF = "//div[text()=\" File 'test_pdf.pdf' is not a valid SQL file. Only .sql files are allowed.\" ]"
4343 ERROR_MSG_POWERBI = "//div[text()=\" File 'test_powerBi.pbix' is not a valid SQL file. Only .sql files are allowed.\" ]"
4444 ERROR_MSG_TXT = "//div[text()=\" File 'test_text.txt' is not a valid SQL file. Only .sql files are allowed.\" ]"
45-
45+
4646 # Large file validation message
4747 ERROR_MSG_LARGE_FILE = "//span[contains(text(),\" File 'large_dump.sql' exceeds the 200MB size limit. Please upload a file smaller than 200MB.\" )]"
48-
48+
4949 # Harmful file validation message
5050 ERROR_MSG_UNABLE_TO_PROCESS = "//span[normalize-space()='Unable to process the file']"
5151
52-
5352 def __init__ (self , page ):
5453 self .page = page
5554
@@ -82,7 +81,7 @@ def upload_all_files(self):
8281 file_chooser = fc_info .value
8382 current_working_dir = os .getcwd ()
8483 testdata_dir = os .path .join (current_working_dir , "testdata/valid_files" )
85-
84+
8685 # Get all files from testdata/valid_files folder
8786 all_files = []
8887 if os .path .exists (testdata_dir ) and os .path .isdir (testdata_dir ):
@@ -91,7 +90,7 @@ def upload_all_files(self):
9190 # Only add if it's a file (not a directory)
9291 if os .path .isfile (file_path ):
9392 all_files .append (file_path )
94-
93+
9594 # Upload all discovered files
9695 if all_files :
9796 file_chooser .set_files (all_files )
@@ -126,12 +125,12 @@ def remove_first_three_files_and_validate_count(self):
126125 Remove the first three uploaded files and validate that 17 files remain.
127126 """
128127 remove_buttons = self .page .locator (self .REMOVE_FILE_BTN )
129-
128+
130129 # Remove first three files
131- for i in range (3 ):
130+ for _i in range (3 ):
132131 remove_buttons .first .click ()
133132 self .page .wait_for_timeout (2000 )
134-
133+
135134 # Validate remaining files count is 17
136135 uploaded_files = self .page .locator (self .FILES_UPLOADED )
137136 actual_count = uploaded_files .count ()
@@ -149,7 +148,6 @@ def cancel_upload_and_validate_home(self):
149148 self .page .wait_for_timeout (3000 )
150149 expect (self .page .locator (self .TITLE_TEXT )).to_be_visible ()
151150
152-
153151 def upload_unsupported_files (self ):
154152 with self .page .expect_file_chooser () as fc_info :
155153 self .page .locator (self .BROWSE_FILES ).click ()
@@ -175,7 +173,7 @@ def upload_all_unsupported_files_and_validate(self):
175173 file_chooser = fc_info .value
176174 current_working_dir = os .getcwd ()
177175 unsupported_dir = os .path .join (current_working_dir , "testdata/Unsupported_files" )
178-
176+
179177 # Get all files from testdata/Unsupported_files folder
180178 all_unsupported_files = []
181179 if os .path .exists (unsupported_dir ) and os .path .isdir (unsupported_dir ):
@@ -184,17 +182,17 @@ def upload_all_unsupported_files_and_validate(self):
184182 # Only add if it's a file (not a directory)
185183 if os .path .isfile (file_path ):
186184 all_unsupported_files .append (file_path )
187-
185+
188186 logger .info (f"Found { len (all_unsupported_files )} unsupported files to upload" )
189187 logger .info (f"Unsupported files: { [os .path .basename (f ) for f in all_unsupported_files ]} " )
190-
188+
191189 # Upload all unsupported files
192190 if all_unsupported_files :
193191 file_chooser .set_files (all_unsupported_files )
194192 self .page .wait_for_timeout (5000 )
195193 self .page .wait_for_load_state ("networkidle" )
196194 logger .info ("All unsupported files uploaded" )
197-
195+
198196 # Validate error messages for each unsupported file type
199197 error_validations = [
200198 (self .ERROR_MSG_AUDIO , "test_audio.wav" ),
@@ -203,22 +201,21 @@ def upload_all_unsupported_files_and_validate(self):
203201 (self .ERROR_MSG_PDF , "test_pdf.pdf" ),
204202 (self .ERROR_MSG_TXT , "test_text.txt" ),
205203 ]
206-
204+
207205 logger .info ("Validating error messages for unsupported files..." )
208206 for error_locator , filename in error_validations :
209207 try :
210208 expect (self .page .locator (error_locator )).to_be_visible (timeout = 5000 )
211209 logger .info (f"✓ Error message validated for '{ filename } '" )
212210 except Exception as e :
213211 logger .warning (f"✗ Error message not found for '{ filename } ': { str (e )} " )
214-
212+
215213 # Validate that translate button is disabled
216214 is_disabled = self .page .locator (self .TRANSLATE_BTN ).is_disabled ()
217215 logger .info (f"Translate button disabled status: { is_disabled } " )
218216 expect (self .page .locator (self .TRANSLATE_BTN )).to_be_disabled ()
219217 logger .info ("Validation passed: Translate button is correctly disabled for unsupported files" )
220218
221-
222219 def upload_harmful_file_and_validate (self ):
223220 """
224221 Upload harmful file from testdata/Harmful_file folder, start translation,
@@ -231,40 +228,40 @@ def upload_harmful_file_and_validate(self):
231228 file_chooser = fc_info .value
232229 current_working_dir = os .getcwd ()
233230 harmful_file_dir = os .path .join (current_working_dir , "testdata/Harmful_file" )
234-
231+
235232 # Get all files from testdata/Harmful_file folder
236233 harmful_files = []
237234 if os .path .exists (harmful_file_dir ) and os .path .isdir (harmful_file_dir ):
238235 for filename in os .listdir (harmful_file_dir ):
239236 file_path = os .path .join (harmful_file_dir , filename )
240237 if os .path .isfile (file_path ):
241238 harmful_files .append (file_path )
242-
239+
243240 if harmful_files :
244241 logger .info (f"Found { len (harmful_files )} harmful file(s) to upload" )
245242 logger .info (f"Harmful file(s): { [os .path .basename (f ) for f in harmful_files ]} " )
246-
243+
247244 # Upload harmful file(s)
248245 file_chooser .set_files (harmful_files )
249246 self .page .wait_for_timeout (5000 )
250247 self .page .wait_for_load_state ("networkidle" )
251248 logger .info ("Harmful file(s) uploaded successfully" )
252-
249+
253250 # Start translation
254251 logger .info ("Clicking 'Start translating' button" )
255252 self .page .locator (self .TRANSLATE_BTN ).click ()
256253 self .page .wait_for_timeout (10000 )
257254 self .page .wait_for_load_state ("networkidle" )
258255 logger .info ("Translation process started" )
259-
256+
260257 # Validate error message is visible
261258 try :
262259 expect (self .page .locator (self .ERROR_MSG_UNABLE_TO_PROCESS )).to_be_visible (timeout = 200000 )
263260 logger .info ("✓ Error message validated: 'Unable to process the file'" )
264261 except Exception as e :
265262 logger .error (f"✗ Error message not found: { str (e )} " )
266263 raise
267-
264+
268265 # Validate download button is disabled
269266 try :
270267 is_disabled = self .page .locator (self .DOWNLOAD_FILES ).is_disabled ()
@@ -274,7 +271,7 @@ def upload_harmful_file_and_validate(self):
274271 except Exception as e :
275272 logger .error (f"✗ Download button validation failed: { str (e )} " )
276273 raise
277-
274+
278275 logger .info ("Validation passed: Harmful file processing error handled correctly" )
279276 else :
280277 logger .error (f"No harmful files found in directory: { harmful_file_dir } " )
@@ -291,7 +288,7 @@ def validate_batch_history(self):
291288 self .page .locator (self .BATCH_HISTORY ).click ()
292289 self .page .wait_for_timeout (3000 )
293290 batch_details = self .page .locator (self .BATCH_DETAILS )
294- for i in range (batch_details .count ()):
291+ for i in range (batch_details .count ()):
295292 expect (batch_details .nth (i )).to_be_visible ()
296293 self .page .locator (self .CLOSE_BATCH_HISTORY ).click ()
297294
@@ -304,25 +301,25 @@ def delete_first_batch_history_and_validate_count(self):
304301 # Open batch history panel
305302 self .page .locator (self .BATCH_HISTORY ).click ()
306303 self .page .wait_for_timeout (3000 )
307-
304+
308305 # Get initial count of batch details
309306 batch_details = self .page .locator (self .BATCH_DETAILS )
310307 initial_count = batch_details .count ()
311308 logger .info (f"Batch history count before deletion: { initial_count } " )
312309 # Hover over the first batch detail to reveal delete button
313310 batch_details .first .hover ()
314311 self .page .wait_for_timeout (1000 )
315-
312+
316313 # Click the delete button (✕) for the first batch
317314 delete_buttons = self .page .locator (self .DELETE_BATCH_BTN )
318315 delete_buttons .first .click ()
319316 self .page .wait_for_timeout (1000 )
320317 logger .info ("Clicked delete button (✕) for the first batch history item" )
321-
318+
322319 self .page .locator (self .DELETE_BATCH_HISTORY ).click ()
323320 self .page .wait_for_timeout (4000 )
324321 logger .info ("Confirmed deletion by clicking 'Delete' button" )
325-
322+
326323 # Open batch history panel
327324 self .page .locator (self .VIEW_BATCH_HISTORY ).click ()
328325 self .page .wait_for_timeout (3000 )
@@ -332,11 +329,11 @@ def delete_first_batch_history_and_validate_count(self):
332329 expected_count = initial_count - 1
333330 logger .info (f"Batch history count after deletion: { new_count } " )
334331 logger .info (f"Expected count: { expected_count } , Actual count: { new_count } " )
335-
332+
336333 # Validate the count is reduced by 1
337334 assert new_count == expected_count , f"Expected { expected_count } batch items after deletion, but found { new_count } "
338335 logger .info (f"Successfully deleted batch history. Count reduced from { initial_count } to { new_count } " )
339-
336+
340337 # Close batch history panel
341338 self .page .locator (self .CLOSE_BATCH_HISTORY ).click ()
342339
@@ -359,4 +356,3 @@ def click_logo_and_validate_home(self):
359356 self .page .locator (self .LOGO_TITLE ).click ()
360357 self .page .wait_for_timeout (3000 )
361358 expect (self .page .locator (self .TITLE_TEXT )).to_be_visible ()
362-
0 commit comments