SandboxTest.java
1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package pl.labno.bernard.htmlunified;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.CollectingAlertHandler;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.util.ArrayList;
public class SandboxTest {
@Test
public void testClickImage() throws IOException {
final WebClient client = new WebClient(BrowserVersion.FIREFOX_3_6);
client.setAjaxController(new NicelyResynchronizingAjaxController());
HtmlPage page = (HtmlPage) client.getPage("file:./target/test-classes/sandbox.html");
Assert.assertEquals("elementToHide", page.getElementById("elementToHide").asText());
page.getElementById("close").click();
Assert.assertEquals("", page.getElementById("elementToHide").asText());
}
@Test
public void testClickJQueryBoundElement() throws IOException {
final WebClient client = new WebClient(BrowserVersion.FIREFOX_3_6);
client.setAjaxController(new NicelyResynchronizingAjaxController());
HtmlPage page = (HtmlPage) client.getPage("file:./target/test-classes/sandbox.html");
final ArrayList<String> alerts = new ArrayList<String>();
client.setAlertHandler(new CollectingAlertHandler(alerts));
page.getElementById("clickable").click();
System.out.println(alerts);
Assert.assertEquals(1, alerts.size());
Assert.assertEquals("Clicked clickable", alerts.get(0));
alerts.clear();
page.getElementById("clickable2child").click();
System.out.println(alerts);
Assert.assertEquals(1, alerts.size());
Assert.assertEquals("Clicked clickable2", alerts.get(0));
}
}