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

com.slickqa.webdriver.CapabilitiesFactory Maven / Gradle / Ivy

There is a newer version: 1.0.1-37
Show newest version
package com.slickqa.webdriver;

import org.apache.logging.log4j.LogManager;
import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.DesiredCapabilities;

/**
 *
 * @author jcorbett
 */
public class CapabilitiesFactory
{
	private static final org.apache.logging.log4j.Logger logger = LogManager.getLogger("test." + CapabilitiesFactory.class.getName());

	public static DesiredCapabilities getCapabilitiesFor(String browserName, String remoteUrl)
	{
		DesiredCapabilities caps = getCapabilitiesFor(browserName);
		caps.setCapability(RemoteDriverWithScreenshots.REMOTE_URL, remoteUrl);
		return caps;
	}

	public static DesiredCapabilities getCapabilitiesFor(String browserName)
	{
		if(browserName.equalsIgnoreCase("ff") ||
		   browserName.equalsIgnoreCase("firefox"))
		{
			return DesiredCapabilities.firefox();
		} else if(browserName.equalsIgnoreCase("ffwin") ||
		          browserName.equalsIgnoreCase("firefoxonwindows"))
		{
			DesiredCapabilities caps = DesiredCapabilities.firefox();
			caps.setPlatform(Platform.WINDOWS);
			return caps;
        } else if(browserName.equalsIgnoreCase("ffnative"))
        {
            DesiredCapabilities caps = DesiredCapabilities.firefox();
            caps.setCapability("NativeEvents", true);
            return caps;
		} else if(browserName.equalsIgnoreCase("ie") ||
		          browserName.equalsIgnoreCase("InternetExplorer"))
		{
			return DesiredCapabilities.internetExplorer();
		} else if(browserName.equalsIgnoreCase("chrome"))
		{
			return DesiredCapabilities.chrome();
		} else if(browserName.equalsIgnoreCase("chromewin") ||
		          browserName.equalsIgnoreCase("chromeonwindows"))
		{
			DesiredCapabilities caps = DesiredCapabilities.chrome();
			caps.setPlatform(Platform.WINDOWS);
			return caps;
		} else if(
		          browserName.equalsIgnoreCase("htmlunit"))
		{
			return DesiredCapabilities.htmlUnit();
		} else if (browserName.equalsIgnoreCase("headless") ||
				   browserName.equalsIgnoreCase("phantomjs"))
		{
			return DesiredCapabilities.phantomjs();
		} else
		{
			logger.error("Unknown or invalid browser name {}, returning headless as a default.", browserName);
			return DesiredCapabilities.htmlUnit();
		}

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy