Download presentation
Presentation is loading. Please wait.
Published byEdward Robbins Modified over 9 years ago
1
Selenium Waits © 2015, Perfecto Mobile Ltd. All Rights Reserved.
2
Agenda Why Wait? Selenium Wait Commands Implicit Waits Explicit Waits Fluent Waits Conflicts Erratic Behavior Demonstration 3/10/2016 2 © 2015, Perfecto Mobile Ltd. All Rights Reserved.
3
Why Wait? When automating an application you must wait for a transaction to complete before proceeding to your next action. Using sleeps should never be used as an alternative to waits. Sleeps will ALWAYS wait the exact amount of time you specify even if the application is ready to proceed. Waits only wait as long as necessary which saves you precious time on your execution. Selenium Offers 3 wait types Implicit Waits Explicit Waits Fluent Waits 3/10/2016 3 © 2015, Perfecto Mobile Ltd. All Rights Reserved.
4
Different Wait Commands Implicit Waits (Good)Explicit Waits (Better)Fluent Waits (Best) Why Use?If possible don’t use implicit waitsAllows you to wait for a specific condition or set of conditions before proceeding Pros Ease of use Fine for small applications with little processing time and no dynamic content or behaviors Great control over wait behavior Allows control over application polling to check for condition Cons No control over behavior False-Positives on successful transactions Can cause errors or additional wait times when used with Explicit and Fluent waits Flow control code (conditional) will result in unnecessary waits No control over application polling to check for condition Requires implementation on an as needed basis instead of globally 3/10/2016 4 © 2015, Perfecto Mobile Ltd. All Rights Reserved.
5
Implicit Wait 3/10/2016 5 © 2015, Perfecto Mobile Ltd. All Rights Reserved. JavaC# Implicit Wait Implicit waits apply globally to every find element call. Depending on the driver, implicit waits will either ping the application every X milliseconds OR if the implicit wait fails the first time it may wait the duration of the timeout before trying one last time to find the element. Implicit waits only check for the existence of an object. Due to this behavior your application may not be ready to use even if the wait succeeds in locating an object. To resolve conflicts: When using implicit waits with fluent/explicit waits you should set the implicit wait to zero prior to performing the fluent/explicit wait. Once the fluent/explicit wait completes you can set the implicit wait back to its default value. When implicit waits are used you should set the value to zero prior to performing conditional checks on a page. Best practice is to not use implicit waits if possible.
6
Explicit Wait 3/10/2016 6 © 2015, Perfecto Mobile Ltd. All Rights Reserved. JavaC# Explicit Waits Unlike implicit waits, explicit waits only apply on a per transaction basis. Explicit waits ping the application every 500ms checking for the condition of the wait to be true. You can have explicit waits wait for finding an element or some predefined expected conditions. https://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html
7
Java - SetupC# - Setup Fluent Wait 3/10/2016 7 © 2015, Perfecto Mobile Ltd. All Rights Reserved. Fluent Waits Just like explicit waits, fluent waits only apply on a per transaction basis. Fluent waits require that you define the wait between checks of the application for an object/condition as well as the overall timeout of the transaction. Additionally you must tell fluent waits not to throw an exception when they don’t find an object as best practice. You can have fluent waits wait for finding an element or some predefined expected conditions. https://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html Java – Find and return elementC# - Find and return element
8
Wait Conflicts Using Implicit and Fluent/Explicit Wait Together Implicit waits and fluent/explicit waits can conflict Due to the driver deciding where waits occur (client vs server side) using implicit and explicit/fluent waits together can create race conditions in all circumstances implicit timeout > fluent/explicit timeout fluent/explicit timeout > implicit timeout implicit timeout == fluent/explicit timeout Implicit waits can conflict with fluent/explicit conditions Fluent/explicit waits have many different conditions which could be met Mixing implicit waits with fluent/explicit waits can result in undesired sleeps Mixing implicit waits with fluent/explicit waits can result in errors returning from one of the implemented waits If you must mix implicit waits with fluent/explicit waits you should set the implicit wait timeout value to zero in order to resolve any conflict which would arise. 3/10/2016 8 © 2015, Perfecto Mobile Ltd. All Rights Reserved.
9
Erratic Wait Behavior Waits can behave differently on a per driver basis Chrome Driver, Firefox Driver, Perfecto, Etc. Remote web driver adds complexity to the wait implementation The remote web driver resides on a server which executes a driver behind the scenes The driver being utilized makes the decision on how waits behave (server vs client) This can change over time as the driver goes through version changes Race conditions may be seen on one driver and not another Behavior may also differ based on the programming language Best Practice: You should test your code on all driver types to ensure response time and/or errors are desirable 3/10/2016 9 © 2015, Perfecto Mobile Ltd. All Rights Reserved.
10
Thank You © 2015,Perfecto Mobile Ltd. All Rights Reserved.
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.