/**
 * Created with IntelliJ IDEA.
 * User: jhasmanyquiroz
 * Date: 11/19/15
 * Time: 6:23 PM
 * To change this template use File | Settings | File Templates.
 */
package runner;
import common.CommonMethods;
import cucumber.api.Scenario;
import cucumber.api.CucumberOptions;
import cucumber.api.java.After;
import cucumber.api.testng.AbstractTestNGCucumberTests;
import org.apache.log4j.Logger;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriverException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.ITestResult;

import java.io.File;
import org.apache.commons.io.FileUtils;

import static framework.BrowserManager.getInstance;

@CucumberOptions(
        plugin = {"pretty", "html:target/cucumber", "json:target/cucumber.json"},
        glue={"steps"},
        features = {"src/test/resources/features"},
        //features = {"src/test/resources/features/login.feature"},
        monochrome = true)

public class RunCukesTest extends AbstractTestNGCucumberTests {

    private static Logger log = Logger.getLogger("RunCukesTest");
    public static boolean isLogin;

    @BeforeTest
    public void beforeExecution() {
        try {
            System.out.println("************************GLOBAL HOOK - BEFORE: "+isLogin);
            CommonMethods.logIn();
            isLogin = true;
            CommonMethods.logIn();
        }catch (Exception e) {
            log.error("Unable to login before execution");
        }
    }

    @AfterTest
    public void afterExecution() {
        try {
            if (isLogin) {
                CommonMethods.logOut();
                isLogin = false;
            }
            System.out.println("************************GLOBAL HOOK - AFTER: "+isLogin);
        } catch (Exception e) {
            log.error("Unable to logout after execution", e);
        } finally {
            getInstance().quitBrowser();
        }
    }

    @BeforeMethod
    public static void beforeFeature() {
        System.out.println("Starting Feature: "+isLogin);
    }

    @AfterMethod
    public static void afterFeature(ITestResult result) {
        System.out.println("Ending Feature: "+isLogin);
        // Here will compare if test is failing then only it will enter into if condition
        if(ITestResult.FAILURE==result.getStatus())
        {
            try
            {
                // Create refernce of TakesScreenshot
                TakesScreenshot ts=(TakesScreenshot)getInstance().getDriver();

                // Call method to capture screenshot
                File source=ts.getScreenshotAs(OutputType.FILE);

                // Copy files to specific location here it will save all screenshot in our project home directory and
                // result.getName() will return name of test case so that screenshot name will be same
                FileUtils.copyFile(source, new File("./Screenshots/"+result.getName()+".png"));

                System.out.println("Screenshot taken");
            }
            catch (Exception e)
            {
                System.out.println("Exception while taking screenshot "+e.getMessage());
            }
        }
    }

    @org.junit.After
    public void embedScreenShot(Scenario scenario) {
        try {
            System.out.println("#########################Take a snapshot#######################");
            byte[] screenshot = ((TakesScreenshot)getInstance().getDriver()).getScreenshotAs(OutputType.BYTES);
            scenario.embed(screenshot, "image/png");
            System.out.println("#######SCENARIO: "+scenario.getName());
        } catch (WebDriverException somePlatformsDontSupportScreenshots) {
            System.err.println(somePlatformsDontSupportScreenshots.getMessage());
        }
    }
}

@@ -225,85 +225,23 @@
 api.
-Scenario;%0Aimport cucumber.api.CucumberOptions;%0Aimport cucumber.api.java.After
+CucumberOptions
 ;%0Aim
@@ -330,138 +330,8 @@
 er;%0A
-import org.openqa.selenium.OutputType;%0Aimport org.openqa.selenium.TakesScreenshot;%0Aimport org.openqa.selenium.WebDriverException;%0A
 impo
@@ -2077,24 +2077,24 @@
 t result) %7B%0A
+
         Syst
@@ -2141,1588 +2141,8 @@
 n);%0A
-        // Here will compare if test is failing then only it will enter into if condition%0A        if(ITestResult.FAILURE==result.getStatus())%0A        %7B%0A            try%0A            %7B%0A                // Create refernce of TakesScreenshot%0A                TakesScreenshot ts=(TakesScreenshot)getInstance().getDriver();%0A%0A                // Call method to capture screenshot%0A                File source=ts.getScreenshotAs(OutputType.FILE);%0A%0A                // Copy files to specific location here it will save all screenshot in our project home directory and%0A                // result.getName() will return name of test case so that screenshot name will be same%0A                FileUtils.copyFile(source, new File(%22./Screenshots/%22+result.getName()+%22.png%22));%0A%0A                System.out.println(%22Screenshot taken%22);%0A            %7D%0A            catch (Exception e)%0A            %7B%0A                System.out.println(%22Exception while taking screenshot %22+e.getMessage());%0A            %7D%0A        %7D%0A    %7D%0A%0A    @org.junit.After%0A    public void embedScreenShot(Scenario scenario) %7B%0A        try %7B%0A            System.out.println(%22#########################Take a snapshot#######################%22);%0A            byte%5B%5D screenshot = ((TakesScreenshot)getInstance().getDriver()).getScreenshotAs(OutputType.BYTES);%0A            scenario.embed(screenshot, %22image/png%22);%0A            System.out.println(%22#######SCENARIO: %22+scenario.getName());%0A        %7D catch (WebDriverException somePlatformsDontSupportScreenshots) %7B%0A            System.err.println(somePlatformsDontSupportScreenshots.getMessage());%0A        %7D%0A
     

Remove the after scenario method