Search in sources :

Example 6 with HtmlRadioButtonInput

use of com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput in project security by jakartaee.

the class OpenId2DefaultIT method testOpenIdConnect.

@Test
@RunAsClient
public void testOpenIdConnect() throws IOException {
    // 1. Public servlet should be accessible for an unauthenticated user
    assertDefaultNotAuthenticated(readFromServer("/publicServlet"));
    // 2. Access to secured web page redirects us to OpenID Connect Provider's login page
    // Look at redirect:
    getWebClient().getOptions().setRedirectEnabled(false);
    WebResponse response = responseFromServer("/protectedServlet");
    for (NameValuePair header : response.getResponseHeaders()) {
        System.out.println("name: " + header.getName() + " : " + header.getValue());
    }
    // Automatically follow redirects and request secured page again
    getWebClient().getOptions().setRedirectEnabled(true);
    // 3. We should now see the login page from the OpenId Provider
    HtmlPage providerLoginPage = pageFromServer("/protectedServlet");
    printPage(providerLoginPage);
    // Authenticate with the OpenId Provider using the username and password for a default user
    providerLoginPage.getElementById("j_username").setAttribute("value", "user");
    providerLoginPage.getElementById("j_password").setAttribute("value", "password");
    // 4. We should now get a confirmation page, which we acknowledge.
    HtmlPage confirmationPage = providerLoginPage.getElementByName("submit").click();
    printPage(confirmationPage);
    // Set to "remember-not" to make tests easily repeatable. If we don't set this without restarting the OpenID Provider
    // we would not get the confirmation page next time.
    HtmlRadioButtonInput radioButton = (HtmlRadioButtonInput) confirmationPage.getElementById("remember-not");
    radioButton.setChecked(true);
    // 5. After authenticating and confirmation, we are now redirected back to our application.
    // A servlet on the /callBack URI is called.
    TextPage callbackPage = confirmationPage.getElementByName("authorize").click();
    printPage(callbackPage);
    assertTrue(callbackPage.getContent().contains("This is the callback servlet"));
    // 6. Access protected servlet as an authenticated user
    assertAuthenticated("web", "user", readFromServer("/protectedServlet"), "foo", "bar");
    // 7. Finally, access should still be allowed to a public web page when already logged in
    assertAuthenticated("web", "user", readFromServer("/publicServlet"), "foo", "bar");
}
Also used : NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) TextPage(com.gargoylesoftware.htmlunit.TextPage) HtmlRadioButtonInput(com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test)

Example 7 with HtmlRadioButtonInput

use of com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput in project faces by jakartaee.

the class Issue2408IT method getRadios.

private List<HtmlRadioButtonInput> getRadios(final HtmlPage page) {
    final List<HtmlRadioButtonInput> radios = new ArrayList<>();
    final DomNodeList<DomElement> elements = page.getElementsByTagName("input");
    for (DomElement elem : elements) {
        if (elem instanceof HtmlRadioButtonInput) {
            radios.add((HtmlRadioButtonInput) elem);
        }
    }
    return radios;
}
Also used : DomElement(com.gargoylesoftware.htmlunit.html.DomElement) ArrayList(java.util.ArrayList) HtmlRadioButtonInput(com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput)

Example 8 with HtmlRadioButtonInput

use of com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput in project faces by jakartaee.

the class Spec329IT method testSpec329.

/**
 * @see HtmlSelectOneRadio#getGroup()
 * @see https://github.com/jakartaee/faces/issues/329
 */
