| <!DOCTYPE html> |
| <!-- |
| Copyright 2012 Software Freedom Conservancy. All Rights Reserved. |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| <title>webdriver_wait_test.html</title> |
| <script src="test_bootstrap.js"></script> |
| <script> |
| goog.require('goog.dom'); |
| goog.require('webdriver.WebDriver'); |
| goog.require('webdriver.Session'); |
| goog.require('webdriver.test.JsExecutor'); |
| goog.require('webdriver.test.testutil'); |
| goog.require('webdriver.testing.jsunit'); |
| |
| function addFoo() { |
| var div = document.createElement('DIV'); |
| div.className = 'foo'; |
| div.innerHTML = 'FOO'; |
| setTimeout(function() { |
| document.body.appendChild(div); |
| }, 750); |
| } |
| |
| function removeFoo() { |
| setTimeout(function() { |
| var foos = goog.dom.getElementsByTagNameAndClass('DIV', 'foo'); |
| if (foos.length) |
| document.body.removeChild(foos[foos.length - 1]); |
| }, 750); |
| } |
| </script> |
| <body> |
| <button id="add" onclick="addFoo();">Add foo!</button> |
| <button id="remove" onclick="removeFoo();">Remove foo!</button> |
| <script> |
| var DRIVER = new webdriver.WebDriver( |
| new webdriver.Session('test_session_id', {}), |
| new webdriver.test.JsExecutor); |
| |
| function testWaiting() { |
| var addButton = DRIVER.findElement(By.id("add")); |
| var removeButton = DRIVER.findElement(By.id("remove")); |
| |
| addButton.click(); |
| addButton.click(); |
| addButton.click(); |
| waitForNFoo(3); |
| |
| removeButton.click(); |
| removeButton.click(); |
| waitForNFoo(1); |
| |
| addButton.click(); |
| addButton.click(); |
| waitForNFoo(3); |
| |
| removeButton.click(); |
| removeButton.click(); |
| removeButton.click(); |
| waitForNFoo(0); |
| } |
| |
| function waitForNFoo(n) { |
| DRIVER.wait(function() { |
| return DRIVER.findElements(By.className('foo')).then(function(foos) { |
| return foos.length == n; |
| }); |
| }, 3000); |
| } |
| |
| </script> |
| </body> |