Skip to content

Commit

Permalink
Finding tagName with empty string should throw InvalidSelectorException
Browse files Browse the repository at this point in the history
We have been returning a NoSuchElementException in single and [] in many
but "" leads to invalid CSS Selector which will be the standard way to
search for elements in the future.
  • Loading branch information
AutomatedTester committed Jan 20, 2016
1 parent 6ba1617 commit c431248
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions javascript/atoms/locators/tag_name.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

goog.provide('bot.locators.tagName');

goog.require('bot.Error');
goog.require('bot.ErrorCode');
goog.require('goog.array');


Expand All @@ -29,6 +31,10 @@ goog.require('goog.array');
* such element could be found.
*/
bot.locators.tagName.single = function(target, root) {
if (target === "") {
throw new bot.Error(bot.ErrorCode.INVALID_SELECTOR_ERROR,
'Unable to locate an element with the tagName ""');
}
return root.getElementsByTagName(target)[0] || null;
};

Expand All @@ -41,5 +47,9 @@ bot.locators.tagName.single = function(target, root) {
* @return {goog.array.ArrayLike} All matching elements, or an empty list.
*/
bot.locators.tagName.many = function(target, root) {
if (target === "") {
throw new bot.Error(bot.ErrorCode.INVALID_SELECTOR_ERROR,
'Unable to locate an element with the tagName ""');
}
return root.getElementsByTagName(target);
};
11 changes: 11 additions & 0 deletions javascript/atoms/test/locator_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,17 @@
assertEquals(8, links.length);
}

function testShouldThrowInvalidSelectorErrorWhenEmptyStringPassedIn() {
try {
bot.locators.findElements({tagName: ''});
fail('Should not have succeeded because the tagName is ""');
} catch (ex) {
// We expect an InvalidSelectorException because the xpath expression is
// syntactically invalid.
assertEquals(bot.ErrorCode.INVALID_SELECTOR_ERROR, ex.code);
}
}

function testCanAddANewElementLocatingStrategy() {
var expected = goog.dom.$('lion');
bot.locators.add('fixed', {
Expand Down

0 comments on commit c431248

Please sign in to comment.