What is POM? POM (Page Object Model) is a design pattern used in test automation mainly with Selenium. It helps you separate test logic from UI elements, making your code cleaner, reusable, and easier to maintain. Why we use POM • To avoid duplicate locators and messy test scripts. • To make updates easy if one element changes, you fix it in one place only. • To keep tests readable and maintainable. Different Ways to Implement POM 1. Without PageFactory (classic way) –using By locators and driver.findElement(). 2. With PageFactory – using @FindBy annotations for cleaner code. Example: Login Page (with PageFactory) import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.PageFactory; public class LoginPage { WebDriver driver; // Locators @FindBy(id = "username") WebElement usernameField; @FindBy(id = "password") WebElement passwordField; @FindBy(id = "loginBtn") WebElement loginButton; // Constructor public LoginPage(WebDriver driver) { this.driver = driver; PageFactory.initElements(driver, this); } // Actions public void login(String username, String password) { usernameField.sendKeys(username); passwordField.sendKeys(password); loginButton.click(); } } Usage in Test Class import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.Test; public class LoginTest { @Test public void verifyLogin() { WebDriver driver = new ChromeDriver(); driver.get("https://example.com/login"); LoginPage loginPage = new LoginPage(driver); loginPage.login("admin", "password123"); driver.quit(); } } Bottom line POM = Clean structure + Reusable locators + Easy maintenance. It’s the backbone of any good Selenium automation framework. #Selenium #POM #TestAutomation #SDET #Java
Mustafizur Rahaman’s Post
More Relevant Posts
-
🚀 Master the Page Object Model (POM) Framework in Selenium 🚀 If you want to make your Selenium automation framework clean, reusable, and easy to maintain, then Page Object Model (POM) is the design pattern you must understand! 💡 ✅ What is POM? Page Object Model (POM) is a design pattern where each web page of the application is represented as a separate class in the code. Each class contains: 🔹 The locators (WebElements) of that page 🔹 The methods (actions) that can be performed on those elements This makes your test scripts more readable and less prone to breaking when UI changes. ✅ Example: // LoginPage.java public class LoginPage { WebDriver driver; @FindBy(id="username") WebElement username; @FindBy(id="password") WebElement password; @FindBy(id="loginBtn") WebElement loginBtn; public LoginPage(WebDriver driver) { this.driver = driver; PageFactory.initElements(driver, this); } public void login(String user, String pass) { username.sendKeys(user); password.sendKeys(pass); loginBtn.click(); } } ✅ Benefits of Using POM: 🔹 Reusability – One class per page, used across multiple tests 🔹 Maintainability – UI changes require updates in one place only 🔹 Readability – Clean separation of test logic and page elements 🔹 Scalability – Easy integration with TestNG, Maven, and Jenkins ✅ Framework Structure Example: ProjectName │ ├── src/test/java │ ├── pages → Page classes (LoginPage, HomePage, etc.) │ ├── tests → Test scripts (LoginTest, DashboardTest) │ ├── utilities → Common functions, drivers, data readers │ ├── pom.xml └── testng.xml ✅ Pro Tip: Combine POM + TestNG + Maven + Extent Reports for a professional automation framework that fits perfectly into CI/CD pipelines! 💻 #Selenium #POM #PageObjectModel #AutomationTesting #SoftwareTesting #QA #TestAutomation #TestNG #Maven #FrameworkDesign #Java #Jenkins
To view or add a comment, sign in
-
Simplify Selenium Waits Using ExpectedConditions (Java) ``` WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("userName"))); element.sendKeys("JohnDoe"); ``` One of the most underrated skills in Selenium automation is mastering **explicit waits**. While newcomers rely on `Thread.sleep()` (which pauses execution blindly), seasoned engineers use `WebDriverWait` and `ExpectedConditions` for intelligent timing. In the above code, `ExpectedConditions.visibilityOfElementLocated()` ensures the element is both present in the DOM and visible on screen before performing any action. This approach reduces flaky tests and improves overall suite stability. A small but valuable enhancement in recent Selenium versions (Selenium 4+) is the shift from the old constructor `new WebDriverWait(WebDriver, long)` to the more readable `Duration` API. It’s a subtle syntax improvement, but it aligns Selenium better with modern Java practices. **Pro Tip:** Combine explicit waits with concise custom conditions using lambda expressions: ``` wait.until(driver -> driver.findElement(By.id("submitBtn")).isEnabled()); ``` This simple pattern allows more control and flexibility compared to pre-defined conditions. As automation engineers, we often chase advanced tools, but refining fundamentals like intelligent waiting strategies can make your suite significantly more reliable and cleaner. 💬 How do you handle sync issues in your Selenium tests? Share your approach below!
To view or add a comment, sign in
-
🚀 Selenium Cheatsheet – Part 1: WebDriver Basics 👩💻 What is Selenium WebDriver? Automate web apps like a real user — click, type, navigate, and test seamlessly. ⚙️ Quick Start: WebDriver driver = new ChromeDriver(); driver.get("https://example.com"); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); ✅ Open browser & navigate ✅ Maximize window ✅ Wait for elements 🌐 Browser Commands You’ll Use Daily: getTitle() → check page title getCurrentUrl() → verify navigation navigate().back()/forward()/refresh() → multi-page flows 🔍 Locators (Your Best Friend): ID, Name, Tag Name, Link Text, Partial Link Text, CSS Selector, XPath 💡 Tip: CSS = fast & stable; XPath = for complex structures ✍️ Interact with Elements: sendKeys() → type click() → click clear() → clear field 🧭 Dropdowns & Checkboxes: Use Select for dropdowns Always check isSelected() before clicking checkboxes 📸 Screenshots: Capture failures automatically → great for reports & debugging 💡 Why it Matters: Master these basics before diving into TestNG, Cucumber, or CI/CD pipelines. 🔜 Next in the Series: Waits, Alerts, Frames & Windows, TestNG, Actions & JS Executor #Selenium #AutomationTesting #WebDriver #Java #TestAutomation #SDET #QACommunity #QA #Cucumber #TestNG #Jenkins #CI_CD #SrividyaThirakala #SoftwareTesting #ManualToAutomation
To view or add a comment, sign in
-
Selenium synchronization wait statements🕒: One of the biggest challenges in Selenium automation is handling timing issues - Test script runs faster than the web elements load! 😅 That’s where Synchronization & Waits come to the rescue. A well-timed script = stable and reliable automation 🚀 💡 Why Synchronization Matters: Modern web apps use dynamic content (AJAX, JavaScript, API calls). Without proper waits, automation tests may fail not because of defects, but due to timing mismatches between script and browser response. ✅ Types of Waits in Selenium: 1️⃣ Implicit Wait: Applies globally to all elements. Selenium keeps polling until timeout. driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); 2️⃣ Explicit Wait: Waits for a specific condition or element. WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15)); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("username"))); 3️⃣ Fluent Wait: Customizable — you can define polling frequency and ignore exceptions. Wait<WebDriver> wait = new FluentWait<>(driver) .withTimeout(Duration.ofSeconds(20)) .pollingEvery(Duration.ofSeconds(2)) .ignoring(NoSuchElementException.class); ⚡ Useful Tips: 🔹 Don’t mix implicit and explicit waits — it may cause unpredictable delays. 🔹 Use ExpectedConditions smartly to avoid unnecessary waits. 🔹 Prefer Explicit/Fluent Waits for dynamic apps. A synchronized test suite is the secret to flaky-test-free automation! 💪 #Selenium #AutomationTesting #Synchronization #Waits #ImplicitWait #ExplicitWait #FluentWait #QATesting #SDET #Java #WebDriver #SoftwareTesting #AutomationEngineer
To view or add a comment, sign in
-
🌟 Day 13 of My 100 Days QA Challenge 🌟 Topic: Setting Up Selenium WebDriver – Step by Step 🧰 Getting your automation environment ready is the first real step toward writing tests. Here's how you can set up Selenium WebDriver in Java the right way: 🛠️ Step-by-Step Setup Guide 1. Add Selenium Dependency Use Maven/Gradle to include Selenium in your project. For Maven (pom.xml): <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.35.0</version> <!-- latest stable version as of now --> </dependency> You can check the current version at the Selenium Downloads page. Selenium 2. Manage WebDriver Binaries You need browser-specific drivers (ChromeDriver, GeckoDriver, etc.). Instead of manually downloading them, you can use WebDriverManager (Java library) to handle this for you automatically. import io.github.bonigarcia.wdm.WebDriverManager; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class WebDriverSetup { public static void main(String[] args) { WebDriverManager.chromedriver().setup(); // Automatically handles driver WebDriver driver = new ChromeDriver(); driver.get("https://example.com"); System.out.println("Title: " + driver.getTitle()); driver.quit(); } } Note: With newer Selenium releases, Selenium Manager is being integrated to manage drivers internally. Selenium+1 3. Launching Browser & Running a Test Create WebDriver instance (Chrome, Firefox, etc.) Configure options (window size, headless mode, timeouts) Use driver.get(url) to navigate Perform actions (click, sendKeys, etc.) Assert results Close driver with driver.quit() 4. Best Practices & Tips Always use the latest matching versions of Selenium & WebDriverManager Clean driver cache if version mismatches arise (especially when browser updates) Use explicit waits instead of Thread.sleep() Run tests headlessly in CI environments Organize your setup logic (e.g. in a Base class) for reuse 👉 Tomorrow’s post: Day 14 – Writing First Selenium Script #100DaysQAChallenge #Selenium #AutomationTesting #WebDriverSetup #Java #WebDriverManager #SeleniumManager #TestAutomation #QualityAssurance #SoftwareTesting #TestingJourney #QALearning #ManualToAutomation #TestingTools #TesterLife #CodingForQA
To view or add a comment, sign in
-
𝐀𝐮𝐭𝐨𝐦𝐚𝐭𝐢𝐨𝐧 𝐓𝐞𝐬𝐭𝐢𝐧𝐠 𝐈𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 👇 1) 𝗦𝗲𝗹𝗲𝗻𝗶𝘂𝗺 𝗕𝗮𝘀𝗶𝗰𝘀 1. What is Selenium? 2. Which component of Selenium is the most important? 3. Which browser supports Selenium? --xx--- 2) 𝗟𝗼𝗰𝗮𝘁𝗼𝗿𝘀 & 𝗫𝗣𝗮𝘁𝗵 4. Among all the given locators, which one is the fastest? 5. How many locators are there in Selenium? 6. How many types of XPath are there in Selenium? 7. Which type of XPath starts with a double forward slash (//)? 8. Which type of XPath starts with a single forward slash (/)? 9. Write the correct syntax for an absolute XPath. 10. Which XPath is used to search dissimilar nodes in an XML document from the current node? --xx--- 3) 𝗘𝗹𝗲𝗺𝗲𝗻𝘁 𝗛𝗮𝗻𝗱𝗹𝗶𝗻𝗴 11. When you only want to access a single element on a webpage, which method will you use? 12. Which class is used to handle drop-downs in Selenium? 13. If a method fails to find the element, which of the two methods throws an exception? --xx--- 4) 𝗪𝗶𝗻𝗱𝗼𝘄𝘀, 𝗪𝗮𝗶𝘁𝘀 & 𝗦𝗰𝗿𝗲𝗲𝗻𝘀𝗵𝗼𝘁𝘀 14. Which method allows you to switch control from one window to another? 15. Which exception is shown in Selenium when there is a delay in loading elements we want to interact with? 16. How many types of waits does Selenium WebDriver provide? 17. Which type of wait command waits for a certain amount of time before throwing an exception? 18. Which wait takes timeout and polling frequency as its parameters? 19. In Selenium 4, which method allows us to take a screenshot of a specific web element? --xx--- 5) 𝗧𝗲𝘀𝘁𝗡𝗚 20. How do you execute multiple test cases at a time in TestNG? 21. Which annotations are executed first in TestNG? --xx--- 6) 𝗙𝗿𝗮𝗺𝗲𝘄𝗼𝗿𝗸 & 𝗧𝗼𝗼𝗹𝘀 22. What is Page Object Model (POM)? 23. Which methods are present in POM to locate web elements? 24. Which tool is used to manage and organize JARs and libraries in automation? 25. Which open-source tool allows us to read and write MS Excel files using Java? --xx--- 8) 𝗧𝗲𝘀𝘁𝗶𝗻𝗴 𝗖𝗼𝗻𝗰𝗲𝗽𝘁𝘀 28. What is UI Testing? 29. What is open-source software? 30. What is regression testing?
To view or add a comment, sign in
-
𝐀𝐮𝐭𝐨𝐦𝐚𝐭𝐢𝐨𝐧 𝐓𝐞𝐬𝐭𝐢𝐧𝐠 𝐈𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 👇 1) 𝗦𝗲𝗹𝗲𝗻𝗶𝘂𝗺 𝗕𝗮𝘀𝗶𝗰𝘀 1. What is Selenium? 2. Which component of Selenium is the most important? 3. Which browser supports Selenium? --xx--- 2) 𝗟𝗼𝗰𝗮𝘁𝗼𝗿𝘀 & 𝗫𝗣𝗮𝘁𝗵 4. Among all the given locators, which one is the fastest? 5. How many locators are there in Selenium? 6. How many types of XPath are there in Selenium? 7. Which type of XPath starts with a double forward slash (//)? 8. Which type of XPath starts with a single forward slash (/)? 9. Write the correct syntax for an absolute XPath. 10. Which XPath is used to search dissimilar nodes in an XML document from the current node? --xx--- 3) 𝗘𝗹𝗲𝗺𝗲𝗻𝘁 𝗛𝗮𝗻𝗱𝗹𝗶𝗻𝗴 11. When you only want to access a single element on a webpage, which method will you use? 12. Which class is used to handle drop-downs in Selenium? 13. If a method fails to find the element, which of the two methods throws an exception? --xx--- 4) 𝗪𝗶𝗻𝗱𝗼𝘄𝘀, 𝗪𝗮𝗶𝘁𝘀 & 𝗦𝗰𝗿𝗲𝗲𝗻𝘀𝗵𝗼𝘁𝘀 14. Which method allows you to switch control from one window to another? 15. Which exception is shown in Selenium when there is a delay in loading elements we want to interact with? 16. How many types of waits does Selenium WebDriver provide? 17. Which type of wait command waits for a certain amount of time before throwing an exception? 18. Which wait takes timeout and polling frequency as its parameters? 19. In Selenium 4, which method allows us to take a screenshot of a specific web element? --xx--- 5) 𝗧𝗲𝘀𝘁𝗡𝗚 20. How do you execute multiple test cases at a time in TestNG? 21. Which annotations are executed first in TestNG? --xx--- 6) 𝗙𝗿𝗮𝗺𝗲𝘄𝗼𝗿𝗸 & 𝗧𝗼𝗼𝗹𝘀 22. What is Page Object Model (POM)? 23. Which methods are present in POM to locate web elements? 24. Which tool is used to manage and organize JARs and libraries in automation? 25. Which open-source tool allows us to read and write MS Excel files using Java? --xx--- 8) 𝗧𝗲𝘀𝘁𝗶𝗻𝗴 𝗖𝗼𝗻𝗰𝗲𝗽𝘁𝘀 28. What is UI Testing? 29. What is open-source software? 30. What is regression testing?
To view or add a comment, sign in
-
Page Object Model (POM) + @FindBy in Selenium – Why It Matters #Selenium #AutomationTesting #Java #SDET #TestAutomation #PageObjectModel #QA When you’re building UI automation at scale, one of the biggest challenges is maintainability. Hardcoded locators inside test classes quickly become a mess. That’s where Page Object Model (POM) comes in. POM is a design pattern where each page of your application is represented by a Page Class. This class contains: ✅ Locators of elements ✅ Methods (actions) to interact with those elements ✅ Navigation logic to the next page This keeps tests clean, readable, and easy to maintain. Example with POM (Without @FindBy) public class LoginPage { private WebDriver driver; private By usernameField = By.id("username"); private By passwordField = By.id("password"); private By loginBtn = By.id("loginBtn"); public LoginPage(WebDriver driver) { this.driver = driver; } public void enterUsername(String username) { driver.findElement(usernameField).sendKeys(username); } public void enterPassword(String password) { driver.findElement(passwordField).sendKeys(password); } public HomePage clickLogin() { driver.findElement(loginBtn).click(); return new HomePage(driver); } } Using @FindBy with PageFactory To simplify element declaration, Selenium provides @FindBy annotation. Instead of writing driver.findElement(), you declare elements once and initialize them with PageFactory. Declaration + Initialization public class LoginPage { private WebDriver driver; @FindBy(id = "username") private WebElement usernameField; @FindBy(id = "password") private WebElement passwordField; @FindBy(id = "loginBtn") private WebElement loginBtn; public LoginPage(WebDriver driver) { this.driver = driver; PageFactory.initElements(driver, this); } public HomePage login(String user, String pass) { usernameField.sendKeys(user); passwordField.sendKeys(pass); loginBtn.click(); return new HomePage(driver); } } Usage in Test : @Test public void validLoginTest() { LoginPage loginPage = new LoginPage(driver); HomePage homePage = loginPage.login("test_user", "test_pass"); Assert.assertTrue(homePage.getWelcomeMessage().contains("Welcome")); } Key Points to Remember : -POM separates locators & actions from test logic → easier maintenance. -@FindBy reduces boilerplate and makes code cleaner. -Must use PageFactory.initElements(driver, this) in constructor to initialize @FindBy elements. -Create a BasePage class to keep common methods like click(), type(), waitForElement(). -Combine POM + API setup (Rest Assured) for faster and stable UI tests. -POM is about structure and maintainability. -@FindBy is about cleaner, readable code. -Together, they make your Selenium framework scalable, reliable, and interview-ready.
To view or add a comment, sign in
-
Page Object Model (POM) + @FindBy in Selenium – Why It Matters #Selenium #AutomationTesting #Java #SDET #TestAutomation #PageObjectModel #QA When you’re building UI automation at scale, one of the biggest challenges is maintainability. Hardcoded locators inside test classes quickly become a mess. That’s where Page Object Model (POM) comes in. POM is a design pattern where each page of your application is represented by a Page Class. This class contains: ✅ Locators of elements ✅ Methods (actions) to interact with those elements ✅ Navigation logic to the next page This keeps tests clean, readable, and easy to maintain. Example with POM (Without @FindBy) public class LoginPage { private WebDriver driver; private By usernameField = By.id("username"); private By passwordField = By.id("password"); private By loginBtn = By.id("loginBtn"); public LoginPage(WebDriver driver) { this.driver = driver; } public void enterUsername(String username) { driver.findElement(usernameField).sendKeys(username); } public void enterPassword(String password) { driver.findElement(passwordField).sendKeys(password); } public HomePage clickLogin() { driver.findElement(loginBtn).click(); return new HomePage(driver); } } Using @FindBy with PageFactory To simplify element declaration, Selenium provides @FindBy annotation. Instead of writing driver.findElement(), you declare elements once and initialize them with PageFactory. Declaration + Initialization public class LoginPage { private WebDriver driver; @FindBy(id = "username") private WebElement usernameField; @FindBy(id = "password") private WebElement passwordField; @FindBy(id = "loginBtn") private WebElement loginBtn; public LoginPage(WebDriver driver) { this.driver = driver; PageFactory.initElements(driver, this); } public HomePage login(String user, String pass) { usernameField.sendKeys(user); passwordField.sendKeys(pass); loginBtn.click(); return new HomePage(driver); } } Usage in Test : @Test public void validLoginTest() { LoginPage loginPage = new LoginPage(driver); HomePage homePage = loginPage.login("test_user", "test_pass"); Assert.assertTrue(homePage.getWelcomeMessage().contains("Welcome")); } Key Points to Remember : -POM separates locators & actions from test logic → easier maintenance. -@FindBy reduces boilerplate and makes code cleaner. -Must use PageFactory.initElements(driver, this) in constructor to initialize @FindBy elements. -Create a BasePage class to keep common methods like click(), type(), waitForElement(). -Combine POM + API setup (Rest Assured) for faster and stable UI tests. -POM is about structure and maintainability. -@FindBy is about cleaner, readable code. -Together, they make your Selenium framework scalable, reliable, and interview-ready.
To view or add a comment, sign in
-
This is the foundational knowledge every automation engineer needs. From prerequisites to framework enhancements, here's a step-by-step breakdown: ✅ **Prerequisites:** - Install JDK & your favorite IDE (Eclipse/IntelliJ). - Get Selenium WebDriver JARs. ✅ **Project Setup (with Maven):** - Create a new Maven project. - Add dependencies for Selenium, TestNG/JUnit, and your browser driver to your `pom.xml`. ✅ **Writing Your First Script:** - Initialize the WebDriver. - Use `driver.get()` to navigate. - Interact with elements using locators like ID, Xpath. - Use assertions to verify outcomes. - Always close your browser with `driver.quit()`. ✅ **Running Tests:** - Execute directly from your IDE or via Maven (`mvn clean test`). 💡 **Pro-Tip:** For a robust, scalable framework, consider these enhancements: - Page Object Model (POM) for maintainability. - Data-driven testing. - Integrate reporting (e.g., Extent Reports). - Set up for cross-browser testing. What's your favorite tool or trick for a smooth Selenium setup? Let's discuss in the comments! 👇 #Selenium #Java #Automation #SoftwareTesting #QA #TestAutomation #LinkedInLearning #CareerGrowth
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development