@Test
public void testSpec329() throws Exception {
    HtmlPage page = webClient.getPage(webUrl + "spec329.xhtml");
    assertTrue(page.getHtmlElementById("messages").asNormalizedText().isEmpty());
    assertTrue(page.getHtmlElementById("inDataTableWithEntityList:selectedItem").asNormalizedText().isEmpty());
    assertTrue(page.getHtmlElementById("inRepeatWithSelectItemList:selectedItem").asNormalizedText().isEmpty());
    assertTrue(page.getHtmlElementById("multipleRadioButtonsWithStaticItemsInFirstRadio:selectedItem").asNormalizedText().isEmpty());
    assertTrue(page.getHtmlElementById("multipleRadioButtonsWithStaticItemsInEachRadio:selectedItem").asNormalizedText().isEmpty());
    assertTrue(page.getHtmlElementById("multipleRadioButtonsWithSelectItemList:selectedItem").asNormalizedText().isEmpty());
    page = ((HtmlSubmitInput) page.getHtmlElementById("inDataTableWithEntityList:button")).click();
    // It should appear only once!
    assertEquals("required", page.getHtmlElementById("messages").asNormalizedText());
    HtmlRadioButtonInput inDataTableWithEntityListRadio = (HtmlRadioButtonInput) page.getHtmlElementById("inDataTableWithEntityList:table:1:radio");
    inDataTableWithEntityListRadio.setChecked(true);
    page = ((HtmlSubmitInput) page.getHtmlElementById("inDataTableWithEntityList:button")).click();
    System.out.println("\n\n***** " + page.getHtmlElementById("messages").asNormalizedText() + "\n\n\n");
    assertTrue(page.getHtmlElementById("messages").asNormalizedText().isEmpty());
    assertEquals("two", page.getHtmlElementById("inDataTableWithEntityList:selectedItem").asNormalizedText());
    page = ((HtmlSubmitInput) page.getHtmlElementById("inRepeatWithSelectItemList:button")).click();
    // It should appear only once!
    assertEquals("required", page.getHtmlElementById("messages").asNormalizedText());
    HtmlRadioButtonInput inRepeatWithSelectItemListRadio = (HtmlRadioButtonInput) page.getHtmlElementById("inRepeatWithSelectItemList:repeat:1:radio");
    inRepeatWithSelectItemListRadio.setChecked(true);
    page = ((HtmlSubmitInput) page.getHtmlElementById("inRepeatWithSelectItemList:button")).click();
    assertTrue(page.getHtmlElementById("messages").asNormalizedText().isEmpty());
    assertEquals("value2", page.getHtmlElementById("inRepeatWithSelectItemList:selectedItem").asNormalizedText());
    page = ((HtmlSubmitInput) page.getHtmlElementById("multipleRadioButtonsWithStaticItemsInFirstRadio:button")).click();
    // It should appear only once for first component!
    assertEquals("required1", page.getHtmlElementById("messages").asNormalizedText());
    HtmlRadioButtonInput multipleRadioButtonsWithStaticItemsInFirstRadio = (HtmlRadioButtonInput) page.getHtmlElementById("multipleRadioButtonsWithStaticItemsInFirstRadio:radio2");
    multipleRadioButtonsWithStaticItemsInFirstRadio.setChecked(true);
    page = ((HtmlSubmitInput) page.getHtmlElementById("multipleRadioButtonsWithStaticItemsInFirstRadio:button")).click();
    assertTrue(page.getHtmlElementById("messages").asNormalizedText().isEmpty());
    assertEquals("two", page.getHtmlElementById("multipleRadioButtonsWithStaticItemsInFirstRadio:selectedItem").asNormalizedText());
    page = ((HtmlSubmitInput) page.getHtmlElementById("multipleRadioButtonsWithStaticItemsInEachRadio:button")).click();
    // It should appear only once for first component!
    assertEquals("required1", page.getHtmlElementById("messages").asNormalizedText());
    HtmlRadioButtonInput multipleRadioButtonsWithStaticItemsInEachRadio = (HtmlRadioButtonInput) page.getHtmlElementById("multipleRadioButtonsWithStaticItemsInEachRadio:radio2");
    multipleRadioButtonsWithStaticItemsInEachRadio.setChecked(true);
    page = ((HtmlSubmitInput) page.getHtmlElementById("multipleRadioButtonsWithStaticItemsInEachRadio:button")).click();
    assertTrue(page.getHtmlElementById("messages").asNormalizedText().isEmpty());
    assertEquals("two", page.getHtmlElementById("multipleRadioButtonsWithStaticItemsInEachRadio:selectedItem").asNormalizedText());
    page = ((HtmlSubmitInput) page.getHtmlElementById("multipleRadioButtonsWithSelectItemList:button")).click();
    // It should appear only once for first component!
    assertEquals("required1", page.getHtmlElementById("messages").asNormalizedText());
    HtmlRadioButtonInput multipleRadioButtonsWithSelectItemListRadio = (HtmlRadioButtonInput) page.getHtmlElementById("multipleRadioButtonsWithSelectItemList:radio2");
    multipleRadioButtonsWithSelectItemListRadio.setChecked(true);
    page = ((HtmlSubmitInput) page.getHtmlElementById("multipleRadioButtonsWithSelectItemList:button")).click();
    assertTrue(page.getHtmlElementById("messages").asNormalizedText().isEmpty());
    assertEquals("value2", page.getHtmlElementById("multipleRadioButtonsWithSelectItemList:selectedItem").asNormalizedText());
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlRadioButtonInput(com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput) Test(org.junit.Test)

Example 9 with HtmlRadioButtonInput

use of com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput in project security by jakartaee.

the class OpenId3DefaultIT method testOpenIdConnect.

@Test
@RunAsClient
public void testOpenIdConnect() throws IOException {
    // 1. Public servlet should be accessible for an unauthenticated user
    assertDefaultNotAuthenticated(readFromServer("/publicServlet"));
    // 2. Access to secured web page redirects us to OpenID Connect Provider's login page
    HtmlPage providerLoginPage = pageFromServer("/protectedServlet");
    printPage(providerLoginPage);
    // Authenticate with the OpenId Provider using the username and password for a default user
    providerLoginPage.getElementById("j_username").setAttribute("value", "user");
    providerLoginPage.getElementById("j_password").setAttribute("value", "password");
    // 3. We should now get a confirmation page, which we acknowledge.
    HtmlPage confirmationPage = providerLoginPage.getElementByName("submit").click();
    printPage(confirmationPage);
    // Set to "remember-not" to make tests easily repeatable. If we don't set this without restarting the OpenID Provider
    // we would not get the confirmation page next time.
    HtmlRadioButtonInput radioButton = (HtmlRadioButtonInput) confirmationPage.getElementById("remember-not");
    radioButton.setChecked(true);
    // 4. After authenticating and confirmation, we are now redirected back to our original resource
    TextPage originalPage = confirmationPage.getElementByName("authorize").click();
    assertAuthenticated("web", "user", originalPage.getContent(), "foo", "bar");
    // 5. Finally, access should still be allowed to a public web page when already logged in
    assertAuthenticated("web", "user", readFromServer("/publicServlet"), "foo", "bar");
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) TextPage(com.gargoylesoftware.htmlunit.TextPage) HtmlRadioButtonInput(com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test)

Example 10 with HtmlRadioButtonInput

use of com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput in project faces by jakartaee.

the class Issue2340IT method testCommandLinkRadio.

/**
 * @see AjaxBehavior
 * @see HtmlCommandLink
 * @see HtmlSelectOneRadio
 * @see https://github.com/eclipse-ee4j/mojarra/issues/2344
 */
@Test
public void testCommandLinkRadio() throws Exception {
    HtmlPage page = getPage("commandLinkRadio.xhtml");
    HtmlAnchor anchor = (HtmlAnchor) page.getElementById("testLink");
    // This will ensure JavaScript finishes before evaluating the page.
    webClient.waitForBackgroundJavaScript(3000);
    anchor.click();
    webClient.waitForBackgroundJavaScript(3000);
    assertTrue(page.asXml().contains("LINK ACTION"));
    HtmlRadioButtonInput radio1 = (HtmlRadioButtonInput) page.getElementById("testRadio:0");
    HtmlRadioButtonInput radio2 = (HtmlRadioButtonInput) page.getElementById("testRadio:1");
    HtmlRadioButtonInput radio3 = (HtmlRadioButtonInput) page.getElementById("testRadio:2");
    page = radio1.click();
    webClient.waitForBackgroundJavaScript(3000);
    assertTrue(page.asXml().contains("RADIO:red"));
    page = radio2.click();
    webClient.waitForBackgroundJavaScript(3000);
    assertTrue(page.asXml().contains("RADIO:blue"));
    page = radio3.click();
    webClient.waitForBackgroundJavaScript(3000);
    assertTrue(page.asXml().contains("RADIO:white"));
}
Also used : HtmlAnchor(com.gargoylesoftware.htmlunit.html.HtmlAnchor) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlRadioButtonInput(com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput) Test(org.junit.Test)

Aggregations

HtmlRadioButtonInput (com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput)16 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)11 Test (org.junit.Test)8 HtmlCheckBoxInput (com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput)6 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)4 HtmlButton (com.gargoylesoftware.htmlunit.html.HtmlButton)4 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)4 HtmlInput (com.gargoylesoftware.htmlunit.html.HtmlInput)4 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)3 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)3 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)2 TextPage (com.gargoylesoftware.htmlunit.TextPage)2 StyleElement (com.gargoylesoftware.htmlunit.css.StyleElement)2 BaseFrameElement (com.gargoylesoftware.htmlunit.html.BaseFrameElement)2 HtmlAnchor (com.gargoylesoftware.htmlunit.html.HtmlAnchor)2 HtmlButtonInput (com.gargoylesoftware.htmlunit.html.HtmlButtonInput)2 HtmlTextArea (com.gargoylesoftware.htmlunit.html.HtmlTextArea)2 Element (com.gargoylesoftware.htmlunit.javascript.host.Element)2 HTMLBodyElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLBodyElement)2 HTMLCanvasElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCanvasElement)2