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

com.github.mkolisnyk.aerial.core.AerialTestNGRunner Maven / Gradle / Ivy

There is a newer version: 0.0.6.1
Show newest version
package com.github.mkolisnyk.aerial.core;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import org.testng.IHookCallBack;
import org.testng.ITestResult;
import org.testng.annotations.Test;

import com.github.mkolisnyk.aerial.annotations.AerialAfterSuite;
import com.github.mkolisnyk.aerial.annotations.AerialBeforeSuite;

import cucumber.api.testng.AbstractTestNGCucumberTests;
import cucumber.api.testng.TestNGCucumberRunner;


public class AerialTestNGRunner extends AbstractTestNGCucumberTests {
    private Class clazz;

    /* (non-Javadoc)
     * @see cucumber.api.testng.AbstractTestNGCucumberTests#run(org.testng.IHookCallBack, org.testng.ITestResult)
     */
    @Override
    public void run(IHookCallBack iHookCallBack,
            ITestResult iTestResult) {
        super.run(iHookCallBack, iTestResult);
    }

    private void runPredefinedMethods(Class annotation) throws Exception {
        if (!annotation.isAnnotation()) {
            return;
        }
        Method[] methodList = this.clazz.getMethods();
        for (Method method : methodList) {
            Annotation[] annotations = method.getAnnotations();
            for (Annotation item : annotations) {
                if (item.annotationType().equals(annotation)) {
                    method.invoke(null);
                    break;
                }
            }
        }
    }

    /* (non-Javadoc)
     * @see cucumber.api.testng.AbstractTestNGCucumberTests#run_cukes()
     */
    @Test(groups = "cucumber", description = "Runs Cucumber Features")
    public void runCukes() throws Exception {
        clazz = this.getClass();
        String[] args = AerialMain.toArgs(clazz);
        AerialMain.main(args);
        try {
            runPredefinedMethods(AerialBeforeSuite.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        new TestNGCucumberRunner(clazz).runCukes();
        try {
            runPredefinedMethods(AerialAfterSuite.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    @Test(enabled = false)
    public void run_cukes() {
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy