Skip to content

Commit

Permalink
Throwing an error with the proper code on empty class name
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Jan 1, 2014
1 parent e01454b commit 6cc6c8c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
26 changes: 19 additions & 7 deletions java/client/test/org/openqa/selenium/ElementFindingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebElement> elements = driver.findElements(By.name("nonExistentButton"));
List<WebElement> 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
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions javascript/atoms/locators/classname.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6cc6c8c

Please sign in to comment.