Java Code Examples for com.gargoylesoftware.htmlunit.html.HtmlAnchor#setAttribute()

The following examples show how to use com.gargoylesoftware.htmlunit.html.HtmlAnchor#setAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DemoApplicationTests.java    From keycloak-springsecurity5-sample with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void requestAuthorizeClientWhenInvalidClientThenStatusBadRequest() throws Exception {
	HtmlPage page = this.webClient.getPage("/");

	ClientRegistration clientRegistration = this.clientRegistrationRepository.findByRegistrationId("google");

	HtmlAnchor clientAnchorElement = this.getClientAnchorElement(page, clientRegistration);
	assertThat(clientAnchorElement).isNotNull();
	clientAnchorElement.setAttribute("href", clientAnchorElement.getHrefAttribute() + "-invalid");

	WebResponse response = null;
	try {
		clientAnchorElement.click();
	} catch (FailingHttpStatusCodeException ex) {
		response = ex.getResponse();
	}

	assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value());
}
 
Example 2
Source File: HelperUser.java    From CodeDefenders with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns the landing HtmlPage after joining the game
 *
 * @param gameID
 * @param isAttacker
 * @return
 * @throws FailingHttpStatusCodeException
 * @throws IOException
 */
public HtmlPage joinOpenGame(int gameID, boolean isAttacker) throws FailingHttpStatusCodeException, IOException {
	HtmlPage openGames = browser.getPage(codedefendersHome + Paths.GAMES_OVERVIEW);

	// Really we can simply click on that link once we know the gameID,
	// no need to go to openGame page
	HtmlAnchor joinLink = null;
	for (HtmlAnchor a : openGames.getAnchors()) {
		if (a.getHrefAttribute()
				.contains(Paths.BATTLEGROUND_GAME + "?" + ((isAttacker) ? "attacker" : "defender") + "=1&gameId=" + gameID)) {
			joinLink = a;
			break;
		}
	}
	if (!joinLink.getHrefAttribute().startsWith(codedefendersHome + "/")) {
		joinLink.setAttribute("href", codedefendersHome + "/" + joinLink.getHrefAttribute());
	}

	return joinLink.click();
}
 
Example 3
Source File: HelperUser.java    From CodeDefenders with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void claimEquivalenceOnLine(int gameId, int line)
		throws FailingHttpStatusCodeException, MalformedURLException, IOException {
	HtmlPage playPage = browser.getPage(codedefendersHome + "" + Paths.BATTLEGROUND_GAME + "?gameId=" + gameId);
	HtmlAnchor claimEquivalenceLink = null;
	for (HtmlAnchor a : playPage.getAnchors()) {
		if (a.getHrefAttribute().contains(Paths.BATTLEGROUND_GAME + "?equivLines=" + line)) {
			claimEquivalenceLink = a;
			break;
		}
	}

	if (!claimEquivalenceLink.getHrefAttribute().startsWith(codedefendersHome + "/")) {
		claimEquivalenceLink.setAttribute("href",
				codedefendersHome + "/" + claimEquivalenceLink.getHrefAttribute());
	}
	claimEquivalenceLink.click();
}
 
Example 4
Source File: HelperUser.java    From CodeDefenders with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void acceptEquivalence(int gameId)
		throws FailingHttpStatusCodeException, MalformedURLException, IOException {
	// codedefendersHome+"/multiplayer/
	HtmlPage playPage = browser.getPage(codedefendersHome + "" + Paths.BATTLEGROUND_GAME + "?gameId=" + gameId);
	HtmlAnchor acceptEquivalenceLink = null;
	for (HtmlAnchor a : playPage.getAnchors()) {
		if (a.getHrefAttribute().contains(Paths.BATTLEGROUND_GAME + "?acceptEquivalent=")) {
			acceptEquivalenceLink = a;
			break;
		}
	}

	if (!acceptEquivalenceLink.getHrefAttribute().startsWith(codedefendersHome + "/")) {
		acceptEquivalenceLink.setAttribute("href",
				codedefendersHome + "/" + acceptEquivalenceLink.getHrefAttribute());
	}

	System.out
			.println("DoubleEquivalenceSubmissionTest.HelperUser.acceptEquivalence() Accepting equivalence on game "
					+ gameId);
	acceptEquivalenceLink.click();
}
 
Example 5
Source File: DoubleEquivalenceSubmissionTest.java    From CodeDefenders with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void joinOpenGame(int gameID, boolean isAttacker) throws FailingHttpStatusCodeException, IOException {
	HtmlPage openGames = browser.getPage("http://localhost:8080" + Paths.GAMES_OVERVIEW);

	// Really we can simply click on that link once we know the gameID,
	// no need to go to openGame page
	HtmlAnchor joinLink = null;
	for (HtmlAnchor a : openGames.getAnchors()) {
		if (a.getHrefAttribute().contains(
				Paths.BATTLEGROUND_GAME + "?" + ((isAttacker) ? "attacker" : "defender") + "=1&gameId=" + gameID)) {
			joinLink = a;
			break;
		}
	}
	if (!joinLink.getHrefAttribute().startsWith("http://localhost:8080/")) {
		joinLink.setAttribute("href", "http://localhost:8080/" + joinLink.getHrefAttribute());
	}
	HtmlPage page = joinLink.click();
}
 
Example 6
Source File: DoubleEquivalenceSubmissionTest.java    From CodeDefenders with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void claimEquivalenceOnLine(int gameId, int line)
		throws FailingHttpStatusCodeException, MalformedURLException, IOException {
	HtmlPage playPage = browser.getPage("http://localhost:8080" + Paths.BATTLEGROUND_GAME + "?gameId=" + gameId);
	HtmlAnchor claimEquivalenceLink = null;
	for (HtmlAnchor a : playPage.getAnchors()) {
		if (a.getHrefAttribute().contains(Paths.BATTLEGROUND_GAME + "?equivLines=" + line)) {
			claimEquivalenceLink = a;
			break;
		}
	}

	if (!claimEquivalenceLink.getHrefAttribute().startsWith("http://localhost:8080/")) {
		claimEquivalenceLink.setAttribute("href",
				"http://localhost:8080/" + claimEquivalenceLink.getHrefAttribute());
	}
	claimEquivalenceLink.click();
}
 
Example 7
Source File: DoubleEquivalenceSubmissionTest.java    From CodeDefenders with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void acceptEquivalence(int gameId)
		throws FailingHttpStatusCodeException, MalformedURLException, IOException {
	// http://localhost:8080/multiplayer/
	HtmlPage playPage = browser.getPage("http://localhost:8080" + Paths.BATTLEGROUND_GAME + "?gameId=" + gameId);
	HtmlAnchor acceptEquivalenceLink = null;
	for (HtmlAnchor a : playPage.getAnchors()) {
		if (a.getHrefAttribute().contains(Paths.BATTLEGROUND_GAME + "?acceptEquivalent=")) {
			acceptEquivalenceLink = a;
			break;
		}
	}

	if (!acceptEquivalenceLink.getHrefAttribute().startsWith("http://localhost:8080/")) {
		acceptEquivalenceLink.setAttribute("href",
				"http://localhost:8080/" + acceptEquivalenceLink.getHrefAttribute());
	}

	System.out.println(
			"DoubleEquivalenceSubmissionTest.HelperUser.acceptEquivalence() Accepting equivalence on game "
					+ gameId);
	acceptEquivalenceLink.click();
}