| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <title>child_locator_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('goog.dom'); |
| goog.require('goog.events.EventType'); |
| goog.require('bot'); |
| goog.require('bot.dom'); |
| goog.require('bot.locators'); |
| </script> |
| |
| <script type="text/javascript"> |
| QUnit.test('can find child element by class name', function(assert) { |
| var parent = bot.locators.findElement({id: 'parent'}); |
| var child = bot.locators.findElement({className: 'child'}, parent); |
| |
| assert.strictEqual(goog.dom.getTextContent(child), 'Child 1'); |
| }); |
| |
| QUnit.test('can find child elements by class name', function(assert) { |
| var parent = bot.locators.findElement({id: 'parent'}); |
| var children = bot.locators.findElements({className: 'child'}, parent); |
| |
| assert.strictEqual(children.length, 3); |
| assert.strictEqual(goog.dom.getTextContent(children[0]), 'Child 1'); |
| assert.strictEqual(goog.dom.getTextContent(children[2]), 'Child 3'); |
| }); |
| |
| QUnit.test('find single by class name - target class has dots', function(assert) { |
| var parent = bot.locators.findElement({id: 'parent'}); |
| var found = bot.locators.findElement({className: 'name.with.dots'}, parent); |
| assert.strictEqual(found, goog.dom.$('dotted_1')); |
| }); |
| |
| QUnit.test('find many by class name - target class has dot', function(assert) { |
| var parent = bot.locators.findElement({id: 'parent'}); |
| var found = bot.locators.findElements({className: 'name.with.dots'}, parent); |
| assert.strictEqual(found.length, 2); |
| assert.strictEqual(found[0], goog.dom.$('dotted_1')); |
| assert.strictEqual(found[1], goog.dom.$('dotted_2')); |
| }); |
| |
| |
| QUnit.test('can find child element by css', function(assert) { |
| if (!document['querySelector']) { |
| assert.ok(true, 'Skipping: querySelector not supported'); |
| return; |
| } |
| |
| var parent = bot.locators.findElement({id: 'parent'}); |
| var child = bot.locators.findElement({css: '.child'}, parent); |
| |
| assert.strictEqual(goog.dom.getTextContent(child), 'Child 1'); |
| }); |
| |
| QUnit.test('can find child elements by css', function(assert) { |
| if (!document['querySelectorAll']) { |
| assert.ok(true, 'Skipping: querySelectorAll not supported'); |
| return; |
| } |
| |
| var parent = bot.locators.findElement({id: 'parent'}); |
| var children = bot.locators.findElements({css: '.child'}, parent); |
| |
| assert.strictEqual(children.length, 3); |
| assert.strictEqual(goog.dom.getTextContent(children[0]), 'Child 1'); |
| assert.strictEqual(goog.dom.getTextContent(children[2]), 'Child 3'); |
| }); |
| |
| QUnit.test('can find child element by id', function(assert) { |
| var parent = bot.locators.findElement({id: 'parent'}); |
| var child = bot.locators.findElement({id: 'child'}, parent); |
| |
| assert.strictEqual(goog.dom.getTextContent(child), 'Child 1'); |
| }); |
| |
| QUnit.test('can find child elements by id', function(assert) { |
| var parent = bot.locators.findElement({id: 'parent'}); |
| var children = bot.locators.findElements({id: 'child'}, parent); |
| |
| assert.strictEqual(children.length, 3); |
| assert.strictEqual(goog.dom.getTextContent(children[0]), 'Child 1'); |
| assert.strictEqual(goog.dom.getTextContent(children[2]), 'Child 3'); |
| }); |
| |
| QUnit.test('can find child element by name', function(assert) { |
| var parent = bot.locators.findElement({id: 'parent'}); |
| var child = bot.locators.findElement({name: 'child'}, parent); |
| |
| assert.strictEqual(goog.dom.getTextContent(child), 'Child 1'); |
| }); |
| |
| QUnit.test('can find child elements by name', function(assert) { |
| var parent = bot.locators.findElement({id: 'parent'}); |
| var children = bot.locators.findElements({name: 'child'}, parent); |
| |
| assert.strictEqual(children.length, 3); |
| assert.strictEqual(goog.dom.getTextContent(children[0]), 'Child 1'); |
| assert.strictEqual(goog.dom.getTextContent(children[2]), 'Child 3'); |
| }); |
| |
| QUnit.test('can find child element by xpath', function(assert) { |
| var parent = bot.locators.findElement({id: 'parent'}); |
| var child = bot.locators.findElement({xpath: './/*[@id="child"]'}, parent); |
| |
| assert.strictEqual(goog.dom.getTextContent(child), 'Child 1'); |
| }); |
| |
| QUnit.test('can find child elements by xpath', function(assert) { |
| var parent = bot.locators.findElement({id: 'parent'}); |
| var children = bot.locators.findElements({xpath: './/*[@id="child"]'}, parent); |
| |
| assert.strictEqual(children.length, 3); |
| assert.strictEqual(goog.dom.getTextContent(children[0]), 'Child 1'); |
| assert.strictEqual(goog.dom.getTextContent(children[2]), 'Child 3'); |
| }); |
| |
| QUnit.test('can find child element by link text', function(assert) { |
| var parent = bot.locators.findElement({id: 'link-parent-a'}); |
| var link = bot.locators.findElement({linkText: 'this is a link'}, parent); |
| |
| assert.strictEqual(bot.dom.getAttribute(link, 'id'), 'link'); |
| }); |
| |
| QUnit.test('can find child elements by link text', function(assert) { |
| var parent = bot.locators.findElement({id: 'link-parent-a'}); |
| var links = bot.locators.findElements({linkText: 'this is a link'}, parent); |
| |
| assert.strictEqual(links.length, 4); |
| }); |
| |
| QUnit.test('should be able to find child links with no text', function(assert) { |
| var parent = bot.locators.findElement({id: 'link-parent-a'}); |
| |
| var link = bot.locators.findElement({linkText: ''}, parent); |
| assert.ok(link !== null); |
| assert.strictEqual(link.id, 'empty-link'); |
| |
| var links = bot.locators.findElements({linkText: ''}, parent); |
| assert.strictEqual(links.length, 1); |
| assert.strictEqual(links[0].id, 'empty-link'); |
| }); |
| |
| QUnit.test('can find child element by partial link text', function(assert) { |
| var parent = bot.locators.findElement({id: 'link-parent-a'}); |
| var link = bot.locators.findElement({partialLinkText: 'is a'}, parent); |
| |
| assert.strictEqual(bot.dom.getAttribute(link, 'id'), 'link'); |
| }); |
| |
| QUnit.test('can find child elements by partial link text', function(assert) { |
| var parent = bot.locators.findElement({id: 'link-parent-a'}); |
| var links = bot.locators.findElements({partialLinkText: 'a lin'}, parent); |
| |
| assert.strictEqual(links.length, 4); |
| }); |
| |
| QUnit.test('should match first link when link text is the empty string', function(assert) { |
| var parent = bot.locators.findElement({id: 'link-parent-a'}); |
| var link = bot.locators.findElement({partialLinkText: ''}, parent); |
| assert.ok(link !== null); |
| assert.strictEqual(link.id, 'link'); |
| }); |
| |
| QUnit.test('should find every link when link text is the empty string', function(assert) { |
| var parent = bot.locators.findElement({id: 'link-parent-a'}); |
| var links = bot.locators.findElements({partialLinkText: ''}, parent); |
| |
| assert.strictEqual(links.length, 6); |
| }); |
| |
| QUnit.test('should be able to find child element by tag name', function(assert) { |
| var parent = bot.locators.findElement({id: 'link-parent-a'}); |
| var link = bot.locators.findElement({tagName: 'A'}, parent); |
| assert.ok(link !== null); |
| assert.strictEqual(bot.dom.getAttribute(link, 'id'), 'link'); |
| }); |
| |
| QUnit.test('should be able to find child elements by tag name', function(assert) { |
| var parent = bot.locators.findElement({id: 'link-parent-a'}); |
| var links = bot.locators.findElements({tagName: 'A'}, parent); |
| assert.strictEqual(links.length, 6); |
| }); |
| </script> |
| </head> |
| <body> |
| <div id="qunit"></div> |
| <div id="qunit-fixture"></div> |
| <p name="child" id="child" class="child">Not really!</p> |
| |
| <div id="parent"> |
| <p name="child" id="child" class="child">Child 1</p> |
| <p name="child" id="child" class="child">Child 2</p> |
| <p name="child" id="child" class="child">Child 3</p> |
| <div id="dotted_1" class="name.with.dots">dotted class</div> |
| <div id="dotted_2" class="name.with.dots">another dotted class</div> |
| </div> |
| |
| <p name="child">Me either</p> |
| |
| <div id="link-parent-a"> |
| <a id="link" href="#">this is a link</a> |
| <a name="fishsticks">this is a link</a> |
| <a href="#">this is a link</a> |
| <a href="#">this is a link</a> |
| <a href="#">unrelated</a> |
| <a href="#" id="empty-link"></a> |
| </div> |
| |
| <a href="#">this is a link</a> |
| </body> |
| </html> |