InterviewSolution
| 1. |
What is synchronization? |
|
Answer» Synchronization is a mechanism that involves two or more components that work parallel with Each other. In Test Automation, Application Under Test and Test Automation tool are the two components. Both these components have their own speed, and to make these two components should move with the same and desired speed, we should write our scripts in such a way that we will not encounter "Element Not Found" errors which will consume time again in debugging. Unconditional and Conditional Synchronization are the two categories of synchronization. Unconditional Synchronization: In Unconditional synchronization, we specify the timeout value only. The tool will wait until a CERTAIN amount of time and then proceed further. Examples: Wait() and Thread.Sleep(), The disadvantage in the above statements is, even though the application is ready there is a chance of unnecessary waiting time. When we interact with third-party systems LIKE interfaces, it is not possible to write a condition or check for a condition. In such scenarios, we have to make applications wait for a certain amount of time by specifying timeout value and the unconditional wait comes as help here. Conditional Synchronization: In conditional synchronization, we specify a condition along with timeout value, so the tool waits and checks for the condition and then it come out if nothing happens. It is important to set the timeout value in conditional synchronization because the tool should proceed further instead of making the tool to wait for a particular condition to satisfy. In Selenium implicit Wait and Explicit Wait are two components of conditional statements. There are two types of Conditional Synchronization:
Implicit Wait: Implicit Wait tells the WebDriver to before throwing exception NoSuchElement/ElementNotVisible, wait until the stated time. Waiting time between each consecutive step is taken by default across the test script. So, the next test Step will be executed only when the specified time is elapsed. Syntax: driver.Manage().TIMEOUTS().ImplicitlyWait(TimeSpan.FromSeconds(30));FromMilliSecondsThe Implicit wait takes two arguments: TimeSpan (timeToWait) and time measure.
Explicit Wait: When page load dynamically explicit waits are good to use. Before throwing NoSuchElement (or) ElementNotVisible Exceptions, explicit Wait tells the WebDriver to Wait TILL the specified condition is met or maximum time elapses. Explicit waits are applied for the specified test Step in the test script. We must first create an instance for the “WebDriverWait” class to use Explicit wait. WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id(element_ID)));The REFERENCE variable “wait” informs the WebDriver to wait until the Expected condition to occur (or) Wait for the specified time of 30seconds, whichever shows in first place before throwing an exception. Below are the ExpectedConditions:
The Implicit wait is simple as compared to Explicit wait and can be declared in setup method of the test script in single line of code. But, despite being easy and simple to apply and hence rising scope of Explicit Waits as these waits can be applied for a specified test Step in test script. |
|