com.polonium.webdriver.PoloniumWebdriverTestRunner Maven / Gradle / Ivy
package com.polonium.webdriver;
import static com.polonium.webdriver.DriverFactory.CURRENT_BROWSER;
import static com.polonium.webdriver.DriverFactory.TARGET_BROWSERS;
import java.lang.reflect.Method;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.runner.Description;
import com.polonium.core.PoloniumTest;
import com.polonium.core.PoloniumTestRunner;
import com.polonium.webdriver.annotations.TargetBrowser;
public class PoloniumWebdriverTestRunner extends PoloniumTestRunner{
private static final String RUNNING_MESSAGE_PREFIX = "Running on: ";
public PoloniumWebdriverTestRunner(Class extends PoloniumTest> testClass) {
super(testClass);
setTargetBrowsers(testClass);
createBrowsersDescription();
}
@Override
protected void runMethods(){
invokeMethods(BeforeClass.class);
for (Method test : tests) {
invokeOnTargetBrowsers(test);
}
}
private void createBrowsersDescription() {
if(TARGET_BROWSERS.length == 0) descriptionBuilder.createDescription(testInstance.getClass(), tests);
else if(TARGET_BROWSERS.length == 1){
CURRENT_BROWSER = TARGET_BROWSERS[0];
descriptionBuilder.createDescription(testInstance.getClass(), tests);
}
else{
CURRENT_BROWSER = TARGET_BROWSERS[0];
descriptionBuilder.createDescription(testInstance.getClass(), tests, getBrowserInfo());
for(int i=1 ; i testClass) {
if(testClass.isAnnotationPresent(TargetBrowser.class)){
TARGET_BROWSERS = testClass.getAnnotation(TargetBrowser.class).value();
}
else DriverFactory.setDefaultBrowser();
}
private String getBrowserInfo() {
return "{" + RUNNING_MESSAGE_PREFIX + DriverFactory.CURRENT_BROWSER + "}";
}
}