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

com.nordstrom.automation.selenium.junit.JUnitPlatformBase Maven / Gradle / Ivy

Go to download

Selenium Foundation is an automation framework designed to extend and enhance the capabilities provided by Selenium (WebDriver).

There is a newer version: 28.3.1-s4
Show newest version
package com.nordstrom.automation.selenium.junit;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.junit.Rule;
import org.openqa.selenium.WebDriver;

import com.nordstrom.automation.selenium.exceptions.PlatformActivationFailedException;
import com.nordstrom.automation.selenium.platform.PlatformEnum;
import com.nordstrom.automation.selenium.platform.PlatformTargetable;
import com.nordstrom.automation.selenium.platform.TargetPlatformRule;
import com.nordstrom.common.base.UncheckedThrow;

public abstract class JUnitPlatformBase

& PlatformEnum> extends JUnitBase implements PlatformTargetable

{ private final Class

platformClass; private final Method values; @Rule public TargetPlatformRule

targetPlatformRule = new TargetPlatformRule<>(this); public JUnitPlatformBase(Class

platformClass) { this.platformClass = platformClass; try { values = platformClass.getMethod("values"); } catch (NoSuchMethodException | SecurityException e) { throw UncheckedThrow.throwUnchecked(e); } } /** * {@inheritDoc} */ @Override public String[] getSubPath() { P platform = getTargetPlatform(); return (platform != null) ? new String[] { platform.getName() } : new String[0]; } /** * {@inheritDoc} */ @Override public P getTargetPlatform() { return targetPlatformRule.getPlatform(); } /** * {@inheritDoc} */ @Override public void activatePlatform(WebDriver driver) { P platform = getTargetPlatform(); if (platform != null) { activatePlatform(driver, platform); } } /** * {@inheritDoc} */ @Override public void activatePlatform(WebDriver driver, P platform) throws PlatformActivationFailedException { // by default, do nothing } /** * {@inheritDoc} */ @Override public P[] getValidPlatforms() { return values(); } /** * {@inheritDoc} */ @Override public P platformFromString(String name) { for (P platform : values()) { if (platform.getName().equals(name)) { return platform; } } return null; } /** * {@inheritDoc} */ @Override public Class

getPlatformType() { return platformClass; } private P[] values() { return invoke(values); } @SuppressWarnings("unchecked") private static T invoke(Method method, Object... parameters) { try { return (T) method.invoke(null, parameters); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw UncheckedThrow.throwUnchecked(e); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy