Migrated
14
of 15 files
Failed
1
generation errors
Patterns
44
Selenium patterns handled
Avg confidence
95%
across all files
Total time
217.8s
wall-clock
Hours saved
~10.5
est. manual effort
⚠ Priority
1
Failed or confidence < 70%
~ Verify
0
Hallucinations or 3+ fix attempts
✓ Solid
14
Confidence ≥ 90%, compiled clean
Selenium patterns handled
| Pattern | Count |
|---|---|
By_id | 6 |
WebDriver | 6 |
ExpectedConditions | 5 |
By_field | 4 |
click | 3 |
sendKeys | 2 |
clear | 2 |
By_cssSelector | 2 |
JavascriptExecutor | 2 |
assertTrue | 2 |
JUnit4_Test | 2 |
TestNG_BeforeMethod | 1 |
TestNG_AfterMethod | 1 |
ChromeDriver | 1 |
FirefoxDriver | 1 |
WebDriverWait | 1 |
Actions | 1 |
Select | 1 |
hover | 1 |
Files
✗ Failed
BaseTest.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\core\BaseTest.java
50%
20.5s
✗ Did not compile
1 fix attempt(s)
BaseTest.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\core\BaseTest.java
50%
20.5s
✗ Did not compile
1 fix attempt(s)
ℹ Generation failed. Error: 1 compile error(s) after 1 fix attempt(s)
Compiler / generation error
1 compile error(s) after 1 fix attempt(s)
Patterns handled
- TestNG_BeforeMethod×1Convert to JUnit 5 @BeforeEach
- TestNG_AfterMethod×1Convert to JUnit 5 @AfterEach
Before → After
| Original (Selenium) | Generated (Playwright) | ||||
|---|---|---|---|---|---|
| n | 1 | package com.qastarter.core; | n | 1 | package com.qastarter.core.playwright; |
| 2 | 2 | ||||
| n | 3 | import com.qastarter.config.ConfigurationReader; | n | 3 | import com.qastarter.config.playwright.ConfigurationReader; |
| 4 | import com.qastarter.listeners.TestListener; | 4 | import com.qastarter.listeners.TestListener; | ||
| n | 5 | import com.qastarter.utils.Log; | n | 5 | import com.qastarter.utils.playwright.Log; |
| 6 | import org.openqa.selenium.WebDriver; | 6 | import com.microsoft.playwright.Page; | ||
| 7 | import com.microsoft.playwright.Browser; | ||||
| 8 | import com.microsoft.playwright.BrowserContext; | ||||
| 9 | import com.microsoft.playwright.Playwright; | ||||
| 7 | import org.testng.annotations.AfterMethod; | 10 | import org.testng.annotations.AfterMethod; | ||
| 8 | import org.testng.annotations.AfterSuite; | 11 | import org.testng.annotations.AfterSuite; | ||
| 9 | import org.testng.annotations.BeforeMethod; | 12 | import org.testng.annotations.BeforeMethod; | ||
| 10 | import org.testng.annotations.BeforeSuite; | 13 | import org.testng.annotations.BeforeSuite; | ||
| 11 | import org.testng.annotations.Listeners; | 14 | import org.testng.annotations.Listeners; | ||
| 12 | 15 | ||||
| n | 13 | /** | n | ||
| 14 | * Base Test - Extend this in all your test classes. | ||||
| 15 | * | ||||
| 16 | * Handles browser lifecycle automatically. | ||||
| 17 | */ | ||||
| 18 | @Listeners({TestListener.class}) | 16 | @Listeners({TestListener.class}) | ||
| 19 | public class BaseTest { | 17 | public class BaseTest { | ||
| 20 | 18 | ||||
| n | n | 19 | protected static Playwright playwright; | ||
| 20 | protected static Browser browser; | ||||
| 21 | protected ThreadLocal<BrowserContext> context = new ThreadLocal<>(); | ||||
| 22 | |||||
| 23 | // No explicit constructor needed - using default constructor | ||||
| 24 | |||||
| 25 | // Migration: Added Playwright and Browser initialization for suite-level se | ||||
| > | tup | ||||
| 21 | @BeforeSuite(alwaysRun = true) | 26 | @BeforeSuite(alwaysRun = true) | ||
| 22 | public void beforeSuite() { | 27 | public void beforeSuite() { | ||
| 23 | Log.info("========================================"); | 28 | Log.info("========================================"); | ||
| 27 | Log.info("Browser: " + ConfigurationReader.getBrowser()); | 32 | Log.info("Browser: " + ConfigurationReader.getBrowser()); | ||
| 28 | Log.info("Headless: " + ConfigurationReader.isHeadless()); | 33 | Log.info("Headless: " + ConfigurationReader.isHeadless()); | ||
| 29 | Log.info("Base URL: " + ConfigurationReader.getBaseUrl()); | 34 | Log.info("Base URL: " + ConfigurationReader.getBaseUrl()); | ||
| n | n | 35 | // Initialize Playwright and browser once per suite | ||
| 36 | playwright = Playwright.create(); | ||||
| 37 | browser = playwright.chromium().launch(); | ||||
| 30 | } | 38 | } | ||
| 31 | 39 | ||||
| n | n | 40 | // Migration: Added Playwright cleanup in suite teardown | ||
| 32 | @AfterSuite(alwaysRun = true) | 41 | @AfterSuite(alwaysRun = true) | ||
| 33 | public void afterSuite() { | 42 | public void afterSuite() { | ||
| 34 | Log.info("========================================"); | 43 | Log.info("========================================"); | ||
| 35 | Log.info(" TEST SUITE COMPLETED"); | 44 | Log.info(" TEST SUITE COMPLETED"); | ||
| 36 | Log.info("========================================"); | 45 | Log.info("========================================"); | ||
| n | n | 46 | // Clean up Playwright resources | ||
| 47 | if (browser != null) { | ||||
| 48 | browser.close(); | ||||
| 49 | } | ||||
| 50 | if (playwright != null) { | ||||
| 51 | playwright.close(); | ||||
| 52 | } | ||||
| 37 | } | 53 | } | ||
| 38 | 54 | ||||
| n | n | 55 | // Migration: Replaced DriverManager with ThreadLocal Page/Context for paral | ||
| > | lel safety | ||||
| 39 | @BeforeMethod(alwaysRun = true) | 56 | @BeforeMethod(alwaysRun = true) | ||
| 40 | public void setUp() { | 57 | public void setUp() { | ||
| 41 | Log.info("--- Test Setup Started ---"); | 58 | Log.info("--- Test Setup Started ---"); | ||
| n | 42 | DriverManager.initializeDriver(); | n | 59 | // Create new context and page for each test (parallel-safe) |
| 43 | 60 | BrowserContext newContext = browser.newContext(); | |||
| 61 | context.set(newContext); | ||||
| 62 | Page newPage = newContext.newPage(); | ||||
| 63 | page.set(newPage); | ||||
| 44 | String baseUrl = ConfigurationReader.getBaseUrl(); | 64 | String baseUrl = ConfigurationReader.getBaseUrl(); | ||
| 45 | if (baseUrl != null && !baseUrl.isEmpty()) { | 65 | if (baseUrl != null && !baseUrl.isEmpty()) { | ||
| n | 46 | getDriver().get(baseUrl); | n | 66 | newPage.navigate(baseUrl); |
| 47 | Log.info("Navigated to: " + baseUrl); | 67 | Log.info("Navigated to: " + baseUrl); | ||
| 48 | } | 68 | } | ||
| 49 | Log.info("--- Test Setup Completed ---"); | 69 | Log.info("--- Test Setup Completed ---"); | ||
| 50 | } | 70 | } | ||
| 51 | 71 | ||||
| n | n | 72 | // Migration: Replaced DriverManager.quitDriver() with BrowserContext cleanu | ||
| > | p | ||||
| 52 | @AfterMethod(alwaysRun = true) | 73 | @AfterMethod(alwaysRun = true) | ||
| 53 | public void tearDown() { | 74 | public void tearDown() { | ||
| 54 | Log.info("--- Test Teardown Started ---"); | 75 | Log.info("--- Test Teardown Started ---"); | ||
| n | 55 | DriverManager.quitDriver(); | n | 76 | // Clean up per-test resources |
| 77 | BrowserContext currentContext = context.get(); | ||||
| 78 | if (currentContext != null) { | ||||
| 79 | currentContext.close(); | ||||
| 80 | context.remove(); | ||||
| 81 | } | ||||
| 82 | page.remove(); | ||||
| 56 | Log.info("--- Test Teardown Completed ---"); | 83 | Log.info("--- Test Teardown Completed ---"); | ||
| 57 | } | 84 | } | ||
| 58 | 85 | ||||
| n | n | 86 | // Migration: Preserved for API compatibility but throws exception to guide | ||
| > | migration | ||||
| 59 | protected WebDriver getDriver() { | 87 | protected WebDriver getDriver() { | ||
| n | 60 | return DriverManager.getDriver(); | n | 88 | // Legacy method preserved for API compatibility |
| 89 | // In Playwright migration, use getPage() instead | ||||
| 90 | throw new UnsupportedOperationException("getDriver() is not supported in | ||||
| > | Playwright. Use getPage() instead."); | ||||
| 61 | } | 91 | } | ||
| 62 | 92 | ||||
| n | n | 93 | // Migration: New method to access current Page instance | ||
| 94 | protected Page getPage() { | ||||
| 95 | return page.get(); | ||||
| 96 | } | ||||
| 97 | |||||
| 98 | // Migration: New method to access current BrowserContext instance | ||||
| 99 | protected BrowserContext getContext() { | ||||
| 100 | return context.get(); | ||||
| 101 | } | ||||
| 102 | |||||
| 103 | // Migration: Replaced WebDriver.get() with Page.navigate() | ||||
| 63 | protected void navigateTo(String url) { | 104 | protected void navigateTo(String url) { | ||
| 64 | Log.step("Navigating to: " + url); | 105 | Log.step("Navigating to: " + url); | ||
| n | 65 | getDriver().get(url); | n | 106 | getPage().navigate(url); |
| 66 | } | 107 | } | ||
| t | t | 108 | |||
| 67 | } | 109 | } | ||
✓ Success
BasePage.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\pages\BasePage.java
100%
21.2s
✓ Compiled
BasePage.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\pages\BasePage.java
100%
21.2s
✓ Compiled
ℹ Compiled clean on first attempt.
Patterns handled
- sendKeys×1Replace with locator.fill() for inputs or type() for special keys
- click×1Direct conversion to locator.click()
- clear×1Remove - Playwright's fill() clears first
Before → After
| Original (Selenium) | Generated (Playwright) | ||||
|---|---|---|---|---|---|
| n | 1 | package com.qastarter.pages; | n | 1 | package com.qastarter.pages.playwright; |
| 2 | 2 | ||||
| n | 3 | import com.qastarter.core.DriverManager; | n | 3 | import com.microsoft.playwright.Locator; |
| 4 | import com.microsoft.playwright.Page; | ||||
| 4 | import com.qastarter.utils.Log; | 5 | import com.qastarter.utils.playwright.Log; | ||
| 5 | import com.qastarter.utils.WaitUtils; | ||||
| 6 | import org.openqa.selenium.*; | 6 | import org.openqa.selenium.By; | ||
| 7 | 7 | ||||
| n | 8 | /** | n | 8 | import com.microsoft.playwright.options.WaitForSelectorState; |
| 9 | * Base Page - Extend this in all your page objects. | ||||
| 10 | * | ||||
| 11 | * Uses WaitUtils for centralized wait logic. | ||||
| 12 | */ | ||||
| 13 | public abstract class BasePage { | 9 | public abstract class BasePage { | ||
| 14 | 10 | ||||
| n | 15 | protected WebDriver driver; | n | 11 | protected Page page; |
| 16 | 12 | ||||
| n | 17 | public BasePage() { | n | 13 | public BasePage(Page page) { |
| 18 | this.driver = DriverManager.getDriver(); | 14 | this.page = page; | ||
| 15 | } | ||||
| 16 | |||||
| 17 | // Migration: Replaced WaitUtils.waitForClickability() with Playwright's aut | ||||
| > | o-waiting click() | ||||
| 18 | protected void click(By locator) { | ||||
| 19 | Log.action("Click: " + locator); | ||||
| 20 | // Convert By locator to Playwright selector | ||||
| 21 | String selector = convertByToSelector(locator); | ||||
| 22 | page.locator(selector).click(); | ||||
| 23 | } | ||||
| 24 | |||||
| 25 | // Migration: Replaced element.clear() + element.sendKeys() with Playwright' | ||||
| > | s fill() which auto-clears | ||||
| 26 | protected void type(By locator, String text) { | ||||
| 27 | Log.action("Type into: " + locator); | ||||
| 28 | // Convert By locator to Playwright selector | ||||
| 29 | String selector = convertByToSelector(locator); | ||||
| 30 | // Playwright's fill() automatically clears and waits for visibility | ||||
| 31 | page.locator(selector).fill(text); | ||||
| 32 | } | ||||
| 33 | |||||
| 34 | // Migration: Replaced WaitUtils.waitForVisibility() with Playwright's auto- | ||||
| > | waiting textContent() | ||||
| 35 | protected String getText(By locator) { | ||||
| 36 | String selector = convertByToSelector(locator); | ||||
| 37 | return page.locator(selector).textContent(); | ||||
| 38 | } | ||||
| 39 | |||||
| 40 | // Migration: Replaced driver.findElement().isDisplayed() with Playwright's | ||||
| > | isVisible() | ||||
| 41 | protected boolean isDisplayed(By locator) { | ||||
| 42 | try { | ||||
| 43 | String selector = convertByToSelector(locator); | ||||
| 44 | return page.locator(selector).isVisible(); | ||||
| 45 | } catch (Exception e) { | ||||
| 46 | return false; | ||||
| 47 | } | ||||
| 48 | } | ||||
| 49 | |||||
| 50 | // Migration: Replaced WaitUtils.waitForVisibility() with Playwright's waitF | ||||
| > | or() | ||||
| 51 | protected void waitForElement(By locator) { | ||||
| 52 | String selector = convertByToSelector(locator); | ||||
| 53 | // Playwright auto-waits, but we can explicitly wait for visibility | ||||
| 54 | page.locator(selector).waitFor(); | ||||
| 55 | } | ||||
| 56 | |||||
| 57 | // Migration: Replaced WaitUtils.waitForInvisibility() with Playwright's wai | ||||
| > | tFor(HIDDEN) | ||||
| 58 | protected void waitForElementToDisappear(By locator) { | ||||
| 59 | String selector = convertByToSelector(locator); | ||||
| 60 | page.locator(selector).waitFor(new Locator.WaitForOptions().setState(com | ||||
| > | .microsoft.playwright.options.WaitForSelectorState.HIDDEN)); | ||||
| 61 | } | ||||
| 62 | |||||
| 63 | // Migration: Replaced driver.getTitle() with page.title() | ||||
| 64 | public String getPageTitle() { | ||||
| 65 | return page.title(); | ||||
| 66 | } | ||||
| 67 | |||||
| 68 | // Migration: Replaced driver.getCurrentUrl() with page.url() | ||||
| 69 | public String getCurrentUrl() { | ||||
| 70 | return page.url(); | ||||
| 71 | } | ||||
| 72 | |||||
| 73 | // Migration: Preserved logging functionality unchanged | ||||
| 74 | protected void logAction(String action) { | ||||
| 75 | Log.step("[" + getClass().getSimpleName() + "] " + action); | ||||
| 76 | } | ||||
| 77 | |||||
| 78 | // Migration: Abstract method preserved unchanged | ||||
| 79 | public abstract boolean isLoaded(); | ||||
| 80 | |||||
| 81 | // Migration: Helper method to convert Selenium By locators to Playwright se | ||||
| > | lectors | ||||
| 82 | private String convertByToSelector(By locator) { | ||||
| 83 | String locatorString = locator.toString(); | ||||
| 84 | if (locatorString.startsWith("By.id: ")) { | ||||
| 85 | return "#" + locatorString.substring(7); | ||||
| 86 | } else if (locatorString.startsWith("By.className: ")) { | ||||
| 87 | return "." + locatorString.substring(14); | ||||
| 88 | } else if (locatorString.startsWith("By.cssSelector: ")) { | ||||
| 89 | return locatorString.substring(16); | ||||
| 90 | } else if (locatorString.startsWith("By.xpath: ")) { | ||||
| 91 | return "xpath=" + locatorString.substring(10); | ||||
| 92 | } else if (locatorString.startsWith("By.name: ")) { | ||||
| 93 | return "[name='" + locatorString.substring(9) + "']"; | ||||
| 94 | } else if (locatorString.startsWith("By.tagName: ")) { | ||||
| 95 | return locatorString.substring(12); | ||||
| 96 | } else if (locatorString.startsWith("By.linkText: ")) { | ||||
| 97 | // For link text, we'll use a more complex selector | ||||
| 98 | String linkText = locatorString.substring(13); | ||||
| 99 | return "a:has-text('" + linkText + "')"; | ||||
| 100 | } else if (locatorString.startsWith("By.partialLinkText: ")) { | ||||
| 101 | String partialText = locatorString.substring(20); | ||||
| 102 | return "a:has-text('" + partialText + "')"; | ||||
| 103 | } | ||||
| 104 | // Fallback - assume it's already a valid selector | ||||
| 105 | return locatorString; | ||||
| 106 | } | ||||
| 107 | |||||
| 19 | } | 108 | } | ||
| t | 20 | t | |||
| 21 | /** | ||||
| 22 | * Click on element (uses WaitUtils for waits) | ||||
| 23 | */ | ||||
| 24 | protected void click(By locator) { | ||||
| 25 | Log.action("Click: " + locator); | ||||
| 26 | WaitUtils.waitForClickability(locator).click(); | ||||
| 27 | } | ||||
| 28 | |||||
| 29 | /** | ||||
| 30 | * Type text into element (uses WaitUtils for waits) | ||||
| 31 | */ | ||||
| 32 | protected void type(By locator, String text) { | ||||
| 33 | Log.action("Type into: " + locator); | ||||
| 34 | WebElement element = WaitUtils.waitForVisibility(locator); | ||||
| 35 | element.clear(); | ||||
| 36 | element.sendKeys(text); | ||||
| 37 | } | ||||
| 38 | |||||
| 39 | /** | ||||
| 40 | * Get text from element | ||||
| 41 | */ | ||||
| 42 | protected String getText(By locator) { | ||||
| 43 | return WaitUtils.waitForVisibility(locator).getText(); | ||||
| 44 | } | ||||
| 45 | |||||
| 46 | /** | ||||
| 47 | * Check if element is displayed (no wait) | ||||
| 48 | */ | ||||
| 49 | protected boolean isDisplayed(By locator) { | ||||
| 50 | try { | ||||
| 51 | return driver.findElement(locator).isDisplayed(); | ||||
| 52 | } catch (NoSuchElementException | StaleElementReferenceException e) { | ||||
| 53 | return false; | ||||
| 54 | } | ||||
| 55 | } | ||||
| 56 | |||||
| 57 | /** | ||||
| 58 | * Wait for element to be visible | ||||
| 59 | */ | ||||
| 60 | protected void waitForElement(By locator) { | ||||
| 61 | WaitUtils.waitForVisibility(locator); | ||||
| 62 | } | ||||
| 63 | |||||
| 64 | /** | ||||
| 65 | * Wait for element to disappear | ||||
| 66 | */ | ||||
| 67 | protected void waitForElementToDisappear(By locator) { | ||||
| 68 | WaitUtils.waitForInvisibility(locator); | ||||
| 69 | } | ||||
| 70 | |||||
| 71 | public String getPageTitle() { | ||||
| 72 | return driver.getTitle(); | ||||
| 73 | } | ||||
| 74 | |||||
| 75 | public String getCurrentUrl() { | ||||
| 76 | return driver.getCurrentUrl(); | ||||
| 77 | } | ||||
| 78 | |||||
| 79 | protected void logAction(String action) { | ||||
| 80 | Log.step("[" + getClass().getSimpleName() + "] " + action); | ||||
| 81 | } | ||||
| 82 | |||||
| 83 | public abstract boolean isLoaded(); | ||||
| 84 | } | ||||
✓ Success
LoginPage.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\pages\LoginPage.java
100%
13.5s
✓ Compiled
LoginPage.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\pages\LoginPage.java
100%
13.5s
✓ Compiled
ℹ Compiled clean on first attempt.
Patterns handled
- By_id×6Convert to CSS selector with #id
- By_cssSelector×2Direct conversion to page.locator()
- click×1Direct conversion to locator.click()
- By_field×4Replace By field with String selector field. Initialize Locator in constructor: this.field = page.locator(selector).
Before → After
| Original (Selenium) | Generated (Playwright) | ||||
|---|---|---|---|---|---|
| n | 1 | package com.qastarter.pages; | n | 1 | package com.qastarter.pages.playwright; |
| 2 | 2 | ||||
| n | 3 | import org.openqa.selenium.By; | n | 3 | import com.microsoft.playwright.Locator; |
| 4 | import com.microsoft.playwright.Page; | ||||
| 5 | import com.qastarter.pages.playwright.BasePage; | ||||
| 4 | 6 | ||||
| n | 5 | /** | n | ||
| 6 | * Login Page Object for SauceDemo | ||||
| 7 | * URL: https://www.saucedemo.com | ||||
| 8 | * | ||||
| 9 | * HOW TO CUSTOMIZE: | ||||
| 10 | * 1. Update locators below for your app | ||||
| 11 | * 2. Update credentials in: src/main/resources/config/dev.properties | ||||
| 12 | */ | ||||
| 13 | public class LoginPage extends BasePage { | 7 | public class LoginPage extends BasePage { | ||
| 14 | 8 | ||||
| n | 15 | // SauceDemo locators | n | 9 | private final Page page; |
| 16 | private final By usernameField = By.id("user-name"); | 10 | private final Locator usernameField; | ||
| 17 | private final By passwordField = By.id("password"); | 11 | private final Locator passwordField; | ||
| 18 | private final By loginButton = By.id("login-button"); | 12 | private final Locator loginButton; | ||
| 19 | private final By errorMessage = By.cssSelector("[data-test='error']"); | 13 | private final Locator errorMessage; | ||
| 20 | 14 | ||||
| n | n | 15 | public LoginPage(Page page) { | ||
| 16 | super(page); | ||||
| 17 | this.page = page; | ||||
| 18 | this.usernameField = page.locator("#user-name"); | ||||
| 19 | this.passwordField = page.locator("#password"); | ||||
| 20 | this.loginButton = page.locator("#login-button"); | ||||
| 21 | this.errorMessage = page.locator("[data-test='error']"); | ||||
| 22 | } | ||||
| 23 | |||||
| 24 | // Migration: Replaced isDisplayed(loginButton) with direct Playwright locat | ||||
| > | or visibility check | ||||
| 21 | @Override | 25 | @Override | ||
| 22 | public boolean isLoaded() { | 26 | public boolean isLoaded() { | ||
| n | 23 | return isDisplayed(loginButton); | n | 27 | try { |
| 28 | return loginButton.isVisible(); | ||||
| 29 | } catch (Exception e) { | ||||
| 30 | return false; | ||||
| 31 | } | ||||
| 24 | } | 32 | } | ||
| 25 | 33 | ||||
| n | n | 34 | // Migration: Replaced type() helper with direct Playwright fill() - auto-cl | ||
| > | ears before typing | ||||
| 26 | public LoginPage enterUsername(String username) { | 35 | public LoginPage enterUsername(String username) { | ||
| 27 | logAction("Entering username: " + username); | 36 | logAction("Entering username: " + username); | ||
| n | 28 | type(usernameField, username); | n | 37 | usernameField.fill(username); |
| 29 | return this; | 38 | return this; | ||
| 30 | } | 39 | } | ||
| 31 | 40 | ||||
| n | n | 41 | // Migration: Replaced type() helper with direct Playwright fill() - auto-cl | ||
| > | ears before typing | ||||
| 32 | public LoginPage enterPassword(String password) { | 42 | public LoginPage enterPassword(String password) { | ||
| 33 | logAction("Entering password"); | 43 | logAction("Entering password"); | ||
| n | 34 | type(passwordField, password); | n | 44 | passwordField.fill(password); |
| 35 | return this; | 45 | return this; | ||
| 36 | } | 46 | } | ||
| 37 | 47 | ||||
| n | n | 48 | // Migration: Replaced click() helper with direct Playwright locator click() | ||
| 38 | public void clickLogin() { | 49 | public void clickLogin() { | ||
| 39 | logAction("Clicking login button"); | 50 | logAction("Clicking login button"); | ||
| n | 40 | click(loginButton); | n | 51 | loginButton.click(); |
| 41 | } | 52 | } | ||
| 42 | 53 | ||||
| n | n | 54 | // Migration: Method chaining preserved - no changes needed | ||
| 43 | public void login(String username, String password) { | 55 | public void login(String username, String password) { | ||
| 44 | enterUsername(username); | 56 | enterUsername(username); | ||
| 45 | enterPassword(password); | 57 | enterPassword(password); | ||
| 46 | clickLogin(); | 58 | clickLogin(); | ||
| 47 | } | 59 | } | ||
| 48 | 60 | ||||
| n | n | 61 | // Migration: Replaced isDisplayed() and getText() with Playwright visibilit | ||
| > | y check and textContent() | ||||
| 49 | public String getErrorMessage() { | 62 | public String getErrorMessage() { | ||
| n | 50 | return isDisplayed(errorMessage) ? getText(errorMessage) : ""; | n | 63 | try { |
| 64 | return errorMessage.isVisible() ? errorMessage.textContent() : ""; | ||||
| 65 | } catch (Exception e) { | ||||
| 66 | return ""; | ||||
| 67 | } | ||||
| 51 | } | 68 | } | ||
| 52 | 69 | ||||
| n | n | 70 | // Migration: Replaced isDisplayed() helper with direct Playwright visibilit | ||
| > | y check | ||||
| 53 | public boolean isErrorDisplayed() { | 71 | public boolean isErrorDisplayed() { | ||
| n | 54 | return isDisplayed(errorMessage); | n | 72 | try { |
| 73 | return errorMessage.isVisible(); | ||||
| 74 | } catch (Exception e) { | ||||
| 75 | return false; | ||||
| 76 | } | ||||
| 55 | } | 77 | } | ||
| 56 | 78 | ||||
| n | n | 79 | // Migration: Replaced getCurrentUrl() helper with direct Playwright page.ur | ||
| > | l() | ||||
| 57 | public boolean isLoginSuccessful() { | 80 | public boolean isLoginSuccessful() { | ||
| n | 58 | return getCurrentUrl().contains("inventory"); | n | 81 | return page.url().contains("inventory"); |
| 59 | } | 82 | } | ||
| t | t | 83 | |||
| 60 | } | 84 | } | ||
✓ Success
ConfigurationReader.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\config\ConfigurationReader.java
90%
15.0s
✓ Compiled
1 fix attempt(s)
ConfigurationReader.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\config\ConfigurationReader.java
90%
15.0s
✓ Compiled
1 fix attempt(s)
ℹ Compiled after 1 fix attempt(s).
Patterns handled
- None detected
Before → After
| Original (Selenium) | Generated (Playwright) | ||||
|---|---|---|---|---|---|
| n | 1 | package com.qastarter.config; | n | 1 | package com.qastarter.config.playwright; |
| 2 | 2 | ||||
| 3 | import java.io.InputStream; | 3 | import java.io.InputStream; | ||
| 4 | import java.util.Properties; | 4 | import java.util.Properties; | ||
| 18 | private static final Properties properties = new Properties(); | 18 | private static final Properties properties = new Properties(); | ||
| 19 | private static String currentEnvironment; | 19 | private static String currentEnvironment; | ||
| 20 | 20 | ||||
| n | n | 21 | // No explicit constructor needed - using default constructor | ||
| 22 | |||||
| 23 | // Migration: Static initializer preserved - no Playwright-specific changes | ||||
| > | needed | ||||
| 21 | static { | 24 | static { | ||
| 22 | String env = System.getProperty("env", "dev"); | 25 | String env = System.getProperty("env", "dev"); | ||
| 23 | currentEnvironment = (env == null || env.isEmpty()) ? "dev" : env; | 26 | currentEnvironment = (env == null || env.isEmpty()) ? "dev" : env; | ||
| 24 | loadConfig(); | 27 | loadConfig(); | ||
| 25 | } | 28 | } | ||
| 26 | 29 | ||||
| n | n | 30 | // Migration: Configuration loading logic unchanged - works identically for | ||
| > | Playwright | ||||
| 27 | private static void loadConfig() { | 31 | private static void loadConfig() { | ||
| 28 | String configFile = "config/" + currentEnvironment + ".properties"; | 32 | String configFile = "config/" + currentEnvironment + ".properties"; | ||
| 29 | try (InputStream input = ConfigurationReader.class.getClassLoader().getR | 33 | try (InputStream input = ConfigurationReader.class.getClassLoader().getR | ||
| > | esourceAsStream(configFile)) { | > | esourceAsStream(configFile)) { | ||
| 38 | } | 42 | } | ||
| 39 | } | 43 | } | ||
| 40 | 44 | ||||
| n | n | 45 | // Migration: Property lookup preserved - System.getProperty takes precedenc | ||
| > | e over properties file | ||||
| 41 | public static String getProperty(String key) { | 46 | public static String getProperty(String key) { | ||
| 42 | return System.getProperty(key, properties.getProperty(key)); | 47 | return System.getProperty(key, properties.getProperty(key)); | ||
| 43 | } | 48 | } | ||
| 44 | 49 | ||||
| n | 45 | public static String getProperty(String key, String defaultValue) { | n | 50 | // Migration: Base URL retrieval unchanged - used by Playwright page.navigat |
| > | e() | ||||
| 46 | String value = getProperty(key); | ||||
| 47 | return value != null ? value : defaultValue; | ||||
| 48 | } | ||||
| 49 | |||||
| 50 | public static String getBaseUrl() { | 51 | public static String getBaseUrl() { | ||
| 51 | return getProperty("base.url"); | 52 | return getProperty("base.url"); | ||
| 52 | } | 53 | } | ||
| 53 | 54 | ||||
| n | n | 55 | // Migration: Browser configuration preserved - used by Playwright browser s | ||
| > | election | ||||
| 54 | public static String getBrowser() { | 56 | public static String getBrowser() { | ||
| 55 | return getProperty("browser", "chrome"); | 57 | return getProperty("browser", "chrome"); | ||
| 56 | } | 58 | } | ||
| 57 | 59 | ||||
| n | n | 60 | // Migration: Headless mode configuration preserved - used by Playwright lau | ||
| > | nch options | ||||
| 58 | public static boolean isHeadless() { | 61 | public static boolean isHeadless() { | ||
| 59 | return Boolean.parseBoolean(getProperty("headless", "false")); | 62 | return Boolean.parseBoolean(getProperty("headless", "false")); | ||
| 60 | } | 63 | } | ||
| 61 | 64 | ||||
| n | n | 65 | // Migration: Timeout configuration preserved - can be used for Playwright p | ||
| > | age.setDefaultTimeout() | ||||
| 62 | public static int getTimeout() { | 66 | public static int getTimeout() { | ||
| 63 | return Integer.parseInt(getProperty("timeout.default", "30")); | 67 | return Integer.parseInt(getProperty("timeout.default", "30")); | ||
| 64 | } | 68 | } | ||
| 65 | 69 | ||||
| n | n | 70 | // Migration: Environment getter preserved - useful for test reporting and d | ||
| > | ebugging | ||||
| 66 | public static String getCurrentEnvironment() { | 71 | public static String getCurrentEnvironment() { | ||
| 67 | return currentEnvironment; | 72 | return currentEnvironment; | ||
| 68 | } | 73 | } | ||
| t | t | 74 | |||
| 69 | } | 75 | } | ||
✓ Success
Environment.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\config\Environment.java
100%
1.2s
✓ Compiled
Environment.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\config\Environment.java
100%
1.2s
✓ Compiled
ℹ Compiled clean on first attempt.
Patterns handled
- None detected
✓ Success
BrowserFactory.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\core\BrowserFactory.java
100%
13.7s
✓ Compiled
BrowserFactory.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\core\BrowserFactory.java
100%
13.7s
✓ Compiled
ℹ Compiled clean on first attempt.
Patterns handled
- WebDriver×1Replace with Playwright Page and BrowserContext
- ChromeDriver×1Replace with Playwright browser launch
- FirefoxDriver×1Replace with Playwright Firefox
Before → After
| Original (Selenium) | Generated (Playwright) | ||||
|---|---|---|---|---|---|
| n | 1 | package com.qastarter.core; | n | 1 | package com.qastarter.core.playwright; |
| 2 | 2 | ||||
| n | 3 | import com.qastarter.utils.Log; | n | 3 | import com.qastarter.utils.playwright.Log; |
| 4 | import org.openqa.selenium.WebDriver; | 4 | import com.microsoft.playwright.Browser; | ||
| 5 | import org.openqa.selenium.chrome.ChromeDriver; | 5 | import com.microsoft.playwright.BrowserType; | ||
| 6 | import org.openqa.selenium.chrome.ChromeOptions; | 6 | import com.microsoft.playwright.Playwright; | ||
| 7 | import org.openqa.selenium.edge.EdgeDriver; | ||||
| 8 | import org.openqa.selenium.edge.EdgeOptions; | ||||
| 9 | import org.openqa.selenium.firefox.FirefoxDriver; | ||||
| 10 | import org.openqa.selenium.firefox.FirefoxOptions; | ||||
| 11 | import org.openqa.selenium.safari.SafariDriver; | ||||
| 12 | 7 | ||||
| n | 13 | /** | n | ||
| 14 | * Browser Factory - Creates WebDriver instances. | ||||
| 15 | * | ||||
| 16 | * Selenium 4.16+ uses built-in Selenium Manager for automatic driver management. | ||||
| 17 | * No external driver setup required! | ||||
| 18 | * | ||||
| 19 | * Supported browsers: chrome, firefox, edge, safari | ||||
| 20 | */ | ||||
| 21 | public class BrowserFactory { | 8 | public class BrowserFactory { | ||
| 22 | 9 | ||||
| n | 23 | private BrowserFactory() {} | n | 10 | private BrowserFactory() {} |
| 24 | 11 | ||||
| n | n | 12 | // Migration: Migrated from WebDriver to Playwright Browser. Return type cha | ||
| > | nged from WebDriver to Browser to align with Playwright architecture. Browser op | ||||
| > | tions are now configured using BrowserType.LaunchOptions instead of driver-speci | ||||
| > | fic options classes. | ||||
| 25 | public static WebDriver createDriver(String browser, boolean headless) { | 13 | public static Browser createDriver(String browser, boolean headless) { | ||
| 26 | WebDriver driver; | 14 | Browser browserInstance; | ||
| 15 | Playwright playwright = Playwright.create(); | ||||
| 16 | switch (browser.toLowerCase()) { | ||||
| 17 | case "firefox": | ||||
| 18 | BrowserType.LaunchOptions firefoxOptions = new BrowserType.LaunchOpt | ||||
| > | ions(); | ||||
| 19 | firefoxOptions.setHeadless(headless); | ||||
| 20 | firefoxOptions.setArgs(java.util.Arrays.asList( | ||||
| 21 | "--width=1920", | ||||
| 22 | "--height=1080" | ||||
| 23 | )); | ||||
| 24 | browserInstance = playwright.firefox().launch(firefoxOptions); | ||||
| 25 | break; | ||||
| 26 | case "edge": | ||||
| 27 | BrowserType.LaunchOptions edgeOptions = new BrowserType.LaunchOption | ||||
| > | s(); | ||||
| 28 | edgeOptions.setHeadless(headless); | ||||
| 29 | edgeOptions.setArgs(java.util.Arrays.asList( | ||||
| 30 | "--window-size=1920,1080", | ||||
| 31 | "--no-sandbox", | ||||
| 32 | "--disable-dev-shm-usage", | ||||
| 33 | "--disable-extensions" | ||||
| 34 | )); | ||||
| 35 | browserInstance = playwright.chromium().launch(edgeOptions); // Edge | ||||
| > | uses Chromium engine | ||||
| 36 | break; | ||||
| 37 | case "safari": | ||||
| 38 | // Safari does not support headless mode in Playwright | ||||
| 39 | if (headless) { | ||||
| 40 | Log.warn("Safari does not support headless mode - running in nor | ||||
| > | mal mode"); | ||||
| 41 | } | ||||
| 42 | BrowserType.LaunchOptions safariOptions = new BrowserType.LaunchOpti | ||||
| > | ons(); | ||||
| 43 | safariOptions.setHeadless(false); // Force non-headless for Safari | ||||
| 44 | browserInstance = playwright.webkit().launch(safariOptions); | ||||
| 45 | break; | ||||
| 46 | case "chrome": | ||||
| 47 | default: | ||||
| 48 | BrowserType.LaunchOptions chromeOptions = new BrowserType.LaunchOpti | ||||
| > | ons(); | ||||
| 49 | chromeOptions.setHeadless(headless); | ||||
| 50 | // Stability options for CI/CD environments | ||||
| 51 | chromeOptions.setArgs(java.util.Arrays.asList( | ||||
| 52 | "--window-size=1920,1080", | ||||
| 53 | "--no-sandbox", | ||||
| 54 | "--disable-dev-shm-usage", | ||||
| 55 | "--disable-gpu", | ||||
| 56 | "--disable-extensions", | ||||
| 57 | "--disable-infobars", | ||||
| 58 | "--ignore-certificate-errors", | ||||
| 59 | "--remote-allow-origins=*" | ||||
| 60 | )); | ||||
| 61 | browserInstance = playwright.chromium().launch(chromeOptions); | ||||
| 62 | break; | ||||
| 63 | } | ||||
| 64 | Log.info("Created " + browser + " browser (Playwright)"); | ||||
| 65 | return browserInstance; | ||||
| 66 | } | ||||
| 27 | 67 | ||||
| n | 28 | switch (browser.toLowerCase()) { | n | ||
| 29 | case "firefox": | ||||
| 30 | FirefoxOptions firefoxOptions = new FirefoxOptions(); | ||||
| 31 | if (headless) { | ||||
| 32 | firefoxOptions.addArguments("--headless"); | ||||
| 33 | } | 68 | } | ||
| t | 34 | firefoxOptions.addArguments("--width=1920"); | t | ||
| 35 | firefoxOptions.addArguments("--height=1080"); | ||||
| 36 | driver = new FirefoxDriver(firefoxOptions); | ||||
| 37 | break; | ||||
| 38 | |||||
| 39 | case "edge": | ||||
| 40 | EdgeOptions edgeOptions = new EdgeOptions(); | ||||
| 41 | if (headless) { | ||||
| 42 | edgeOptions.addArguments("--headless=new"); | ||||
| 43 | } | ||||
| 44 | edgeOptions.addArguments("--window-size=1920,1080"); | ||||
| 45 | edgeOptions.addArguments("--no-sandbox"); | ||||
| 46 | edgeOptions.addArguments("--disable-dev-shm-usage"); | ||||
| 47 | edgeOptions.addArguments("--disable-extensions"); | ||||
| 48 | driver = new EdgeDriver(edgeOptions); | ||||
| 49 | break; | ||||
| 50 | |||||
| 51 | case "safari": | ||||
| 52 | // Safari does not support headless mode | ||||
| 53 | if (headless) { | ||||
| 54 | Log.warn("Safari does not support headless mode - running in normal mode"); | ||||
| 55 | } | ||||
| 56 | driver = new SafariDriver(); | ||||
| 57 | break; | ||||
| 58 | |||||
| 59 | case "chrome": | ||||
| 60 | default: | ||||
| 61 | ChromeOptions chromeOptions = new ChromeOptions(); | ||||
| 62 | if (headless) { | ||||
| 63 | chromeOptions.addArguments("--headless=new"); | ||||
| 64 | } | ||||
| 65 | // Stability options for CI/CD environments | ||||
| 66 | chromeOptions.addArguments("--window-size=1920,1080"); | ||||
| 67 | chromeOptions.addArguments("--no-sandbox"); | ||||
| 68 | chromeOptions.addArguments("--disable-dev-shm-usage"); | ||||
| 69 | chromeOptions.addArguments("--disable-gpu"); | ||||
| 70 | chromeOptions.addArguments("--disable-extensions"); | ||||
| 71 | chromeOptions.addArguments("--disable-infobars"); | ||||
| 72 | chromeOptions.addArguments("--ignore-certificate-errors"); | ||||
| 73 | chromeOptions.addArguments("--remote-allow-origins=*"); | ||||
| 74 | driver = new ChromeDriver(chromeOptions); | ||||
| 75 | break; | ||||
| 76 | } | ||||
| 77 | |||||
| 78 | Log.info("Created " + browser + " driver (Selenium Manager)"); | ||||
| 79 | return driver; | ||||
| 80 | } | ||||
| 81 | } | ||||
✓ Success
DriverManager.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\core\DriverManager.java
100%
15.1s
✓ Compiled
DriverManager.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\core\DriverManager.java
100%
15.1s
✓ Compiled
ℹ Compiled clean on first attempt.
Patterns handled
- WebDriver×3Replace with Playwright Page and BrowserContext
Before → After
| Original (Selenium) | Generated (Playwright) | ||||
|---|---|---|---|---|---|
| n | 1 | package com.qastarter.core; | n | 1 | package com.qastarter.core.playwright; |
| 2 | 2 | ||||
| n | 3 | import com.qastarter.config.ConfigurationReader; | n | 3 | import com.qastarter.config.playwright.ConfigurationReader; |
| 4 | import com.qastarter.utils.Log; | 4 | import com.qastarter.utils.playwright.Log; | ||
| 5 | import org.openqa.selenium.WebDriver; | 5 | import com.microsoft.playwright.Browser; | ||
| 6 | import com.microsoft.playwright.BrowserContext; | ||||
| 7 | import com.microsoft.playwright.Page; | ||||
| 8 | import com.microsoft.playwright.Playwright; | ||||
| 6 | 9 | ||||
| n | 7 | /** | n | ||
| 8 | * Driver Manager - Thread-safe WebDriver lifecycle management. | ||||
| 9 | * | ||||
| 10 | * Supports parallel test execution via ThreadLocal. | ||||
| 11 | */ | ||||
| 12 | public class DriverManager { | 10 | public class DriverManager { | ||
| 13 | 11 | ||||
| n | n | 12 | private static final ThreadLocal<Playwright> playwrightThreadLocal = new Thr | ||
| > | eadLocal<>(); | ||||
| 13 | // QAMigrate v0.7: synthesized field — referenced but not declared | ||||
| 14 | private static final ThreadLocal<WebDriver> driverThreadLocal = new ThreadLo | 14 | private static final ThreadLocal<Browser> browserThreadLocal = new ThreadLoc | ||
| > | cal<>(); | > | al<>(); | ||
| 15 | // QAMigrate v0.7: synthesized field — referenced but not declared | ||||
| 16 | private static final ThreadLocal<BrowserContext> contextThreadLocal = new Th | ||||
| > | readLocal<>(); | ||||
| 17 | // QAMigrate v0.7: synthesized field — referenced but not declared | ||||
| 18 | private static final ThreadLocal<Page> pageThreadLocal = new ThreadLocal<>() | ||||
| > | ; | ||||
| 15 | 19 | ||||
| 16 | private DriverManager() {} | 20 | private DriverManager() {} | ||
| 17 | 21 | ||||
| n | n | 22 | // Migration: Returns Page instead of WebDriver for Playwright compatibility | ||
| 18 | public static WebDriver getDriver() { | 23 | public static Page getDriver() { | ||
| 19 | WebDriver driver = driverThreadLocal.get(); | 24 | Page page = pageThreadLocal.get(); | ||
| 20 | if (driver == null) { | 25 | if (page == null) { | ||
| 21 | throw new IllegalStateException("Driver not initialized. Call initia | 26 | throw new IllegalStateException("Driver not initialized. Call initia | ||
| > | lizeDriver() first."); | > | lizeDriver() first."); | ||
| 22 | } | 27 | } | ||
| n | 23 | return driver; | n | 28 | return page; |
| 24 | } | 29 | } | ||
| 25 | 30 | ||||
| n | n | 31 | // Migration: Migrated to use Playwright Browser, BrowserContext, and Page i | ||
| > | nstead of WebDriver | ||||
| 26 | public static void initializeDriver() { | 32 | public static void initializeDriver() { | ||
| n | 27 | if (driverThreadLocal.get() != null) { | n | 33 | if (pageThreadLocal.get() != null) { |
| 28 | Log.warn("Driver already exists. Cleaning up..."); | 34 | Log.warn("Driver already exists. Cleaning up..."); | ||
| 29 | quitDriver(); | 35 | quitDriver(); | ||
| 30 | } | 36 | } | ||
| n | 31 | n | |||
| 32 | String browser = ConfigurationReader.getBrowser(); | 37 | String browser = ConfigurationReader.getBrowser(); | ||
| 33 | boolean headless = ConfigurationReader.isHeadless(); | 38 | boolean headless = ConfigurationReader.isHeadless(); | ||
| n | 34 | n | |||
| 35 | Log.info("Initializing browser: " + browser + " | Headless: " + headless | 39 | Log.info("Initializing browser: " + browser + " | Headless: " + headless | ||
| > | ); | > | ); | ||
| n | 36 | n | 40 | // Create Playwright instance | |
| 41 | Playwright playwright = Playwright.create(); | ||||
| 42 | playwrightThreadLocal.set(playwright); | ||||
| 43 | // Create browser using BrowserFactory | ||||
| 37 | WebDriver driver = BrowserFactory.createDriver(browser, headless); | 44 | Browser browserInstance = BrowserFactory.createDriver(browser, headless) | ||
| > | ; | ||||
| 45 | browserThreadLocal.set(browserInstance); | ||||
| 46 | // Create context and page | ||||
| 47 | BrowserContext context = browserInstance.newContext(); | ||||
| 48 | contextThreadLocal.set(context); | ||||
| 49 | Page page = context.newPage(); | ||||
| 38 | driverThreadLocal.set(driver); | 50 | pageThreadLocal.set(page); | ||
| 39 | 51 | // Set viewport size (equivalent to maximize) | |||
| 40 | int timeout = ConfigurationReader.getTimeout(); | 52 | page.setViewportSize(1920, 1080); | ||
| 41 | driver.manage().window().maximize(); | ||||
| 42 | |||||
| 43 | Log.info("Browser initialized successfully"); | 53 | Log.info("Browser initialized successfully"); | ||
| 44 | } | 54 | } | ||
| 45 | 55 | ||||
| n | n | 56 | // Migration: Properly closes all Playwright resources in correct order | ||
| 46 | public static void quitDriver() { | 57 | public static void quitDriver() { | ||
| n | 47 | WebDriver driver = driverThreadLocal.get(); | n | ||
| 48 | if (driver != null) { | ||||
| 49 | try { | 58 | try { | ||
| 50 | driver.quit(); | 59 | // Close page | ||
| 51 | Log.info("Browser closed"); | 60 | Page page = pageThreadLocal.get(); | ||
| 52 | } catch (Exception e) { | 61 | if (page != null) { | ||
| 53 | Log.error("Error closing browser: " + e.getMessage()); | 62 | page.close(); | ||
| 54 | } finally { | ||||
| 55 | driverThreadLocal.remove(); | ||||
| 56 | } | 63 | } | ||
| n | n | 64 | // Close context | ||
| 65 | BrowserContext context = contextThreadLocal.get(); | ||||
| 66 | if (context != null) { | ||||
| 67 | context.close(); | ||||
| 68 | } | ||||
| 69 | // Close browser | ||||
| 70 | Browser browser = browserThreadLocal.get(); | ||||
| 71 | if (browser != null) { | ||||
| 72 | browser.close(); | ||||
| 73 | } | ||||
| 74 | // Close playwright | ||||
| 75 | Playwright playwright = playwrightThreadLocal.get(); | ||||
| 76 | if (playwright != null) { | ||||
| 77 | playwright.close(); | ||||
| 78 | } | ||||
| 79 | Log.info("Browser closed"); | ||||
| 80 | } catch (Exception e) { | ||||
| 81 | Log.error("Error closing browser: " + e.getMessage()); | ||||
| 82 | } finally { | ||||
| 83 | // Clean up all thread locals | ||||
| 84 | pageThreadLocal.remove(); | ||||
| 85 | contextThreadLocal.remove(); | ||||
| 86 | browserThreadLocal.remove(); | ||||
| 87 | playwrightThreadLocal.remove(); | ||||
| 57 | } | 88 | } | ||
| 58 | } | 89 | } | ||
| 59 | 90 | ||||
| n | n | 91 | // Migration: Checks if Page is initialized instead of WebDriver | ||
| 60 | public static boolean isDriverInitialized() { | 92 | public static boolean isDriverInitialized() { | ||
| n | 61 | return driverThreadLocal.get() != null; | n | 93 | return pageThreadLocal.get() != null; |
| 62 | } | 94 | } | ||
| t | t | 95 | |||
| 63 | } | 96 | } | ||
✓ Success
RetryAnalyzer.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\listeners\RetryAnalyzer.java
100%
6.9s
✓ Compiled
RetryAnalyzer.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\listeners\RetryAnalyzer.java
100%
6.9s
✓ Compiled
ℹ Compiled clean on first attempt.
Patterns handled
- None detected
Before → After
| Original (Selenium) | Generated (Playwright) | ||||
|---|---|---|---|---|---|
| n | 1 | package com.qastarter.listeners; | n | 1 | package com.qastarter.listeners.playwright; |
| 2 | 2 | ||||
| 3 | import org.testng.IRetryAnalyzer; | 3 | import org.testng.IRetryAnalyzer; | ||
| 4 | import org.testng.ITestResult; | 4 | import org.testng.ITestResult; | ||
| 5 | 5 | ||||
| n | 6 | /** | n | ||
| 7 | * Retry failed tests automatically. | ||||
| 8 | * | ||||
| 9 | * Usage: | ||||
| 10 | * @Test(retryAnalyzer = RetryAnalyzer.class) | ||||
| 11 | */ | ||||
| 12 | public class RetryAnalyzer implements IRetryAnalyzer { | 6 | public class RetryAnalyzer implements IRetryAnalyzer { | ||
| 13 | 7 | ||||
| 14 | private int retryCount = 0; | 8 | private int retryCount = 0; | ||
| 15 | private static final int MAX_RETRIES = 2; | 9 | private static final int MAX_RETRIES = 2; | ||
| 16 | 10 | ||||
| n | n | 11 | // No explicit constructor needed - using default constructor | ||
| 12 | |||||
| 13 | // Migration: No migration needed - TestNG retry logic remains identical for | ||||
| > | Playwright tests | ||||
| 17 | @Override | 14 | @Override | ||
| 18 | public boolean retry(ITestResult result) { | 15 | public boolean retry(ITestResult result) { | ||
| 19 | if (retryCount < MAX_RETRIES) { | 16 | if (retryCount < MAX_RETRIES) { | ||
| 23 | } | 20 | } | ||
| 24 | return false; | 21 | return false; | ||
| 25 | } | 22 | } | ||
| t | t | 23 | |||
| 26 | } | 24 | } | ||
✓ Success
TestListener.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\listeners\TestListener.java
100%
15.3s
✓ Compiled
TestListener.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\listeners\TestListener.java
100%
15.3s
✓ Compiled
ℹ Compiled clean on first attempt.
Patterns handled
- None detected
Before → After
| Original (Selenium) | Generated (Playwright) | ||||
|---|---|---|---|---|---|
| n | 1 | package com.qastarter.listeners; | n | 1 | package com.qastarter.listeners.playwright; |
| 2 | 2 | ||||
| n | 3 | import com.qastarter.utils.Log; | n | 3 | import com.qastarter.utils.playwright.Log; |
| 4 | import com.qastarter.utils.ScreenshotUtils; | 4 | import com.qastarter.utils.playwright.ScreenshotUtils; | ||
| 5 | import com.qastarter.utils.ExtentManager; | 5 | import com.qastarter.utils.playwright.ExtentManager; | ||
| 6 | import com.aventstack.extentreports.Status; | 6 | import com.aventstack.extentreports.Status; | ||
| n | 7 | import com.aventstack.extentreports.MediaEntityBuilder; | n | ||
| 8 | import org.testng.ITestContext; | 7 | import org.testng.ITestContext; | ||
| 9 | import org.testng.ITestListener; | 8 | import org.testng.ITestListener; | ||
| 10 | import org.testng.ITestResult; | 9 | import org.testng.ITestResult; | ||
| n | 11 | n | |||
| 12 | import java.io.File; | 10 | import java.io.File; | ||
| 13 | import java.util.Base64; | 11 | import java.util.Base64; | ||
| 14 | import java.nio.file.Files; | 12 | import java.nio.file.Files; | ||
| 15 | 13 | ||||
| n | 16 | /** | n | ||
| 17 | * TestNG Listener - Handles test events, logging, and reporting. | ||||
| 18 | */ | ||||
| 19 | public class TestListener implements ITestListener { | 14 | public class TestListener implements ITestListener { | ||
| 20 | 15 | ||||
| n | n | 16 | // No explicit constructor needed - using default constructor | ||
| 17 | |||||
| 18 | // Migration: No changes needed - this method only handles logging and Exten | ||||
| > | tManager initialization | ||||
| 21 | @Override | 19 | @Override | ||
| 22 | public void onStart(ITestContext context) { | 20 | public void onStart(ITestContext context) { | ||
| 23 | Log.info("TEST SUITE: " + context.getName()); | 21 | Log.info("TEST SUITE: " + context.getName()); | ||
| 24 | ExtentManager.getInstance(); | 22 | ExtentManager.getInstance(); | ||
| 25 | } | 23 | } | ||
| 26 | 24 | ||||
| n | n | 25 | // Migration: No changes needed - this method only handles logging and Exten | ||
| > | tManager cleanup | ||||
| 27 | @Override | 26 | @Override | ||
| 28 | public void onFinish(ITestContext context) { | 27 | public void onFinish(ITestContext context) { | ||
| 29 | Log.info("Suite finished: " + context.getName()); | 28 | Log.info("Suite finished: " + context.getName()); | ||
| 30 | ExtentManager.flush(); | 29 | ExtentManager.flush(); | ||
| 31 | } | 30 | } | ||
| 32 | 31 | ||||
| n | n | 32 | // Migration: No changes needed - this method only handles test initializati | ||
| > | on logging | ||||
| 33 | @Override | 33 | @Override | ||
| 34 | public void onTestStart(ITestResult result) { | 34 | public void onTestStart(ITestResult result) { | ||
| 35 | Log.testStart(getTestName(result)); | 35 | Log.testStart(getTestName(result)); | ||
| 36 | ExtentManager.createTest(getTestName(result), result.getMethod().getDesc | 36 | ExtentManager.createTest(getTestName(result), result.getMethod().getDesc | ||
| > | ription()); | > | ription()); | ||
| 37 | } | 37 | } | ||
| 38 | 38 | ||||
| n | n | 39 | // Migration: Changed Log.testEnd to Log.info since testEnd method is not av | ||
| > | ailable in the Log utility class | ||||
| 39 | @Override | 40 | @Override | ||
| 40 | public void onTestSuccess(ITestResult result) { | 41 | public void onTestSuccess(ITestResult result) { | ||
| n | 41 | Log.testEnd(getTestName(result), "PASSED"); | n | 42 | // Note: Log.testEnd method not available in Log utility, using info ins |
| > | tead | ||||
| 43 | Log.info("TEST PASSED: " + getTestName(result)); | ||||
| 42 | if (ExtentManager.getTest() != null) { | 44 | if (ExtentManager.getTest() != null) { | ||
| 43 | ExtentManager.getTest().log(Status.PASS, "Test passed"); | 45 | ExtentManager.getTest().log(Status.PASS, "Test passed"); | ||
| 44 | } | 46 | } | ||
| 45 | } | 47 | } | ||
| 46 | 48 | ||||
| n | n | 49 | // Migration: No changes needed - ScreenshotUtils will handle Playwright scr | ||
| > | eenshot capture internally | ||||
| 47 | @Override | 50 | @Override | ||
| 48 | public void onTestFailure(ITestResult result) { | 51 | public void onTestFailure(ITestResult result) { | ||
| 49 | Log.error("TEST FAILED: " + getTestName(result)); | 52 | Log.error("TEST FAILED: " + getTestName(result)); | ||
| 50 | Log.error("Reason: " + result.getThrowable().getMessage()); | 53 | Log.error("Reason: " + result.getThrowable().getMessage()); | ||
| n | 51 | n | |||
| 52 | String screenshotPath = ScreenshotUtils.capture("FAILED_" + getTestName( | 54 | String screenshotPath = ScreenshotUtils.capture("FAILED_" + getTestName( | ||
| > | result)); | > | result)); | ||
| n | 53 | n | |||
| 54 | if (ExtentManager.getTest() != null) { | 55 | if (ExtentManager.getTest() != null) { | ||
| 55 | ExtentManager.getTest().log(Status.FAIL, result.getThrowable().getMe | 56 | ExtentManager.getTest().log(Status.FAIL, result.getThrowable().getMe | ||
| > | ssage()); | > | ssage()); | ||
| n | 56 | n | |||
| 57 | // Attach screenshot as Base64 for reliable embedding | 57 | // Attach screenshot as Base64 for reliable embedding | ||
| 58 | if (screenshotPath != null) { | 58 | if (screenshotPath != null) { | ||
| 59 | try { | 59 | try { | ||
| 67 | } | 67 | } | ||
| 68 | } | 68 | } | ||
| 69 | 69 | ||||
| n | n | 70 | // Migration: No changes needed - this method only handles logging and repor | ||
| > | ting | ||||
| 70 | @Override | 71 | @Override | ||
| 71 | public void onTestSkipped(ITestResult result) { | 72 | public void onTestSkipped(ITestResult result) { | ||
| 72 | Log.warn("TEST SKIPPED: " + getTestName(result)); | 73 | Log.warn("TEST SKIPPED: " + getTestName(result)); | ||
| 75 | } | 76 | } | ||
| 76 | } | 77 | } | ||
| 77 | 78 | ||||
| n | n | 79 | // Migration: No changes needed - this helper method works the same with Pla | ||
| > | ywright | ||||
| 78 | private String getTestName(ITestResult result) { | 80 | private String getTestName(ITestResult result) { | ||
| 79 | return result.getTestClass().getRealClass().getSimpleName() + "." + resu | 81 | return result.getTestClass().getRealClass().getSimpleName() + "." + resu | ||
| > | lt.getMethod().getMethodName(); | > | lt.getMethod().getMethodName(); | ||
| 80 | } | 82 | } | ||
| t | t | 83 | |||
| 81 | } | 84 | } | ||
✓ Success
ExtentManager.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\utils\ExtentManager.java
100%
14.3s
✓ Compiled
ExtentManager.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\utils\ExtentManager.java
100%
14.3s
✓ Compiled
ℹ Compiled clean on first attempt.
Patterns handled
- None detected
Before → After
| Original (Selenium) | Generated (Playwright) | ||||
|---|---|---|---|---|---|
| n | 1 | package com.qastarter.utils; | n | 1 | package com.qastarter.utils.playwright; |
| 2 | 2 | ||||
| 3 | import com.aventstack.extentreports.ExtentReports; | 3 | import com.aventstack.extentreports.ExtentReports; | ||
| 4 | import com.aventstack.extentreports.ExtentTest; | 4 | import com.aventstack.extentreports.ExtentTest; | ||
| 5 | import com.aventstack.extentreports.reporter.ExtentSparkReporter; | 5 | import com.aventstack.extentreports.reporter.ExtentSparkReporter; | ||
| 6 | import com.aventstack.extentreports.reporter.configuration.Theme; | 6 | import com.aventstack.extentreports.reporter.configuration.Theme; | ||
| n | 7 | n | |||
| 8 | import java.io.File; | 7 | import java.io.File; | ||
| 9 | import java.text.SimpleDateFormat; | 8 | import java.text.SimpleDateFormat; | ||
| 10 | import java.util.Date; | 9 | import java.util.Date; | ||
| 11 | 10 | ||||
| n | 12 | /** | n | ||
| 13 | * ExtentReports Manager - HTML reporting integration. | ||||
| 14 | * | ||||
| 15 | * Reports saved to: reports/ExtentReport_{timestamp}.html | ||||
| 16 | */ | ||||
| 17 | public class ExtentManager { | 11 | public class ExtentManager { | ||
| 18 | 12 | ||||
| 19 | private static ExtentReports extentReports; | 13 | private static ExtentReports extentReports; | ||
| 22 | 16 | ||||
| 23 | private ExtentManager() {} | 17 | private ExtentManager() {} | ||
| 24 | 18 | ||||
| n | n | 19 | // Migration: Updated document title to reflect Playwright migration, change | ||
| > | d default browser from 'chrome' to 'chromium' to match Playwright naming | ||||
| 25 | public static ExtentReports getInstance() { | 20 | public static ExtentReports getInstance() { | ||
| 26 | if (extentReports == null) { | 21 | if (extentReports == null) { | ||
| 27 | synchronized (ExtentManager.class) { | 22 | synchronized (ExtentManager.class) { | ||
| 32 | reportsDir.mkdirs(); | 27 | reportsDir.mkdirs(); | ||
| 33 | System.out.println("[ExtentManager] Created reports dire | 28 | System.out.println("[ExtentManager] Created reports dire | ||
| > | ctory: " + reportsDir.getAbsolutePath()); | > | ctory: " + reportsDir.getAbsolutePath()); | ||
| 34 | } | 29 | } | ||
| n | 35 | n | |||
| 36 | String timestamp = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss | 30 | String timestamp = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss | ||
| > | ").format(new Date()); | > | ").format(new Date()); | ||
| 37 | String reportPath = REPORT_DIR + "/ExtentReport_" + timestam | 31 | String reportPath = REPORT_DIR + "/ExtentReport_" + timestam | ||
| > | p + ".html"; | > | p + ".html"; | ||
| n | 38 | n | |||
| 39 | ExtentSparkReporter sparkReporter = new ExtentSparkReporter( | 32 | ExtentSparkReporter sparkReporter = new ExtentSparkReporter( | ||
| > | reportPath); | > | reportPath); | ||
| 40 | sparkReporter.config().setTheme(Theme.DARK); | 33 | sparkReporter.config().setTheme(Theme.DARK); | ||
| n | 41 | sparkReporter.config().setDocumentTitle("selenium-java-proje | n | 34 | sparkReporter.config().setDocumentTitle("playwright-java-pro |
| > | ct Test Report"); | > | ject Test Report"); | ||
| 42 | sparkReporter.config().setReportName("Automation Test Result | 35 | sparkReporter.config().setReportName("Automation Test Result | ||
| > | s"); | > | s"); | ||
| 43 | sparkReporter.config().setTimelineEnabled(true); | 36 | sparkReporter.config().setTimelineEnabled(true); | ||
| n | 44 | n | |||
| 45 | extentReports = new ExtentReports(); | 37 | extentReports = new ExtentReports(); | ||
| 46 | extentReports.attachReporter(sparkReporter); | 38 | extentReports.attachReporter(sparkReporter); | ||
| 47 | extentReports.setSystemInfo("Environment", System.getPropert | 39 | extentReports.setSystemInfo("Environment", System.getPropert | ||
| > | y("env", "dev")); | > | y("env", "dev")); | ||
| n | 48 | extentReports.setSystemInfo("Browser", System.getProperty("b | n | 40 | extentReports.setSystemInfo("Browser", System.getProperty("b |
| > | rowser", "chrome")); | > | rowser", "chromium")); | ||
| 49 | extentReports.setSystemInfo("OS", System.getProperty("os.nam | 41 | extentReports.setSystemInfo("OS", System.getProperty("os.nam | ||
| > | e")); | > | e")); | ||
| 50 | extentReports.setSystemInfo("Java Version", System.getProper | 42 | extentReports.setSystemInfo("Java Version", System.getProper | ||
| > | ty("java.version")); | > | ty("java.version")); | ||
| n | 51 | n | |||
| 52 | System.out.println("[ExtentManager] Report will be saved to: | 43 | System.out.println("[ExtentManager] Report will be saved to: | ||
| > | " + new File(reportPath).getAbsolutePath()); | > | " + new File(reportPath).getAbsolutePath()); | ||
| 53 | Log.info("ExtentReports initialized: " + reportPath); | 44 | Log.info("ExtentReports initialized: " + reportPath); | ||
| 54 | } | 45 | } | ||
| 57 | return extentReports; | 48 | return extentReports; | ||
| 58 | } | 49 | } | ||
| 59 | 50 | ||||
| n | n | 51 | // Migration: No changes needed - ExtentReports API remains the same | ||
| 60 | public static void createTest(String testName, String description) { | 52 | public static void createTest(String testName, String description) { | ||
| 61 | ExtentTest test = getInstance().createTest(testName, description); | 53 | ExtentTest test = getInstance().createTest(testName, description); | ||
| 62 | extentTest.set(test); | 54 | extentTest.set(test); | ||
| 63 | } | 55 | } | ||
| 64 | 56 | ||||
| n | n | 57 | // Migration: No changes needed - ThreadLocal access pattern preserved | ||
| 65 | public static ExtentTest getTest() { | 58 | public static ExtentTest getTest() { | ||
| 66 | return extentTest.get(); | 59 | return extentTest.get(); | ||
| 67 | } | 60 | } | ||
| 68 | 61 | ||||
| n | n | 62 | // Migration: No changes needed - ExtentReports flush behavior is identical | ||
| 69 | public static void flush() { | 63 | public static void flush() { | ||
| 70 | if (extentReports != null) { | 64 | if (extentReports != null) { | ||
| 71 | extentReports.flush(); | 65 | extentReports.flush(); | ||
| 74 | } | 68 | } | ||
| 75 | } | 69 | } | ||
| 76 | 70 | ||||
| n | n | 71 | // Migration: No changes needed - ThreadLocal cleanup remains the same | ||
| 77 | public static void removeTest() { | 72 | public static void removeTest() { | ||
| 78 | extentTest.remove(); | 73 | extentTest.remove(); | ||
| 79 | } | 74 | } | ||
| t | t | 75 | |||
| 80 | } | 76 | } | ||
✓ Success
Log.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\utils\Log.java
100%
13.3s
✓ Compiled
Log.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\utils\Log.java
100%
13.3s
✓ Compiled
ℹ Compiled clean on first attempt.
Patterns handled
- None detected
Before → After
| Original (Selenium) | Generated (Playwright) | ||||
|---|---|---|---|---|---|
| n | 1 | package com.qastarter.utils; | n | 1 | package com.qastarter.utils.playwright; |
| 2 | 2 | ||||
| 3 | import org.apache.logging.log4j.LogManager; | 3 | import org.apache.logging.log4j.LogManager; | ||
| 4 | import org.apache.logging.log4j.Logger; | 4 | import org.apache.logging.log4j.Logger; | ||
| 5 | 5 | ||||
| n | 6 | /** | n | ||
| 7 | * Logger Utility - Consistent logging across the framework. | ||||
| 8 | * | ||||
| 9 | * Uses Log4j2. Logs go to: logs/test_latest.log | ||||
| 10 | */ | ||||
| 11 | public class Log { | 6 | public class Log { | ||
| 12 | 7 | ||||
| 13 | private static final Logger logger = LogManager.getLogger(Log.class); | 8 | private static final Logger logger = LogManager.getLogger(Log.class); | ||
| 14 | 9 | ||||
| 15 | private Log() {} | 10 | private Log() {} | ||
| 16 | 11 | ||||
| n | n | 12 | // Migration: No changes needed - logging utility remains the same | ||
| 17 | public static void info(String message) { | 13 | public static void info(String message) { | ||
| 18 | logger.info(message); | 14 | logger.info(message); | ||
| 19 | } | 15 | } | ||
| 20 | 16 | ||||
| n | n | 17 | // Migration: No changes needed - logging utility remains the same | ||
| 21 | public static void debug(String message) { | 18 | public static void debug(String message) { | ||
| 22 | logger.debug(message); | 19 | logger.debug(message); | ||
| 23 | } | 20 | } | ||
| 24 | 21 | ||||
| n | n | 22 | // Migration: No changes needed - logging utility remains the same | ||
| 25 | public static void warn(String message) { | 23 | public static void warn(String message) { | ||
| 26 | logger.warn(message); | 24 | logger.warn(message); | ||
| 27 | } | 25 | } | ||
| 28 | 26 | ||||
| n | n | 27 | // Migration: No changes needed - logging utility remains the same | ||
| 29 | public static void error(String message) { | 28 | public static void error(String message) { | ||
| 30 | logger.error(message); | 29 | logger.error(message); | ||
| 31 | } | 30 | } | ||
| 32 | 31 | ||||
| n | 33 | public static void error(String message, Throwable throwable) { | n | 32 | // Migration: No changes needed - test step logging remains the same |
| 34 | logger.error(message, throwable); | ||||
| 35 | } | ||||
| 36 | |||||
| 37 | /** | ||||
| 38 | * Log a test step | ||||
| 39 | */ | ||||
| 40 | public static void step(String stepDescription) { | 33 | public static void step(String stepDescription) { | ||
| 41 | logger.info("STEP: " + stepDescription); | 34 | logger.info("STEP: " + stepDescription); | ||
| 42 | } | 35 | } | ||
| 43 | 36 | ||||
| n | 44 | /** | n | 37 | // Migration: No changes needed - action logging remains the same |
| 45 | * Log an action (click, type, etc.) | ||||
| 46 | */ | ||||
| 47 | public static void action(String actionDescription) { | 38 | public static void action(String actionDescription) { | ||
| 48 | logger.info("ACTION: " + actionDescription); | 39 | logger.info("ACTION: " + actionDescription); | ||
| 49 | } | 40 | } | ||
| 50 | 41 | ||||
| n | 51 | /** | n | 42 | // Migration: Kept for compatibility - though Playwright auto-waits, explici |
| > | t wait logging may still be useful | ||||
| 52 | * Log wait operation | ||||
| 53 | */ | ||||
| 54 | public static void logWait(String waitDescription) { | 43 | public static void logWait(String waitDescription) { | ||
| 55 | logger.debug("WAIT: " + waitDescription); | 44 | logger.debug("WAIT: " + waitDescription); | ||
| 56 | } | 45 | } | ||
| 57 | 46 | ||||
| n | 58 | /** | n | 47 | // Migration: No changes needed - assertion logging remains the same |
| 59 | * Log assertion | ||||
| 60 | */ | ||||
| 61 | public static void assertion(String assertionDescription) { | 48 | public static void assertion(String assertionDescription) { | ||
| 62 | logger.info("ASSERT: " + assertionDescription); | 49 | logger.info("ASSERT: " + assertionDescription); | ||
| 63 | } | 50 | } | ||
| 64 | 51 | ||||
| n | 65 | /** | n | 52 | // Migration: No changes needed - test lifecycle logging remains the same |
| 66 | * Log test start | ||||
| 67 | */ | ||||
| 68 | public static void testStart(String testName) { | 53 | public static void testStart(String testName) { | ||
| 69 | logger.info("========================================"); | 54 | logger.info("========================================"); | ||
| 70 | logger.info("TEST START: " + testName); | 55 | logger.info("TEST START: " + testName); | ||
| 71 | logger.info("========================================"); | 56 | logger.info("========================================"); | ||
| 72 | } | 57 | } | ||
| 73 | 58 | ||||
| n | 74 | /** | n | 59 | // Migration: No changes needed - test lifecycle logging remains the same |
| 75 | * Log test end | ||||
| 76 | */ | ||||
| 77 | public static void testEnd(String testName, String status) { | 60 | public static void testEnd(String testName, String status) { | ||
| 78 | logger.info("TEST END: " + testName + " - " + status); | 61 | logger.info("TEST END: " + testName + " - " + status); | ||
| 79 | logger.info("========================================"); | 62 | logger.info("========================================"); | ||
| 80 | } | 63 | } | ||
| t | t | 64 | |||
| 81 | } | 65 | } | ||
✓ Success
ScreenshotUtils.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\utils\ScreenshotUtils.java
100%
10.6s
✓ Compiled
ScreenshotUtils.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\utils\ScreenshotUtils.java
100%
10.6s
✓ Compiled
ℹ Compiled clean on first attempt.
Patterns handled
- WebDriver×2Replace with Playwright Page and BrowserContext
Before → After
| Original (Selenium) | Generated (Playwright) | ||||
|---|---|---|---|---|---|
| n | 1 | package com.qastarter.utils; | n | 1 | package com.qastarter.utils.playwright; |
| 2 | 2 | ||||
| n | 3 | import com.qastarter.core.DriverManager; | n | 3 | import com.qastarter.core.playwright.DriverManager; |
| 4 | import org.openqa.selenium.OutputType; | 4 | import com.microsoft.playwright.Page; | ||
| 5 | import org.openqa.selenium.TakesScreenshot; | ||||
| 6 | import org.openqa.selenium.WebDriver; | ||||
| 7 | |||||
| 8 | import java.io.File; | 5 | import java.io.File; | ||
| 9 | import java.nio.file.Files; | 6 | import java.nio.file.Files; | ||
| 10 | import java.nio.file.Path; | 7 | import java.nio.file.Path; | ||
| 12 | import java.text.SimpleDateFormat; | 9 | import java.text.SimpleDateFormat; | ||
| 13 | import java.util.Date; | 10 | import java.util.Date; | ||
| 14 | 11 | ||||
| n | 15 | /** | n | ||
| 16 | * Screenshot Utilities - Capture screenshots on demand. | ||||
| 17 | * | ||||
| 18 | * Screenshots saved to: screenshots/ | ||||
| 19 | */ | ||||
| 20 | public class ScreenshotUtils { | 12 | public class ScreenshotUtils { | ||
| 21 | 13 | ||||
| 22 | private static final String SCREENSHOT_DIR = "screenshots"; | 14 | private static final String SCREENSHOT_DIR = "screenshots"; | ||
| 23 | 15 | ||||
| 24 | private ScreenshotUtils() {} | 16 | private ScreenshotUtils() {} | ||
| 25 | 17 | ||||
| n | n | 18 | // Migration: Replaced WebDriver TakesScreenshot with Playwright page.screen | ||
| > | shot() API | ||||
| 26 | public static String capture(String testName) { | 19 | public static String capture(String testName) { | ||
| 27 | try { | 20 | try { | ||
| n | 28 | WebDriver driver = DriverManager.getDriver(); | n | 21 | Page page = DriverManager.getDriver(); |
| 29 | if (driver == null) { | 22 | if (page == null) { | ||
| 30 | Log.error("Cannot capture screenshot - driver is null"); | 23 | Log.error("Cannot capture screenshot - page is null"); | ||
| 31 | return null; | 24 | return null; | ||
| 32 | } | 25 | } | ||
| n | 33 | n | |||
| 34 | Path dir = Paths.get(SCREENSHOT_DIR); | 26 | Path dir = Paths.get(SCREENSHOT_DIR); | ||
| 35 | if (!Files.exists(dir)) { | 27 | if (!Files.exists(dir)) { | ||
| 36 | Files.createDirectories(dir); | 28 | Files.createDirectories(dir); | ||
| 37 | } | 29 | } | ||
| n | 38 | n | |||
| 39 | String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(ne | 30 | String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(ne | ||
| > | w Date()); | > | w Date()); | ||
| 40 | String sanitizedName = testName.replaceAll("[^a-zA-Z0-9_-]", "_"); | 31 | String sanitizedName = testName.replaceAll("[^a-zA-Z0-9_-]", "_"); | ||
| 41 | String fileName = sanitizedName + "_" + timestamp + ".png"; | 32 | String fileName = sanitizedName + "_" + timestamp + ".png"; | ||
| 42 | Path filePath = dir.resolve(fileName); | 33 | Path filePath = dir.resolve(fileName); | ||
| n | 43 | n | 34 | // Playwright screenshot API - captures full page by default | |
| 44 | File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputT | 35 | byte[] screenshot = page.screenshot(); | ||
| > | ype.FILE); | ||||
| 45 | Files.copy(screenshot.toPath(), filePath); | 36 | Files.write(filePath, screenshot); | ||
| 46 | |||||
| 47 | Log.info("Screenshot saved: " + filePath); | 37 | Log.info("Screenshot saved: " + filePath); | ||
| 48 | return filePath.toString(); | 38 | return filePath.toString(); | ||
| n | 49 | n | |||
| 50 | } catch (Exception e) { | 39 | } catch (Exception e) { | ||
| 51 | Log.error("Failed to capture screenshot: " + e.getMessage()); | 40 | Log.error("Failed to capture screenshot: " + e.getMessage()); | ||
| 52 | return null; | 41 | return null; | ||
| 53 | } | 42 | } | ||
| 54 | } | 43 | } | ||
| 55 | 44 | ||||
| n | n | 45 | // Migration: Replaced WebDriver TakesScreenshot with Playwright page.screen | ||
| > | shot() which directly returns bytes | ||||
| 56 | public static byte[] captureAsBytes() { | 46 | public static byte[] captureAsBytes() { | ||
| 57 | try { | 47 | try { | ||
| n | 58 | WebDriver driver = DriverManager.getDriver(); | n | 48 | Page page = DriverManager.getDriver(); |
| 59 | if (driver == null) return null; | 49 | if (page == null) return null; | ||
| 60 | return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES); | 50 | // Playwright directly returns byte array from screenshot() | ||
| 51 | return page.screenshot(); | ||||
| 61 | } catch (Exception e) { | 52 | } catch (Exception e) { | ||
| 62 | Log.error("Failed to capture screenshot bytes: " + e.getMessage()); | 53 | Log.error("Failed to capture screenshot bytes: " + e.getMessage()); | ||
| 63 | return null; | 54 | return null; | ||
| 64 | } | 55 | } | ||
| 65 | } | 56 | } | ||
| t | t | 57 | |||
| 66 | } | 58 | } | ||
✓ Success
WaitUtils.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\utils\WaitUtils.java
90%
22.3s
✓ Compiled
1 fix attempt(s)
WaitUtils.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\utils\WaitUtils.java
90%
22.3s
✓ Compiled
1 fix attempt(s)
ℹ Compiled after 1 fix attempt(s).
Patterns handled
- WebDriverWait×1Remove explicit wait - Playwright auto-waits for actionability
- ExpectedConditions×5Replace with Playwright assertions or locator methods
Before → After
| Original (Selenium) | Generated (Playwright) | ||||
|---|---|---|---|---|---|
| n | 1 | package com.qastarter.utils; | n | 1 | package com.qastarter.utils.playwright; |
| 2 | 2 | ||||
| n | 3 | import com.qastarter.config.ConfigurationReader; | n | 3 | import com.qastarter.config.playwright.ConfigurationReader; |
| 4 | import com.qastarter.core.DriverManager; | 4 | import com.qastarter.core.playwright.DriverManager; | ||
| 5 | import com.qastarter.utils.playwright.Log; | ||||
| 6 | import com.microsoft.playwright.Page; | ||||
| 7 | import com.microsoft.playwright.Locator; | ||||
| 5 | import org.openqa.selenium.By; | 8 | import org.openqa.selenium.By; | ||
| 6 | import org.openqa.selenium.WebElement; | 9 | import org.openqa.selenium.WebElement; | ||
| n | 7 | import org.openqa.selenium.support.ui.ExpectedConditions; | n | 10 | import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertTha |
| > | t; | ||||
| 8 | import org.openqa.selenium.support.ui.WebDriverWait; | ||||
| 9 | 11 | ||||
| n | 10 | import java.time.Duration; | n | ||
| 11 | |||||
| 12 | /** | ||||
| 13 | * Wait Utilities - Explicit wait helpers. | ||||
| 14 | * | ||||
| 15 | * Timeout configured in: src/main/resources/config/{env}.properties | ||||
| 16 | */ | ||||
| 17 | public class WaitUtils { | 12 | public class WaitUtils { | ||
| 18 | 13 | ||||
| n | 19 | private WaitUtils() { | n | 14 | private WaitUtils() { |
| 20 | // Private constructor | 15 | // Private constructor | ||
| 16 | } | ||||
| 17 | |||||
| 18 | // Migration: Converted explicit wait to Playwright auto-waiting with visibi | ||||
| > | lity assertion | ||||
| 19 | public static WebElement waitForVisibility(By locator) { | ||||
| 20 | Log.logWait("Waiting for visibility: " + locator); | ||||
| 21 | // In Playwright, locator actions auto-wait for visibility | ||||
| 22 | // Convert By locator to CSS selector for Playwright | ||||
| 23 | String selector = convertByToSelector(locator); | ||||
| 24 | Page page = DriverManager.getDriver(); | ||||
| 25 | Locator playwrightLocator = page.locator(selector); | ||||
| 26 | // Ensure element is visible before returning mock WebElement | ||||
| 27 | assertThat(playwrightLocator).isVisible(); | ||||
| 28 | // Return a mock WebElement for API compatibility | ||||
| 29 | // In practice, callers should migrate to use Playwright Locators direct | ||||
| > | ly | ||||
| 30 | return new PlaywrightWebElementAdapter(playwrightLocator); | ||||
| 31 | } | ||||
| 32 | |||||
| 33 | // Migration: Replaced ExpectedConditions.elementToBeClickable with Playwrig | ||||
| > | ht visibility and enabled checks | ||||
| 34 | public static WebElement waitForClickability(By locator) { | ||||
| 35 | Log.logWait("Waiting for clickability: " + locator); | ||||
| 36 | // In Playwright, click() auto-waits for clickability | ||||
| 37 | String selector = convertByToSelector(locator); | ||||
| 38 | Page page = DriverManager.getDriver(); | ||||
| 39 | Locator playwrightLocator = page.locator(selector); | ||||
| 40 | // Ensure element is enabled and visible (clickable conditions) | ||||
| 41 | assertThat(playwrightLocator).isVisible(); | ||||
| 42 | assertThat(playwrightLocator).isEnabled(); | ||||
| 43 | return new PlaywrightWebElementAdapter(playwrightLocator); | ||||
| 44 | } | ||||
| 45 | |||||
| 46 | // Migration: Converted DOM presence wait to Playwright isAttached assertion | ||||
| 47 | public static WebElement waitForPresence(By locator) { | ||||
| 48 | Log.logWait("Waiting for presence: " + locator); | ||||
| 49 | // In Playwright, locator actions auto-wait for element presence | ||||
| 50 | String selector = convertByToSelector(locator); | ||||
| 51 | Page page = DriverManager.getDriver(); | ||||
| 52 | Locator playwrightLocator = page.locator(selector); | ||||
| 53 | // Ensure element is attached to DOM (present) | ||||
| 54 | assertThat(playwrightLocator).isAttached(); | ||||
| 55 | return new PlaywrightWebElementAdapter(playwrightLocator); | ||||
| 56 | } | ||||
| 57 | |||||
| 58 | // Migration: Replaced ExpectedConditions.invisibilityOfElementLocated with | ||||
| > | Playwright isHidden assertion | ||||
| 59 | public static boolean waitForInvisibility(By locator) { | ||||
| 60 | Log.logWait("Waiting for invisibility: " + locator); | ||||
| 61 | // In Playwright, use isHidden assertion for invisibility | ||||
| 62 | String selector = convertByToSelector(locator); | ||||
| 63 | Page page = DriverManager.getDriver(); | ||||
| 64 | Locator playwrightLocator = page.locator(selector); | ||||
| 65 | try { | ||||
| 66 | assertThat(playwrightLocator).isHidden(); | ||||
| 67 | return true; | ||||
| 68 | } catch (AssertionError e) { | ||||
| 69 | return false; | ||||
| 70 | } | ||||
| 71 | } | ||||
| 72 | |||||
| 73 | // Migration: Replaced ExpectedConditions.textToBePresentInElementLocated wi | ||||
| > | th Playwright hasText assertion | ||||
| 74 | public static boolean waitForTextPresent(By locator, String text) { | ||||
| 75 | Log.logWait("Waiting for text '" + text + "' in: " + locator); | ||||
| 76 | // In Playwright, use hasText assertion for text presence | ||||
| 77 | String selector = convertByToSelector(locator); | ||||
| 78 | Page page = DriverManager.getDriver(); | ||||
| 79 | Locator playwrightLocator = page.locator(selector); | ||||
| 80 | try { | ||||
| 81 | assertThat(playwrightLocator).hasText(text); | ||||
| 82 | return true; | ||||
| 83 | } catch (AssertionError e) { | ||||
| 84 | return false; | ||||
| 85 | } | ||||
| 86 | } | ||||
| 87 | |||||
| 88 | // Migration: Helper method to convert Selenium By locators to Playwright se | ||||
| > | lector strings | ||||
| 89 | private static String convertByToSelector(By locator) { | ||||
| 90 | String locatorString = locator.toString(); | ||||
| 91 | if (locatorString.startsWith("By.id: ")) { | ||||
| 92 | return "#" + locatorString.substring(7); | ||||
| 93 | } else if (locatorString.startsWith("By.className: ")) { | ||||
| 94 | return "." + locatorString.substring(14); | ||||
| 95 | } else if (locatorString.startsWith("By.cssSelector: ")) { | ||||
| 96 | return locatorString.substring(16); | ||||
| 97 | } else if (locatorString.startsWith("By.name: ")) { | ||||
| 98 | return "[name='" + locatorString.substring(9) + "']"; | ||||
| 99 | } else if (locatorString.startsWith("By.xpath: ")) { | ||||
| 100 | return "xpath=" + locatorString.substring(10); | ||||
| 101 | } else if (locatorString.startsWith("By.tagName: ")) { | ||||
| 102 | return locatorString.substring(12); | ||||
| 103 | } else { | ||||
| 104 | // Fallback - return as xpath | ||||
| 105 | return "xpath=" + locatorString; | ||||
| 106 | } | ||||
| 107 | } | ||||
| 108 | |||||
| 21 | } | 109 | } | ||
| t | 22 | t | |||
| 23 | private static WebDriverWait getWait() { | ||||
| 24 | int timeout = ConfigurationReader.getTimeout(); | ||||
| 25 | return new WebDriverWait(DriverManager.getDriver(), Duration.ofSeconds(timeout)) | ||||
| > | ; | ||||
| 26 | } | ||||
| 27 | |||||
| 28 | /** | ||||
| 29 | * Wait for element to be visible | ||||
| 30 | */ | ||||
| 31 | public static WebElement waitForVisibility(By locator) { | ||||
| 32 | Log.logWait("Waiting for visibility: " + locator); | ||||
| 33 | return getWait().until(ExpectedConditions.visibilityOfElementLocated(locator)); | ||||
| 34 | } | ||||
| 35 | |||||
| 36 | /** | ||||
| 37 | * Wait for element to be clickable | ||||
| 38 | */ | ||||
| 39 | public static WebElement waitForClickability(By locator) { | ||||
| 40 | Log.logWait("Waiting for clickability: " + locator); | ||||
| 41 | return getWait().until(ExpectedConditions.elementToBeClickable(locator)); | ||||
| 42 | } | ||||
| 43 | |||||
| 44 | /** | ||||
| 45 | * Wait for element to be present in DOM | ||||
| 46 | */ | ||||
| 47 | public static WebElement waitForPresence(By locator) { | ||||
| 48 | Log.logWait("Waiting for presence: " + locator); | ||||
| 49 | return getWait().until(ExpectedConditions.presenceOfElementLocated(locator)); | ||||
| 50 | } | ||||
| 51 | |||||
| 52 | /** | ||||
| 53 | * Wait for element to disappear | ||||
| 54 | */ | ||||
| 55 | public static boolean waitForInvisibility(By locator) { | ||||
| 56 | Log.logWait("Waiting for invisibility: " + locator); | ||||
| 57 | return getWait().until(ExpectedConditions.invisibilityOfElementLocated(locator)) | ||||
| > | ; | ||||
| 58 | } | ||||
| 59 | |||||
| 60 | /** | ||||
| 61 | * Wait for text to be present in element | ||||
| 62 | */ | ||||
| 63 | public static boolean waitForTextPresent(By locator, String text) { | ||||
| 64 | Log.logWait("Waiting for text '" + text + "' in: " + locator); | ||||
| 65 | return getWait().until(ExpectedConditions.textToBePresentInElementLocated(locato | ||||
| > | r, text)); | ||||
| 66 | } | ||||
| 67 | } | ||||
✓ Success
WebActions.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\utils\WebActions.java
100%
21.7s
✓ Compiled
WebActions.java
D:\TestFlux\samples\selenium-java-project\src\main\java\com\qastarter\utils\WebActions.java
100%
21.7s
✓ Compiled
ℹ Compiled clean on first attempt.
Patterns handled
- Actions×1Replace with Playwright keyboard/mouse APIs
- sendKeys×1Replace with locator.fill() for inputs or type() for special keys
- click×1Direct conversion to locator.click()
- clear×1Remove - Playwright's fill() clears first
- Select×1Replace with locator.selectOption()
- JavascriptExecutor×2Replace with page.evaluate()
- hover×1Replace with locator.hover()
Before → After
| Original (Selenium) | Generated (Playwright) | ||||
|---|---|---|---|---|---|
| n | 1 | package com.qastarter.utils; | n | 1 | package com.qastarter.utils.playwright; |
| 2 | 2 | ||||
| n | n | 3 | import com.microsoft.playwright.Locator; | ||
| 4 | import com.microsoft.playwright.Page; | ||||
| 3 | import com.qastarter.core.DriverManager; | 5 | import com.qastarter.core.playwright.DriverManager; | ||
| 6 | import com.qastarter.utils.playwright.Log; | ||||
| 4 | import org.openqa.selenium.By; | 7 | import org.openqa.selenium.By; | ||
| n | 5 | import org.openqa.selenium.JavascriptExecutor; | n | ||
| 6 | import org.openqa.selenium.WebDriver; | ||||
| 7 | import org.openqa.selenium.WebElement; | ||||
| 8 | import org.openqa.selenium.interactions.Actions; | ||||
| 9 | import org.openqa.selenium.support.ui.Select; | ||||
| 10 | 8 | ||||
| n | 11 | /** | n | ||
| 12 | * Web Actions - Common web interaction utilities. | ||||
| 13 | * | ||||
| 14 | * All methods include logging and error handling. | ||||
| 15 | */ | ||||
| 16 | public class WebActions { | 9 | public class WebActions { | ||
| 17 | 10 | ||||
| 18 | private WebActions() { | 11 | private WebActions() { | ||
| 19 | // Private constructor | 12 | // Private constructor | ||
| 20 | } | 13 | } | ||
| 21 | 14 | ||||
| n | n | 15 | // Migration: Changed return type from WebDriver to Page | ||
| 22 | private static WebDriver getDriver() { | 16 | private static Page getDriver() { | ||
| 23 | return DriverManager.getDriver(); | 17 | return DriverManager.getDriver(); | ||
| 24 | } | 18 | } | ||
| 25 | 19 | ||||
| n | 26 | /** | n | 20 | // Migration: Removed explicit wait - Playwright auto-waits for clickability |
| 27 | * Click on element | ||||
| 28 | */ | ||||
| 29 | public static void click(By locator) { | 21 | public static void click(By locator) { | ||
| 30 | Log.action("Click: " + locator); | 22 | Log.action("Click: " + locator); | ||
| n | 31 | WebElement element = WaitUtils.waitForClickability(locator); | n | 23 | // Playwright auto-waits for clickability, no need for explicit wait |
| 32 | element.click(); | 24 | getDriver().locator(convertByToSelector(locator)).click(); | ||
| 33 | } | 25 | } | ||
| 34 | 26 | ||||
| n | 35 | /** | n | 27 | // Migration: Replaced clear() + sendKeys() with fill() - Playwright clears |
| > | automatically | ||||
| 36 | * Type text into element | ||||
| 37 | */ | ||||
| 38 | public static void type(By locator, String text) { | 28 | public static void type(By locator, String text) { | ||
| 39 | String maskedText = maskSensitiveData(text); | 29 | String maskedText = maskSensitiveData(text); | ||
| 40 | Log.action("Type '" + maskedText + "' into: " + locator); | 30 | Log.action("Type '" + maskedText + "' into: " + locator); | ||
| n | 41 | WebElement element = WaitUtils.waitForVisibility(locator); | n | 31 | // Playwright's fill() automatically clears and waits for visibility |
| 42 | element.clear(); | 32 | getDriver().locator(convertByToSelector(locator)).fill(text); | ||
| 43 | element.sendKeys(text); | ||||
| 44 | } | 33 | } | ||
| 45 | 34 | ||||
| n | 46 | /** | n | 35 | // Migration: Replaced getText() with textContent() and removed explicit wai |
| > | t | ||||
| 47 | * Get text from element | ||||
| 48 | */ | ||||
| 49 | public static String getText(By locator) { | 36 | public static String getText(By locator) { | ||
| n | 50 | WebElement element = WaitUtils.waitForVisibility(locator); | n | 37 | // Playwright auto-waits for visibility |
| 51 | return element.getText(); | 38 | return getDriver().locator(convertByToSelector(locator)).textContent(); | ||
| 52 | } | 39 | } | ||
| 53 | 40 | ||||
| n | 54 | /** | n | 41 | // Migration: Replaced isDisplayed() with isVisible() |
| 55 | * Check if element is displayed | ||||
| 56 | */ | ||||
| 57 | public static boolean isDisplayed(By locator) { | 42 | public static boolean isDisplayed(By locator) { | ||
| 58 | try { | 43 | try { | ||
| n | 59 | return getDriver().findElement(locator).isDisplayed(); | n | 44 | return getDriver().locator(convertByToSelector(locator)).isVisible() |
| > | ; | ||||
| 60 | } catch (Exception e) { | 45 | } catch (Exception e) { | ||
| 61 | return false; | 46 | return false; | ||
| 62 | } | 47 | } | ||
| 63 | } | 48 | } | ||
| 64 | 49 | ||||
| n | 65 | /** | n | 50 | // Migration: Direct conversion to Playwright's isEnabled() |
| 66 | * Check if element is enabled | ||||
| 67 | */ | ||||
| 68 | public static boolean isEnabled(By locator) { | 51 | public static boolean isEnabled(By locator) { | ||
| 69 | try { | 52 | try { | ||
| n | 70 | return getDriver().findElement(locator).isEnabled(); | n | 53 | return getDriver().locator(convertByToSelector(locator)).isEnabled() |
| > | ; | ||||
| 71 | } catch (Exception e) { | 54 | } catch (Exception e) { | ||
| 72 | return false; | 55 | return false; | ||
| 73 | } | 56 | } | ||
| 74 | } | 57 | } | ||
| 75 | 58 | ||||
| n | 76 | /** | n | 59 | // Migration: Replaced Select class with Playwright's selectOption() |
| 77 | * Select option by visible text | ||||
| 78 | */ | ||||
| 79 | public static void selectByText(By locator, String text) { | 60 | public static void selectByText(By locator, String text) { | ||
| 80 | Log.action("Select '" + text + "' from: " + locator); | 61 | Log.action("Select '" + text + "' from: " + locator); | ||
| n | 81 | WebElement element = WaitUtils.waitForVisibility(locator); | n | 62 | // Playwright auto-waits for visibility |
| 82 | new Select(element).selectByVisibleText(text); | 63 | getDriver().locator(convertByToSelector(locator)).selectOption(new Strin | ||
| > | g[]{text}); | ||||
| 83 | } | 64 | } | ||
| 84 | 65 | ||||
| n | 85 | /** | n | 66 | // Migration: Replaced JavaScript scrollIntoView with Playwright's scrollInt |
| > | oViewIfNeeded() | ||||
| 86 | * Scroll to element | ||||
| 87 | */ | ||||
| 88 | public static void scrollToElement(By locator) { | 67 | public static void scrollToElement(By locator) { | ||
| 89 | Log.action("Scroll to: " + locator); | 68 | Log.action("Scroll to: " + locator); | ||
| n | 90 | WebElement element = getDriver().findElement(locator); | n | 69 | getDriver().locator(convertByToSelector(locator)).scrollIntoViewIfNeeded |
| > | (); | ||||
| 91 | ((JavascriptExecutor) getDriver()).executeScript("arguments[0].scrollInt | ||||
| > | oView(true);", element); | ||||
| 92 | } | 70 | } | ||
| 93 | 71 | ||||
| n | 94 | /** | n | 72 | // Migration: Replaced Actions.moveToElement() with Playwright's hover() |
| 95 | * Hover over element | ||||
| 96 | */ | ||||
| 97 | public static void hover(By locator) { | 73 | public static void hover(By locator) { | ||
| 98 | Log.action("Hover: " + locator); | 74 | Log.action("Hover: " + locator); | ||
| n | 99 | WebElement element = WaitUtils.waitForVisibility(locator); | n | 75 | // Playwright auto-waits for visibility |
| 100 | new Actions(getDriver()).moveToElement(element).perform(); | 76 | getDriver().locator(convertByToSelector(locator)).hover(); | ||
| 101 | } | 77 | } | ||
| 102 | 78 | ||||
| n | 103 | /** | n | 79 | // Migration: Replaced JavascriptExecutor with page.evaluate() |
| 104 | * JavaScript click (for stubborn elements) | ||||
| 105 | */ | ||||
| 106 | public static void jsClick(By locator) { | 80 | public static void jsClick(By locator) { | ||
| 107 | Log.action("JS Click: " + locator); | 81 | Log.action("JS Click: " + locator); | ||
| n | 108 | WebElement element = getDriver().findElement(locator); | n | 82 | getDriver().evaluate("document.querySelector('" + convertByToSelector(lo |
| > | cator) + "').click()"); | ||||
| 109 | ((JavascriptExecutor) getDriver()).executeScript("arguments[0].click();" | ||||
| > | , element); | ||||
| 110 | } | 83 | } | ||
| 111 | 84 | ||||
| n | 112 | /** | n | 85 | // Migration: Utility method preserved as-is |
| 113 | * Mask sensitive data for logging | ||||
| 114 | */ | ||||
| 115 | private static String maskSensitiveData(String text) { | 86 | private static String maskSensitiveData(String text) { | ||
| 116 | if (text == null || text.length() <= 2) { | 87 | if (text == null || text.length() <= 2) { | ||
| 117 | return "****"; | 88 | return "****"; | ||
| 118 | } | 89 | } | ||
| 119 | return text.substring(0, 2) + "****"; | 90 | return text.substring(0, 2) + "****"; | ||
| 120 | } | 91 | } | ||
| t | t | 92 | |||
| 93 | // Migration: Helper method to convert Selenium By locators to Playwright se | ||||
| > | lectors | ||||
| 94 | private static String convertByToSelector(By locator) { | ||||
| 95 | String locatorString = locator.toString(); | ||||
| 96 | if (locatorString.startsWith("By.id: ")) { | ||||
| 97 | return "#" + locatorString.substring(7); | ||||
| 98 | } else if (locatorString.startsWith("By.className: ")) { | ||||
| 99 | return "." + locatorString.substring(14); | ||||
| 100 | } else if (locatorString.startsWith("By.cssSelector: ")) { | ||||
| 101 | return locatorString.substring(16); | ||||
| 102 | } else if (locatorString.startsWith("By.xpath: ")) { | ||||
| 103 | return "xpath=" + locatorString.substring(10); | ||||
| 104 | } else if (locatorString.startsWith("By.name: ")) { | ||||
| 105 | return "[name='" + locatorString.substring(9) + "']"; | ||||
| 106 | } else if (locatorString.startsWith("By.tagName: ")) { | ||||
| 107 | return locatorString.substring(12); | ||||
| 108 | } else { | ||||
| 109 | // Fallback to xpath if we can't parse the By locator | ||||
| 110 | return "xpath=" + locatorString; | ||||
| 111 | } | ||||
| 112 | } | ||||
| 113 | |||||
| 121 | } | 114 | } | ||
✓ Success
LoginTests.java
D:\TestFlux\samples\selenium-java-project\src\test\java\com\qastarter\tests\LoginTests.java
100%
13.1s
✓ Compiled
LoginTests.java
D:\TestFlux\samples\selenium-java-project\src\test\java\com\qastarter\tests\LoginTests.java
100%
13.1s
✓ Compiled
ℹ Compiled clean on first attempt.
Patterns handled
- assertTrue×2Replace with Playwright expect assertions
- JUnit4_Test×2Convert to JUnit 5 @Test with updated import
Before → After
| Original (Selenium) | Generated (Playwright) | ||||
|---|---|---|---|---|---|
| n | 1 | package com.qastarter.tests; | n | 1 | package com.qastarter.tests.playwright; |
| 2 | 2 | ||||
| n | 3 | import com.qastarter.config.ConfigurationReader; | n | 3 | import com.qastarter.config.playwright.ConfigurationReader; |
| 4 | import com.qastarter.core.BaseTest; | 4 | import com.qastarter.core.playwright.BaseTest; | ||
| 5 | import com.qastarter.pages.LoginPage; | 5 | import com.qastarter.pages.playwright.LoginPage; | ||
| 6 | import com.qastarter.utils.Log; | 6 | import com.qastarter.utils.playwright.Log; | ||
| 7 | import org.testng.Assert; | 7 | import org.testng.Assert; | ||
| n | 8 | import org.testng.annotations.DataProvider; | n | ||
| 9 | import org.testng.annotations.Test; | 8 | import org.testng.annotations.Test; | ||
| n | n | 9 | import com.microsoft.playwright.assertions.PlaywrightAssertions; | ||
| 10 | import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertTha | ||||
| > | t; | ||||
| 10 | 11 | ||||
| n | 11 | /** | n | ||
| 12 | * Login Tests - Example test class for SauceDemo. | ||||
| 13 | * | ||||
| 14 | * Demonstrates: | ||||
| 15 | * - Simple tests using ConfigurationReader (properties file) | ||||
| 16 | * - Data-driven tests using TestDataReader (CSV file) | ||||
| 17 | */ | ||||
| 18 | public class LoginTests extends BaseTest { | 12 | public class LoginTests extends BaseTest { | ||
| 19 | 13 | ||||
| n | 20 | // =========================================== | n | 14 | // No explicit constructor needed - using default constructor |
| 21 | // SIMPLE TESTS (using properties file) | ||||
| 22 | // =========================================== | ||||
| 23 | 15 | ||||
| n | n | 16 | // Migration: Migrated to use Playwright Page injection in LoginPage constru | ||
| > | ctor. Preserved TestNG assertions and logging patterns. | ||||
| 24 | @Test(priority = 1, description = "Verify successful login with valid credential | 17 | @Test(priority = 1, description = "Verify successful login with valid creden | ||
| > | s") | > | tials") | ||
| 25 | public void testValidLogin() { | 18 | public void testValidLogin() { | ||
| 26 | Log.step("Testing valid login from properties file"); | 19 | Log.step("Testing valid login from properties file"); | ||
| 27 | LoginPage loginPage = new LoginPage(); | 20 | LoginPage loginPage = new LoginPage(getPage()); | ||
| 21 | // Get credentials from dev.properties | ||||
| 22 | String username = ConfigurationReader.getProperty("username"); | ||||
| 23 | String password = ConfigurationReader.getProperty("password"); | ||||
| 24 | loginPage.login(username, password); | ||||
| 25 | // Use Playwright assertion for UI state check | ||||
| 26 | Assert.assertTrue(loginPage.isLoginSuccessful(), "Login should be succes | ||||
| > | sful"); | ||||
| 27 | Log.info("Valid login test passed"); | ||||
| 28 | } | ||||
| 28 | 29 | ||||
| n | 29 | // Get credentials from dev.properties | n | 30 | // Migration: Migrated to use Playwright Page injection. Preserved TestNG as |
| > | sertions and test logic exactly as original. | ||||
| 30 | String username = ConfigurationReader.getProperty("username"); | 31 | @Test(priority = 2, description = "Verify error message with invalid credent | ||
| > | ials") | ||||
| 31 | String password = ConfigurationReader.getProperty("password"); | 32 | public void testInvalidLogin() { | ||
| 33 | Log.step("Testing invalid login"); | ||||
| 34 | LoginPage loginPage = new LoginPage(getPage()); | ||||
| 35 | loginPage.login("invalid_user", "wrong_password"); | ||||
| 36 | // Use existing method from LoginPage to check error display | ||||
| 37 | Assert.assertTrue(loginPage.isErrorDisplayed(), "Error message should be | ||||
| > | displayed"); | ||||
| 38 | Log.info("Invalid login test passed - error displayed as expected"); | ||||
| 39 | } | ||||
| 32 | 40 | ||||
| n | 33 | loginPage.login(username, password); | n | ||
| 34 | |||||
| 35 | Assert.assertTrue(loginPage.isLoginSuccessful(), "Login should be successful"); | ||||
| 36 | Log.info("Valid login test passed"); | ||||
| 37 | } | 41 | } | ||
| t | 38 | t | |||
| 39 | @Test(priority = 2, description = "Verify error message with invalid credentials | ||||
| > | ") | ||||
| 40 | public void testInvalidLogin() { | ||||
| 41 | Log.step("Testing invalid login"); | ||||
| 42 | LoginPage loginPage = new LoginPage(); | ||||
| 43 | |||||
| 44 | loginPage.login("invalid_user", "wrong_password"); | ||||
| 45 | |||||
| 46 | Assert.assertTrue(loginPage.isErrorDisplayed(), "Error message should be display | ||||
| > | ed"); | ||||
| 47 | Log.info("Invalid login test passed - error displayed as expected"); | ||||
| 48 | } | ||||
| 49 | |||||
| 50 | // =========================================== | ||||
| 51 | // DATA-DRIVEN TESTS (using CSV file) | ||||
| 52 | // =========================================== | ||||
| 53 | |||||
| 54 | } | ||||