Ukraine Office: +38 (063) 50 74 707

USA Office: +1 (212) 203-8264

contact@testmatick.com

Manual Testing

Ensure the highest quality for your software with our manual testing services.

Mobile Testing

Optimize your mobile apps for flawless performance across all devices and platforms with our comprehensive mobile testing services.

Automated Testing

Enhance your software development with our automated testing services, designed to boost efficiency.

Functional Testing

Refine your application’s core functionality with our functional testing services

VIEW ALL SERVICES 

Discussion – 

0

Discussion – 

0

Wait Commands in Selenium

Wait-Commands-in-Selenium

Waits are characteristic features of any UI test for dynamic applications. They facilitate the synchronization of AUT and the testing script. An application’s response to commands is much slower than script performance. That’s why in scripts, you have to wait for a particular application state to interact with it.

Using wait commands is important when running tests in Selenium. It allows you to avoid problems that may occur due to changes in the time delay.

Nevertheless, waiting, especially in automated tests, isn’t always a good thing. But it’s possible to reorganize your work using a favorable method. Selenium WebDriver has three commands for implementing waits in tests: Implicit Wait, Explicit Wait, Fluent Wait.

In this article, we’ll focus on the first two commands.

Implicit Wait tells the Selenium WebDriver to wait the required time, only then generate an exception. After defining the time, the WebDriver waits for an item before generating an exception.

Once the commands are executed, Implicit Wait is valid for as long as the browser is open. The default value is 0, so an exception will be instant.

Syntax: driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS)

Setting Implicit Wait:

Setting Implicit Wait

Setting Implicit Wait

Implicit Wait extends the time frame of the test script execution. Commands must wait a certain amount of time before returning to test execution.

Explicit Wait is implemented when the condition is met, after which the test will be running again.

Syntax: WebDriverWait wait = new WebDriverWait(driver,10)

The list of conditions applied by ExpectedConditions:

• alertIsPresent()
• elementSelectionStateToBe()
• elementToBeClickable()
• elementToBeSelected()
• frameToBeAvaliableAndSwitchToIt()
• invisibilityOfTheElementLocated()
• invisibilityOfElementWithText()
• presenceOfAllElementsLocatedBy()
• presenceOfElementLocated()
• textToBePresentInElement()
• textToBePresentInElementLocated()
• textToBePresentInElementValue()
• titleIs()
• titleContains()
• visibilityOf()
• visibilityOfAllElements()
• visibilityOfAllElementsLocatedBy()
• visibilityOfElementLocated()

Example of Explicit Wait test:

private WebDriver driver;
private WebDriverWait wait;
private WebElement exampleElement;

@BeforeMethod(alwaysRun = true)
public void setUpDriver() {
//Set up driver
ChromeOptions options = new ChromeOptions();
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver(options);
//Set explicit wait
wait = new WebDriverWait(driver, 10);
}

@Test(description = “Open url”)
public void openUrl() {
//Open browser
driver.manage().window().setSize(new Dimension(1280, 970));
//Get url
driver.get(“https://some-site.com”);

//Wait until blockUI disappear
wait.until(ExpectedConditions.invisibilityOfElementLocated
(By.cssSelector(“element”)));
wait.until(ExpectedConditions.invisibilityOf(exampleElement));

//Search an element
WebElement element = driver.findElement(By.id(“some-id”));
Assert.assertTrue(element.isDisplayed());

//Click element
element.click();

//Wait until alert is present
wait.until(ExpectedConditions.alertIsPresent());
driver.switchTo().alert().accept();

}

@AfterMethod(alwaysRun = true)
public void closeBrowser() {
//Close browser
driver.quit();
}

In the automated tester’s work for an independent quality assurance organization, it is very important to apply Selenium wait commands. This will save a lot of time and provide a great approach to solving many software testing problems.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

You May Also Like

Encapsulation as One of the Fundamental Principles of Object-Oriented Programming

Encapsulation as One of the Fundamental Principles of Object-Oriented Programming

Knowing the basics of object-oriented programming is necessary not only for programmers, but also, of course, for testers who interact with program code, study it, or write it. Insight into programming fundamentals enables QA experts to better understand the program behavior, give effective recommendations on how to improve the structure of program code, and, more efficiently create autotest code.

Test Automation Strategies That Really Work

Test Automation Strategies That Really Work

An approach to the development and implementation of automated tests for an application-in-test depends on numerous factors. A size and complexity of an application, a structure of a project team, instantly appearing deadlines, requirements for security, and many other details define the most suitable strategy. Further, we will describe some working strategies that can be helpful for any project that requires automation.

Using Test Retries as a Method to Hide Bugs

Using Test Retries as a Method to Hide Bugs

Every tester is in some way familiar with the concept of randomly failing automated tests. An analysis of the results of these tests can be really time-consuming and some teams prefer running tests once again if they fail. But is this efficient? The answer is not as obvious and clear as it seems.