| <!DOCTYPE html> |
| <!-- |
| Copyright 2010 WebDriver committers |
| Copyright 2010 Google Inc. |
| |
| 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. |
| --> |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <title>element_test.html</title> |
| <link rel="stylesheet" href="/filez/_main/third_party/js/qunit/qunit.css"> |
| <script src="/filez/_main/third_party/js/qunit/qunit.js"></script> |
| <script src="/filez/_main/third_party/js/qunit/qunit_test_runner.js"></script> |
| <script src="../test_bootstrap.js"></script> |
| <script type="text/javascript"> |
| goog.require('bot.Keyboard'); |
| goog.require('bot.locators'); |
| goog.require('bot.userAgent'); |
| goog.require('goog.userAgent'); |
| goog.require('webdriver.atoms.element'); |
| goog.require('webdriver.Key'); |
| </script> |
| |
| <script type="text/javascript"> |
| QUnit.test('should return the value of an attribute', function(assert) { |
| var element = bot.locators.findElement({id: 'has_id'}); |
| |
| assert.strictEqual(webdriver.atoms.element.getAttribute(element, 'title'), 'cheese'); |
| }); |
| |
| QUnit.test('should return null if a value does not exist as an attribute or a property', function(assert) { |
| var element = bot.locators.findElement({id: 'has_id'}); |
| |
| assert.strictEqual(webdriver.atoms.element.getAttribute(element, 'this_does_not_exist'), null); |
| }); |
| |
| QUnit.test('should return the value of a property', function(assert) { |
| var element = bot.locators.findElement({id: 'has_property'}); |
| |
| assert.strictEqual(webdriver.atoms.element.getAttribute(element, 'value'), "This is an example"); |
| }); |
| |
| QUnit.test('should return values as strings', function(assert) { |
| var element = bot.locators.findElement({id: 'has_property'}); |
| |
| assert.strictEqual(webdriver.atoms.element.getAttribute(element, 'rows'), '2'); |
| }); |
| |
| QUnit.test('should return same value for class and className', function(assert) { |
| var element = document.body; |
| |
| assert.strictEqual(webdriver.atoms.element.getAttribute(element, 'class'), |
| webdriver.atoms.element.getAttribute(element, 'className')); |
| }); |
| |
| QUnit.test('should return boolean properties as strings', function(assert) { |
| var readOnlyElement = bot.locators.findElement({id: 'ro'}); |
| |
| assert.strictEqual(webdriver.atoms.element.getAttribute(readOnlyElement, 'readonly'), "true"); |
| }); |
| |
| QUnit.test('setting any value for a boolean attribute sets it to true', function(assert) { |
| var element = bot.locators.findElement({id: 'bad-ro'}); |
| |
| assert.strictEqual(webdriver.atoms.element.getAttribute(element, 'readonly'), "true"); |
| }); |
| |
| QUnit.test('should attempt to stringify the style property', function(assert) { |
| var element = bot.locators.findElement({id: 'green'}); |
| |
| var style = webdriver.atoms.element.getAttribute(element, 'style').toLowerCase(); |
| assert.ok(style.indexOf('background-color') != -1); |
| }); |
| |
| QUnit.test('should correctly report the value of checked for radio buttons', function(assert) { |
| var selected = bot.locators.findElement({id: 'selected-radio'}); |
| var unselected = bot.locators.findElement({id: 'unselected-radio'}); |
| |
| assert.strictEqual(webdriver.atoms.element.getAttribute(selected, 'checked'), "true"); |
| assert.strictEqual(webdriver.atoms.element.getAttribute(unselected, 'checked'), null); |
| }); |
| |
| QUnit.test('should indicate whether an element is selected', function(assert) { |
| var input = bot.locators.findElement({id: 'normal'}); |
| var unselectedRadio = bot.locators.findElement({id: 'unselected-radio'}); |
| var selectedRadio = bot.locators.findElement({id: 'selected-radio'}); |
| var unselectedOption = bot.locators.findElement({id: 'unselected-option'}); |
| var selectedOption = bot.locators.findElement({id: 'selected-option'}); |
| |
| assert.ok(webdriver.atoms.element.isSelected(selectedRadio)); |
| assert.ok(webdriver.atoms.element.isSelected(selectedOption)); |
| assert.notOk(webdriver.atoms.element.isSelected(unselectedRadio)); |
| assert.notOk(webdriver.atoms.element.isSelected(unselectedOption)); |
| assert.notOk(webdriver.atoms.element.isSelected(input)); |
| }); |
| |
| QUnit.test('should correctly report the value of selected for radio buttons', function(assert) { |
| var selected = bot.locators.findElement({id: 'selected-radio'}); |
| var unselected = bot.locators.findElement({id: 'unselected-radio'}); |
| |
| assert.strictEqual(webdriver.atoms.element.getAttribute(selected, 'selected'), "true"); |
| assert.strictEqual(webdriver.atoms.element.getAttribute(unselected, 'selected'), null); |
| }); |
| |
| QUnit.test('multiple property of selects is a boolean', function(assert) { |
| var element = bot.locators.findElement({name: 'multi'}); |
| |
| assert.strictEqual(webdriver.atoms.element.getAttribute(element, 'multiple'), 'true'); |
| }); |
| |
| QUnit.test('should return an empty string if an attribute is set but empty', function(assert) { |
| var element = bot.locators.findElement({id: 'body'}); |
| |
| assert.strictEqual(webdriver.atoms.element.getAttribute(element, 'style'), ''); |
| }); |
| |
| QUnit.test('should fall back to using attribute if property available but not set', function(assert) { |
| var element = bot.locators.findElement({id: 'body'}); |
| |
| assert.strictEqual(webdriver.atoms.element.getAttribute(element, 'name'), 'body'); |
| }); |
| |
| QUnit.test('should return the value of the disabled attribute as null if not set', function(assert) { |
| var notInput = bot.locators.findElement({id: 'has_id'}); |
| assert.strictEqual(webdriver.atoms.element.getAttribute(notInput, 'disabled'), null); |
| |
| var enabled = bot.locators.findElement({id: 'normal'}); |
| assert.strictEqual(webdriver.atoms.element.getAttribute(enabled, 'disabled'), null); |
| |
| var broken = bot.locators.findElement({id: 'disabled'}); |
| assert.strictEqual(webdriver.atoms.element.getAttribute(broken, 'disabled'), "true"); |
| }); |
| |
| QUnit.test('the top windows title should not be considered visible text', function(assert) { |
| var title = bot.locators.findElement({tagName: 'title'}); |
| assert.strictEqual(webdriver.atoms.element.getText(title), ''); |
| }); |
| |
| QUnit.test('a frame documents title should not be considered visible text', function(assert) { |
| var frameDoc = bot.locators.findElement({id: 'frame_page_frame'}).contentWindow.document; |
| var title = bot.locators.findElement({tagName: 'title'}, frameDoc); |
| assert.strictEqual(frameDoc.title, 'frame page'); |
| assert.strictEqual(webdriver.atoms.element.getText(title), ''); |
| }); |
| |
| QUnit.test('can get visible text', function(assert) { |
| var para = bot.locators.findElement({id: 'has_id'}); |
| assert.strictEqual(webdriver.atoms.element.getText(para), 'This has an ID'); |
| }); |
| |
| QUnit.test('will return value of index for an option even if not declared', function(assert) { |
| var select = bot.locators.findElement({id: 'multi'}); |
| var options = bot.locators.findElements({tagName: 'option'}); |
| assert.strictEqual(webdriver.atoms.element.getAttribute(options[1], 'index'), "1"); |
| }); |
| |
| QUnit.test('should return the protocol of an image', function(assert) { |
| var image = bot.locators.findElement({id: 'image'}); |
| var url = webdriver.atoms.element.getAttribute(image, 'src'); |
| assert.ok(url.indexOf('http') == 0, url); |
| }); |
| |
| QUnit.test('should return null when getting src attribute of invalid image tag', function(assert) { |
| var image = bot.locators.findElement({id: 'invalidImgTag'}); |
| var url = webdriver.atoms.element.getAttribute(image, 'src'); |
| assert.strictEqual(url, null); |
| }); |
| |
| QUnit.test('should return null for non present boolean attribute', function(assert) { |
| var el = document.getElementById('disabled'); |
| assert.strictEqual(webdriver.atoms.element.getAttribute(el, 'required'), null); |
| }); |
| |
| QUnit.test('should return true for boolean property', function(assert) { |
| var el = document.getElementById('image'); |
| assert.strictEqual(webdriver.atoms.element.getAttribute(el, 'complete'), 'true'); |
| }); |
| |
| QUnit.test('should return true for specified boolean property', function(assert) { |
| var el = document.getElementById('nowrap'); |
| assert.strictEqual(webdriver.atoms.element.getAttribute(el, 'nowrap'), 'true'); |
| }); |
| |
| QUnit.test('should return false for spellcheck false', function(assert) { |
| var el = document.getElementById('nospell'); |
| assert.strictEqual(webdriver.atoms.element.getAttribute(el, 'spellcheck'), 'false'); |
| }); |
| |
| QUnit.test('should return true for spellcheck true', function(assert) { |
| var el = document.getElementById('spell'); |
| assert.strictEqual(webdriver.atoms.element.getAttribute(el, 'spellcheck'), 'true'); |
| }); |
| |
| QUnit.test('should return true for spellcheck undefined', function(assert) { |
| var el = document.getElementById('normal'); |
| var defaultSpellcheck = 'false'; |
| if (goog.userAgent.WEBKIT) { |
| defaultSpellcheck = 'true'; |
| } |
| if (goog.userAgent.IE && !goog.userAgent.product.isVersion(10)) { |
| defaultSpellcheck = 'undefined'; |
| } |
| assert.strictEqual(webdriver.atoms.element.getAttribute(el, 'spellcheck'), defaultSpellcheck); |
| }); |
| |
| var newLine = bot.userAgent.IE_DOC_PRE9 ? '\r\n' : '\n'; |
| |
| QUnit.test('typing enter key on text area', function(assert) { |
| var el = document.getElementById('textarea'); |
| el.value = ''; |
| webdriver.atoms.element.type(el, |
| ['hello', webdriver.Key.ENTER, webdriver.Key.ENTER, 'world']); |
| assert.strictEqual(el.value, 'hello' + newLine + newLine + 'world'); |
| }); |
| |
| QUnit.test('typing newline on text area', function(assert) { |
| var el = document.getElementById('textarea'); |
| el.value = ''; |
| webdriver.atoms.element.type(el, ['hello\n\nworld']); |
| assert.strictEqual(el.value, 'hello' + newLine + newLine + 'world'); |
| }); |
| |
| QUnit.test('can use null key to release modifiers - modifiers not persisted', function(assert) { |
| var el = document.getElementById('textarea'); |
| el.value = ''; |
| webdriver.atoms.element.type( |
| el, ['abc', webdriver.Key.SHIFT, 'def', webdriver.Key.NULL, 'ghi']); |
| assert.strictEqual(el.value, 'abcDEFghi'); |
| }); |
| |
| QUnit.test('can use null key to release modifiers - modifiers persisted', function(assert) { |
| var keyboard = new bot.Keyboard(); |
| var el = document.getElementById('textarea'); |
| el.value = ''; |
| webdriver.atoms.element.type( |
| el, ['abc', webdriver.Key.SHIFT, 'def'], keyboard, true); |
| assert.strictEqual(el.value, 'abcDEF'); |
| |
| webdriver.atoms.element.type( |
| el, ['ghi', webdriver.Key.NULL, 'jkl'], keyboard, true); |
| assert.strictEqual(el.value, 'abcDEFGHIjkl'); |
| }); |
| </script> |
| </head> |
| <body id="body" class="c" style="" name="body"> |
| <div id="qunit"></div> |
| <div id="qunit-fixture"></div> |
| |
| <p id="has_id" title="cheese">This has an ID</p> |
| |
| <textarea id="has_property" rows="2">This is an example</textarea> |
| <textarea id="textarea"></textarea> |
| |
| <form action="#" name="fishy"> |
| <input type="text" id="normal"> |
| <input type="text" id="ro" readonly> |
| <input type="text" id="bad-ro" readonly="false"> |
| <input disabled id="disabled"> |
| |
| <input type="radio" id="unselected-radio" name="fishy">Fishy |
| <input type="radio" id="selected-radio" name="fishy" checked="true">Dishy |
| <input type="radio" name="fishy">Cheesy too |
| |
| <select multiple='multiple' name="multi"> |
| <option id="selected-option" selected=true>Selected</option> |
| <option id="unselected-option">Unselected</option> |
| <option>Ham</option> |
| <option selected="selected">Sausages</option> |
| <option>Onion gravy</option> |
| </select> |
| </select> |
| |
| <input id="nospell" spellcheck="false"/> |
| <input id="spell" spellcheck="true"/> |
| </form> |
| |
| <img src="kitten.jpg" id="image"> |
| <!-- Here comes an invalid <img> tag which has no src attribute ... --> |
| <img id="invalidImgTag" /> |
| |
| <div style="background-color: green" id="green">This is a green div</div> |
| <div id="nowrap" nowrap>Unwrappable</div> |
| |
| <iframe name="frame_page" id="frame_page_frame" src="frame_page.html"></iframe> |
| </body> |
| </html> |