From 6cc6c8c6975b0c8b1370b97a077e5dbcc23c02ea Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Wed, 1 Jan 2014 22:53:28 +0400 Subject: [PATCH] Throwing an error with the proper code on empty class name --- .../openqa/selenium/ElementFindingTest.java | 26 ++++++++++++++----- javascript/atoms/locators/classname.js | 6 +++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/java/client/test/org/openqa/selenium/ElementFindingTest.java b/java/client/test/org/openqa/selenium/ElementFindingTest.java index 2a49e71a47416..0616fec66fa33 100644 --- a/java/client/test/org/openqa/selenium/ElementFindingTest.java +++ b/java/client/test/org/openqa/selenium/ElementFindingTest.java @@ -180,43 +180,43 @@ public void testShouldBeAbleToFindMultipleElementsByTagName() { assertThat(elements.size(), greaterThan(1)); } - // By.name negative + // By.tagName negative @Test(expected = NoSuchElementException.class) public void testShouldNotBeAbleToLocateByTagNameASingleElementThatDoesNotExist() { driver.get(pages.formPage); - driver.findElement(By.name("nonExistentButton")); + driver.findElement(By.tagName("nonExistentButton")); } @Test public void testShouldNotBeAbleToLocateByTagNameMultipleElementsThatDoNotExist() { driver.get(pages.formPage); - List elements = driver.findElements(By.name("nonExistentButton")); + List elements = driver.findElements(By.tagName("nonExistentButton")); assertThat(elements.size(), is(0)); } @Test(expected = NoSuchElementException.class) public void testFindingASingleElementByEmptyTagNameShouldThrow() { driver.get(pages.formPage); - driver.findElement(By.name("")); + driver.findElement(By.tagName("")); } @Test(expected = NoSuchElementException.class) public void testFindingMultipleElementsByEmptyTagNameShouldThrow() { driver.get(pages.formPage); - driver.findElement(By.name("")); + driver.findElement(By.tagName("")); } @Test(expected = NoSuchElementException.class) public void testFindingASingleElementByTagNameWithSpaceShouldThrow() { driver.get(pages.formPage); - driver.findElement(By.name("nonexistent button")); + driver.findElement(By.tagName("nonexistent button")); } @Test(expected = NoSuchElementException.class) public void testFindingMultipleElementsByTagNameWithSpaceShouldThrow() { driver.get(pages.formPage); - driver.findElement(By.name("nonexistent button")); + driver.findElement(By.tagName("nonexistent button")); } // By.className positive @@ -279,6 +279,18 @@ public void testShouldNotFindElementByClassWhenTheNameQueriedIsShorterThanCandid driver.findElement(By.className("nameB")); } + @Test(expected = InvalidSelectorException.class) + public void testFindingASingleElementByEmptyClassNameShouldThrow() { + driver.get(pages.xhtmlTestPage); + driver.findElement(By.className("")); + } + + @Test(expected = InvalidSelectorException.class) + public void testFindingMultipleElementsByEmptyClassNameShouldThrow() { + driver.get(pages.xhtmlTestPage); + driver.findElements(By.className("")); + } + @Test(expected = InvalidSelectorException.class) public void testFindingASingleElementByCompoundClassNameShouldThrow() { driver.get(pages.xhtmlTestPage); diff --git a/javascript/atoms/locators/classname.js b/javascript/atoms/locators/classname.js index baa73bab484e3..4b6bab3b0e99c 100644 --- a/javascript/atoms/locators/classname.js +++ b/javascript/atoms/locators/classname.js @@ -47,7 +47,8 @@ bot.locators.className.canUseQuerySelector_ = function(root) { */ bot.locators.className.single = function(target, root) { if (!target) { - throw Error('No class name specified'); + throw new bot.Error(bot.ErrorCode.INVALID_SELECTOR_ERROR, + 'No class name specified'); } target = goog.string.trim(target); @@ -76,7 +77,8 @@ bot.locators.className.single = function(target, root) { */ bot.locators.className.many = function(target, root) { if (!target) { - throw Error('No class name specified'); + throw new bot.Error(bot.ErrorCode.INVALID_SELECTOR_ERROR, + 'No class name specified'); } target = goog.string.trim(target);