Skip to content

Commit 168df0f

Browse files
committed
cleanup and more tests
1 parent b9253c1 commit 168df0f

2 files changed

Lines changed: 106 additions & 2 deletions

File tree

src/test/java/org/openqa/selenium/htmlunit/by/FindByXPathTest.java

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.junit.Test;
2323
import org.junit.runner.RunWith;
2424
import org.openqa.selenium.By;
25+
import org.openqa.selenium.InvalidSelectorException;
2526
import org.openqa.selenium.WebDriver;
2627
import org.openqa.selenium.WebElement;
2728
import org.openqa.selenium.htmlunit.WebDriverTestCase;
@@ -104,4 +105,109 @@ public void relativeElementsByXPath() throws Exception {
104105
assertEquals(1, elements.size());
105106
assertEquals("testId2", elements.get(0).getAttribute("id"));
106107
}
108+
109+
@Test(expected = InvalidSelectorException.class)
110+
public void elementsByXPathEmpty() throws Exception {
111+
final String html = "<html>\n"
112+
+ "<head>\n"
113+
+ "</head>\n"
114+
+ "<body>\n"
115+
+ " <div id='ctx'>\n"
116+
+ " <div id='testId' class='other'></div>\n"
117+
+ " <div id='testId2' class='testClass'></div>\n"
118+
+ " </div>\n"
119+
+ "</body>\n"
120+
+ "</html>\n";
121+
122+
final WebDriver driver = loadPage2(html);
123+
final WebElement ctx = driver.findElement(By.id("ctx"));
124+
ctx.findElements(By.xpath(""));
125+
}
126+
127+
@Test(expected = IllegalArgumentException.class)
128+
public void elementsByXPathNull() throws Exception {
129+
final String html = "<html>\n"
130+
+ "<head>\n"
131+
+ "</head>\n"
132+
+ "<body>\n"
133+
+ " <div id='ctx'>\n"
134+
+ " <div id='testId' class='other'></div>\n"
135+
+ " <div id='testId2' class='testClass'></div>\n"
136+
+ " </div>\n"
137+
+ "</body>\n"
138+
+ "</html>\n";
139+
140+
final WebDriver driver = loadPage2(html);
141+
final WebElement ctx = driver.findElement(By.id("ctx"));
142+
ctx.findElements(By.xpath(null));
143+
}
144+
145+
@Test(expected = InvalidSelectorException.class)
146+
public void elementsByXPathBlank() throws Exception {
147+
final String html = "<html>\n"
148+
+ "<head>\n"
149+
+ "</head>\n"
150+
+ "<body>\n"
151+
+ " <div id='ctx'>\n"
152+
+ " <div id='testId' class='other'></div>\n"
153+
+ " <div id='testId2' class='testClass'></div>\n"
154+
+ " </div>\n"
155+
+ "</body>\n"
156+
+ "</html>\n";
157+
158+
final WebDriver driver = loadPage2(html);
159+
final WebElement ctx = driver.findElement(By.id("ctx"));
160+
ctx.findElements(By.xpath(" \t "));
161+
}
162+
163+
@Test(expected = InvalidSelectorException.class)
164+
public void elementByXPathEmpty() throws Exception {
165+
final String html = "<html>\n"
166+
+ "<head>\n"
167+
+ "</head>\n"
168+
+ "<body>\n"
169+
+ " <div id='ctx'>\n"
170+
+ " <div id='testId' class='other'></div>\n"
171+
+ " <div id='testId2' class='testClass'></div>\n"
172+
+ " </div>\n"
173+
+ "</body>\n"
174+
+ "</html>\n";
175+
176+
final WebDriver driver = loadPage2(html);
177+
driver.findElement(By.xpath(""));
178+
}
179+
180+
@Test(expected = IllegalArgumentException.class)
181+
public void elementByXPathNull() throws Exception {
182+
final String html = "<html>\n"
183+
+ "<head>\n"
184+
+ "</head>\n"
185+
+ "<body>\n"
186+
+ " <div id='ctx'>\n"
187+
+ " <div id='testId' class='other'></div>\n"
188+
+ " <div id='testId2' class='testClass'></div>\n"
189+
+ " </div>\n"
190+
+ "</body>\n"
191+
+ "</html>\n";
192+
193+
final WebDriver driver = loadPage2(html);
194+
driver.findElement(By.xpath(null));
195+
}
196+
197+
@Test(expected = InvalidSelectorException.class)
198+
public void elementByXPathBlank() throws Exception {
199+
final String html = "<html>\n"
200+
+ "<head>\n"
201+
+ "</head>\n"
202+
+ "<body>\n"
203+
+ " <div id='ctx'>\n"
204+
+ " <div id='testId' class='other'></div>\n"
205+
+ " <div id='testId2' class='testClass'></div>\n"
206+
+ " </div>\n"
207+
+ "</body>\n"
208+
+ "</html>\n";
209+
210+
final WebDriver driver = loadPage2(html);
211+
driver.findElement(By.xpath(" \t "));
212+
}
107213
}

src/test/java/org/openqa/selenium/htmlunit/html/WebClient3Test.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ public void javascriptContentDetectorWithoutContentMixedCase() throws Exception
4646
*/
4747
@Test
4848
public void getPageAboutProtocol() throws Exception {
49-
final String html = "<html><body>DataUrl Test</body></html>";
50-
5149
final WebDriver driver = getWebDriver();
5250
driver.get("about:blank");
5351

0 commit comments

Comments
 (0)