QA WBA 1 Sprint Summary

Modified on Tue, 25 Jul, 2023 at 8:08 AM

Index:

  1. Synchronization

  2. Actions Buttons and Selection

  3. Web components




Topic 1: Synchronization


Synchronization


What is it?


Synchronization is a mechanism that ensures that two or more concurrent processes or threads in test automation do not simultaneously execute some particular program segment known as a critical section, hence ensuring the integrity of the test and the accuracy of the results.


Where is it used?


Synchronization is used in the following scenarios in testing:


When testing multi-threaded applications to ensure no race conditions occur.

When there is a need for interactions with the UI or API that require a certain state of the system (for example, an element has to appear on a web page, or an API endpoint has to respond within a certain time).

When tests depend on the state of external resources (like a database or a server), which need to be in a specific state before the test can run.



How is it used?



One of the common ways to synchronize tests is by using wait mechanisms. There are two types of wait in Selenium, explicit and implicit waits.

Explicit wait is a code you define to wait for a certain condition to occur before proceeding further in the code. 


Implicit wait tells WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements that are not immediately available.



A code snippet using explicit wait would look like this:


WebDriverWait wait = new WebDriverWait(driver, 20);

WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("element-id")));

Takeaways / best practices :

  • Avoid unnecessary waits: Instead of using a static Thread.sleep(), try to use explicit waits that would wait only as long as necessary.




Topic 2: Actions Buttons and Selection


Web Actions



What is it?



Actions in QA automation refer to the activities that a test performs on the system under test, such as clicking a button, entering text, submitting a form, or sending an HTTP request.



Where is it used?



Actions are used in virtually every automated test, as they simulate the behavior of a user or another system interacting with the system under test.



How is it used?

  • In Selenium, you can use the WebElement interface to interact with HTML elements.

  • You can also use the Actions class to perform complex user interactions like drag-and-drop.




Here is a code snippet that uses the WebElement interface and the Actions class:


WebElement element = driver.findElement(By.id("element-id"));

element.click();



Actions actions = new Actions(driver);

actions.dragAndDrop(sourceElement, targetElement).perform();


Takeaways / best practices :

  • Handle errors gracefully: If an action fails (for example, an element is not found or a request returns a 4xx or 5xx status code), make sure to handle the error appropriately, so that the failure is reported accurately and does not cause unrelated tests to fail.




Checkboxes and Buttons


What is it?

In the context of QA Automation, checkboxes and buttons are interactive elements on a webpage that a user can manipulate, and we need to interact with these elements during testing to simulate user behaviour.


Where is it used?


Checkboxes and buttons are commonly found in web applications. They are used in various places like forms for input submission, navigation menus for directing users, control panels for manipulating settings, etc.


How is it used?


You can interact with checkboxes and buttons using Selenium WebDriver.

You can find the element using one of the find methods (like findElement(By.id())) and then click on it using the click() method.

For checkboxes, you can also check whether it's checked using the isSelected() method.



Here is a code snippet that clicks on a button and toggles a checkbox:

// Find and click a button

WebElement button = driver.findElement(By.id("button-id"));

button.click();



// Find a checkbox, check its status, and toggle it

WebElement checkbox = driver.findElement(By.id("checkbox-id"));

if (!checkbox.isSelected()) {

    checkbox.click();

}


Takeaways / best practices :


  • Always check the state of a checkbox before interacting with it. You don't want to accidentally uncheck it when you think you are checking it.

  • Be aware of the possibility of StaleElementReferenceException. This can happen if the state of a checkbox or button changes after you find the element but before you interact with it.

  • If a button click leads to a new page being loaded, you might need to add a wait after the click to make sure the new page is loaded before you start interacting with it.



Topic 3: Web components


Tables and calendars



What is it?


In the context of QA automation, tables are structured web elements that display information in a grid-like format, and calendars are interactive web elements that allow users to select dates.



Where is it used?


Tables and calendars are used in various parts of a web application. Tables are often used to display data in an organized manner, and calendars are used whenever there is a need for date selection, such as input fields for birth dates, appointment dates, etc.


How is it used?



Selenium:

Selenium WebDriver can be used to interact with both tables and calendars. For tables, you would usually find the rows and cells you're interested in and read or interact with their content. For calendars, you would navigate to the correct month and year, then select the day.

Here is a code snippet that reads data from a table and selects a date from a calendar:


// Find a table and read its first cell

WebElement table = driver.findElement(By.id("table-id"));

String firstCellText = table.findElement(By.xpath(".//tr[1]/td[1]")).getText();



// Find a calendar and select a date

WebElement calendar = driver.findElement(By.id("calendar-id"));

calendar.findElement(By.xpath(".//td[.='2023']")).click();

calendar.findElement(By.xpath(".//td[.='July']")).click();

calendar.findElement(By.xpath(".//td[.='18']")).click();


Takeaways / best practices :



Tables and calendars can be complex, so make sure your locators are accurate. For example, the structure of a table can change if rows or columns are added or removed, and the structure of a calendar can change depending on the month and year.



When interacting with a table, be aware that the first row might be a header row, and the cells in this row might be th elements instead of td elements.



When interacting with a calendar, consider all possible states. For example, the day you want to select might be in the previous month, the next month, or not visible at all if the calendar shows only one week at a time.



Be patient with tables and calendars. These elements can take some time to load, especially if the table has many rows or the calendar is slow to navigate.


All the best and Happy Learning!

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article