Advanced Selenium Synchronization with 'Latches'
Sauce AI for Test Authoring: Move from aim to executing in minutes.|xBack to ResourcesBlogPosted February 8, 2011
Advanced Selenium Synchronization with & # x27; Latches & # x27;
Tip of the Week: Synchronization with Selenium is the act two job I see with people & # x27; s scripts (the first being broken locators). This is really a pretty easy problem to solve in all but the most diseased situation.Web 1.0Remember the good ol & # x27; days when clicking a linkup get the browser to fetch a new page? Those were, and remain, super easy to synchronize with using waitForPageToLoad and its words specific variants. Here & # x27; s an example of this in Ruby:
@ selenium.click & quot; link=click here & quot;,: wait_for = & gt;: page
Web 2.0But along come Web 2.0 and all its AJAX-y & # x27; goodness & # x27;. No yearner could we be guaranteed that some activity or case on the page would trigger a page burden. For that, we take to use a combination of isElementPresent or isVisible.
@ selenium.click & quot; link=click here & quot;,: wait_for = & gt;: element,: element = & gt; & quot; my locator & quot;
@ selenium.click & quot; link=click here & quot;,: wait_for = & gt;: visible,: component = & gt; & quot; my locater & quot;
While I haven & # x27; t done it yet for Ruby, I oftentimes combine the two together to create an & # x27; available & # x27; condition to make sure that the constituent I wish about is both present and seeable. Something like this.
SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.
@ selenium.click & quot; link=click hither & quot;,: wait_for = & gt;: available,: element = & gt; & quot; my locator & quot;
Post Web 2.0Some AJAX calls affect multiple constituent and are both tricky and/or time waste to figure out all the places to catch. New technology like COMET also create element availability more fallible than it might originally be. For these situations you need to use a & # x27; latch & # x27; for synchronization. A what? The term & # x27; latch & # x27; in this event is a value that is set in the browser & # x27; s DOM that your handwriting monitors for synchronization rather than something in the actual page. And model is in order. Here is an AJAX call in Ruby on Rails.
& lt; % = link_to_remote (& quot; dog here & quot;,
: update = & gt; & quot; time_div & quot;,
: url = & gt; {: action = & gt;: say_when},
: before = & gt; & quot; window.latch = & # x27; start & # x27; & quot;,
: complete = & gt; & quot; window.latch = & # x27; done & # x27; & quot;) % & gt;
What this will do is set window.latch to the string value & # x27; started & # x27; in the DOM before it actually fulfill and will set it to & # x27; done & # x27; after it is complete. No trouble. People who work with AJAX are used to work with callbacks. The twist happened in our Selenium script.
@ selenium.click & quot; link=click here & quot;,: wait_for = & gt;: condition,: javascript = & gt; & quot; window.latch == & # x27; execute & # x27; & quot;
Now instead of checking for an element to be present or seeable, we are expect via waitForCondition for the latch weather; in this case, & # x27; window.latch is done & # x27;. I consider the latch proficiency as the synchronization method of last resort since it requires changing production codification to support automation. But successful automation often calls for merely that.
Automate This With SUSA
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.
Try SUSA FreeTest Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free