Blame view

src/test/java/pl/labno/bernard/htmlunified/SandboxTest.java 1.85 KB
bernard authored
1 2 3
package pl.labno.bernard.htmlunified;

import com.gargoylesoftware.htmlunit.BrowserVersion;
bernard authored
4
import com.gargoylesoftware.htmlunit.CollectingAlertHandler;
bernard authored
5 6 7 8 9 10 11
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;
bernard authored
12
import java.util.ArrayList;
bernard authored
13 14 15 16

public class SandboxTest {

    @Test
bernard authored
17
    public void testClickImage() throws IOException {
bernard authored
18 19 20 21 22 23 24
        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());
    }
bernard authored
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

    @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));
    }
bernard authored
44
}