All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ch.inftec.ju.ee.webtest.WebTestUtils Maven / Gradle / Ivy

Go to download

Contains helping classes for Unit Testing, supporting CDI and EE features, including DB access

There is a newer version: 4.5.1-11
Show newest version
package ch.inftec.ju.ee.webtest;

import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.inftec.ju.util.JuUtils;
import ch.inftec.ju.util.PropertyChain;

/**
 * Utility class containing web test helper methods.
 * @author Martin
 *
 */
public class WebTestUtils {
	private static Logger logger = LoggerFactory.getLogger(WebTestUtils.class);
	
	/**
	 * Gets the full page URL for an URL specified without host and port,
	 * e.g. web-app/page.jsf. Host name and port will be resolved from the
	 * JU properties, e.g. http://localhost:8080/web-app/page.jsf
	 * 
	 * @param subPageUrl
	 *            Page URL without host an port
	 */
	public static String getPageUrl(String subPageUrl) {
		PropertyChain pc = JuUtils.getJuPropertyChain();

		String host = pc.get("ju-testing-ee.web.host");
		Integer port = pc.get("ju-testing-ee.web.port", Integer.class) + pc.get("ju-util-ee.portOffset", Integer.class);

		String url = String.format("http://%s:%d/%s", host, port, subPageUrl);
		return url;
	}

	/**
	 * Opens the specified page. The page URL must be specified without host and port,
	 * e.g. web-app/page.jsf. Host name and port will be resolved from the
	 * JU properties, e.g. http://localhost:8080/web-app/page.jsf
	 * 
	 * @param driver
	 *            WebDriver to get page for
	 * @param subPageUrl
	 *            Page URL
	 */
	public static void getPage(WebDriver driver, String subPageUrl) {
		String url = WebTestUtils.getPageUrl(subPageUrl);
		logger.debug("Getting " + url);
		
		driver.get(url);	
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy