Skip to main content

Posts

Selenium 3 vs Selenium 4

Recent posts

Difference between get() vs navigate() in Selenium

Selenium offers two distinct functions, get() and Maps() , for loading web pages. While both serve the fundamental purpose of directing the browser to a URL, they possess unique advantages and disadvantages that make them suitable for different scenarios. This article will delve into a detailed comparison of these two functions. What is the get() function in Selenium? The get() function in Selenium WebDriver is used to open a specified URL in the browser. Its primary purpose is to initiate a new browser session and navigate directly to the given web address. This method is straightforward and efficient for simply loading a web page from a URL. What is the Maps() function in Selenium? In Selenium WebDriver, the Maps() method is part of the WebDriver.Navigation interface. It offers more advanced capabilities for managing browser history and navigation compared to the get() method. The Maps() method allows users to move forward and backward through the browser's history, refre...

POM

  Understanding POM The Page Object Model (POM) is a design pattern in test automation that separates UI elements, actions, and test scenarios into different files or classes. This helps make tests easier to read, reuse, and maintain, especially for web applications. It can be implemented using Page Factory (with @FindBy annotations for lazy loading) or without it (using driver.findElement() for more control). Is POM a Waste of Time and Money? It seems likely that POM is not inherently a waste, but its value depends on how it's used. Critics, like Eldad Uzman, argue it can add unnecessary overhead for simple cases or require skilled teams, potentially increasing costs. However, many experts highlight its benefits for long-term maintenance, suggesting it's worth the investment for complex projects. The evidence leans toward POM being effective when aligned with project needs, but it may not suit every scenario, especially if creating a single framework for all applications, a...

TestNG Listeners

 TestNG provides a bunch of listeners as a part of its testing environment. These listeners are as follows: ITestListener IRetryListener IReporter ISuiteListener IInvokedMethod IHookable IConfigurationListener IConfigurableListener IAnnotationTransformer IExecution IMethodInterceptor

Retry Failed Tests in TestNG

TestNG provides various listeners to customize our needs. One such powerful listener is IRetryListener using which you can retry a test case multiple times before declaring it as Failed. If you see a failure can just automatically rerun the test to make sure that the test is consistently failing. this way it reduces false failures because of random issues and you spend more time debugging true failures. IRetryListener interface has only one method public boolean retry(ITestResult result); This method will be called whenever a test method fails. You can get the details of the test from  ITestResult  input argument to this method. This method implementation should return true if you want to re-execute your failed test and false if you don't want to re-execute your test.

Page load using JavascriptExecutor

public static boolean waitForPageLoad(WebDriver driver, int timeout){ ExpectedCondition<Boolean> pageLoadCondition = new ExpectedCondition<Boolean>(){ public Boolean apply(WebDriver driver){ return ((JavascriptExecutor)driver).executeScript("return document.readyState"); } }; WebDriverWait wait = new WebDriverWait(driver, timeout); return wait.until(pageLoadCondition);  }