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 alerts = new ArrayList();
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));
}
}