|
| 1 | +import os.path |
| 2 | + |
| 3 | +from base.base import BasePage |
| 4 | + |
| 5 | +from playwright.sync_api import expect |
| 6 | + |
| 7 | + |
| 8 | +class HomePage(BasePage): |
| 9 | + TITLE_TEXT = "//h1[normalize-space()='Modernize your code']" |
| 10 | + BROWSE_FILES = "//button[normalize-space()='Browse files']" |
| 11 | + SUCCESS_MSG = "//span[contains(text(),'All valid files uploaded successfully!')]" |
| 12 | + TRANSLATE_BTN = "//button[normalize-space()='Start translating']" |
| 13 | + BATCH_HISTORY = "//button[@aria-label='View batch history']" |
| 14 | + CLOSE_BATCH_HISTORY = "//button[@aria-label='Close panel']" |
| 15 | + BATCH_DETAILS = "//div[@class='batch-details']" |
| 16 | + DOWNLOAD_FILES = "//button[normalize-space()='Download all as .zip']" |
| 17 | + RETURN_HOME = "//button[normalize-space()='Return home']" |
| 18 | + SUMMARY = "//span[normalize-space()='Summary']" |
| 19 | + FILE_PROCESSED_MSG = "//span[normalize-space()='3 files processed successfully']" |
| 20 | + |
| 21 | + def __init__(self, page): |
| 22 | + self.page = page |
| 23 | + |
| 24 | + def validate_home_page(self): |
| 25 | + expect(self.page.locator(self.TITLE_TEXT)).to_be_visible() |
| 26 | + |
| 27 | + def upload_files(self): |
| 28 | + with self.page.expect_file_chooser() as fc_info: |
| 29 | + self.page.locator(self.BROWSE_FILES).click() |
| 30 | + self.page.wait_for_timeout(5000) |
| 31 | + self.page.wait_for_load_state("networkidle") |
| 32 | + file_chooser = fc_info.value |
| 33 | + current_working_dir = os.getcwd() |
| 34 | + file_path1 = os.path.join(current_working_dir, "testdata/q1_informix.sql") |
| 35 | + file_path2 = os.path.join(current_working_dir, "testdata/f1.sql") |
| 36 | + file_path3 = os.path.join(current_working_dir, "testdata/f2.sql") |
| 37 | + file_chooser.set_files([file_path1, file_path2, file_path3]) |
| 38 | + self.page.wait_for_timeout(10000) |
| 39 | + self.page.wait_for_load_state("networkidle") |
| 40 | + expect(self.page.locator(self.SUCCESS_MSG)).to_be_visible() |
| 41 | + |
| 42 | + def upload_unsupported_files(self): |
| 43 | + with self.page.expect_file_chooser() as fc_info: |
| 44 | + self.page.locator(self.BROWSE_FILES).click() |
| 45 | + self.page.wait_for_timeout(5000) |
| 46 | + self.page.wait_for_load_state("networkidle") |
| 47 | + file_chooser = fc_info.value |
| 48 | + current_working_dir = os.getcwd() |
| 49 | + file_path = os.path.join(current_working_dir, "testdata/invalid.py") |
| 50 | + file_chooser.set_files([file_path]) |
| 51 | + self.page.wait_for_timeout(4000) |
| 52 | + self.page.wait_for_load_state("networkidle") |
| 53 | + expect(self.page.locator(self.TRANSLATE_BTN)).to_be_disabled() |
| 54 | + |
| 55 | + def validate_translate(self): |
| 56 | + self.page.locator(self.TRANSLATE_BTN).click() |
| 57 | + expect(self.page.locator(self.DOWNLOAD_FILES)).to_be_enabled(timeout=200000) |
| 58 | + self.page.locator(self.SUMMARY).click() |
| 59 | + expect(self.page.locator(self.FILE_PROCESSED_MSG)).to_be_visible() |
| 60 | + self.page.wait_for_timeout(3000) |
| 61 | + |
| 62 | + def validate_batch_history(self): |
| 63 | + self.page.locator(self.BATCH_HISTORY).click() |
| 64 | + self.page.wait_for_timeout(3000) |
| 65 | + batch_details = self.page.locator(self.BATCH_DETAILS) |
| 66 | + for i in range(batch_details.count()): |
| 67 | + expect(batch_details.nth(i)).to_be_visible() |
| 68 | + self.page.locator(self.CLOSE_BATCH_HISTORY).click() |
| 69 | + |
| 70 | + def validate_download_files(self): |
| 71 | + self.page.locator(self.DOWNLOAD_FILES).click() |
| 72 | + self.page.wait_for_timeout(7000) |
| 73 | + self.page.locator(self.RETURN_HOME).click() |
| 74 | + self.page.wait_for_timeout(3000) |
| 75 | + expect(self.page.locator(self.TITLE_TEXT)).to_be_visible() |
0 commit comments