// Path: kheera-testrunner/src/main/java/com/kheera/internal/StepDefinition.java
// public interface StepDefinition {
//     void onCreate(Context context, TestRunnerConfig runnerConfig);
// }
// 
// Path: kheera-testrunner/src/main/java/com/kheera/internal/TestRunnerConfig.java
// public class TestRunnerConfig {
//     @SerializedName("Name")
//     public String Name;
// 
//     @SerializedName("Description")
//     public String Description;
// 
//     @SerializedName("TestData")
//     public String TestDataFile;
// 
//     @SerializedName("AppConfig")
//     public String AppConfigFile;
// 
//     @SerializedName("Screenshots")
//     public boolean Screenshots;
// 
//     @SerializedName("IncludeSkipped")
//     public boolean IncludeSkipped;
// 
//     @SerializedName("WriteTestReport")
//     public boolean WriteTestReport;
// 
//     @SerializedName("ReportLogPath")
//     public String ReportLogPath;
// 
//     @SerializedName("FilterBy")
//     public String FilterBy;
// 
//     @SerializedName("FilterType")
//     public String FilterType;
// 
//     @SerializedName("DetailedErrors")
//     public boolean DetailedErrors;
// 
//     @SerializedName("CoverageReport")
//     public boolean CoverageReport;
// 
//     @SerializedName("CoverageFile")
//     public String CoverageFile;
// 
//     @SerializedName("LogTag")
//     public String LogTag;
// }
// 
// Path: samples/src/androidTest/java/com/kheera/kheerasample/screens/LoginScreen.java
// public class LoginScreen {
//     public static Activity ActivityInstance;
// 
//     public static void open() {
// 
//             boolean mInitialTouchMode = false;
// 
//             getInstrumentation().setInTouchMode(mInitialTouchMode);
// 
//             Intent newIntent = new Intent(getInstrumentation().getTargetContext(), LoginActivity.class);
//             newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//             ActivityInstance = getInstrumentation().startActivitySync(newIntent);
// 
//             getInstrumentation().waitForIdleSync();
// 
//             ((KeyguardManager) getInstrumentation().getContext().getSystemService(KEYGUARD_SERVICE)).newKeyguardLock(KEYGUARD_SERVICE).disableKeyguard();
// 
//             //turn the screen on
//             ActivityInstance.runOnUiThread(new Runnable() {
//                 @Override
//                 public void run() {
//                     ActivityInstance.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
//                             | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
//                             | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
//                             | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
//                             | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
//                 }
//             });
//     }
// 
//     public static void enterEmail(String email) {
//         onView(withId(R.id.email)).perform(typeText(email));
//     }
// 
//     public static void enterPassword(String password) {
//         onView(withId(R.id.password)).perform(typeText(password));
//     }
// 
//     public static void performLogin() {
//         onView(withId(R.id.email_sign_in_button)).perform(click());
//     }
// }


import android.content.Context;
import android.os.Build;
import android.util.Log;
import com.kheera.annotations.OnFinishTest;
import com.kheera.annotations.OnStartTest;
import com.kheera.annotations.RetainAcrossTests;
import com.kheera.annotations.TestModule;
import com.kheera.annotations.TestStep;
import com.kheera.internal.StepDefinition;
import com.kheera.internal.TestRunnerConfig;
import com.kheera.kheerasample.R;
import com.kheera.kheerasample.screens.LoginScreen;
import java.util.concurrent.TimeUnit;
import androidx.test.espresso.IdlingPolicies;
import androidx.test.espresso.intent.Intents;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.hasErrorText;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
    @OnFinishTest()
    public void onFinishTest(String featureName, String scenarioName) {
        getInstrumentation().waitForIdleSync();

        if (LoginScreen.ActivityInstance != null) {

            if (Build.VERSION.SDK_INT > 20) {
                LoginScreen.ActivityInstance.finishAndRemoveTask();
            }
        }

        Intents.release();
    }

    @TestStep("^I am on the login page$")
    public void iAmOnTheLoginPage() throws Throwable {
        LoginScreen.open();
    }

    @TestStep("^I log in using my email and password$")
    public void iLogInUsingMyUsernameAndPassword() throws Throwable {
        LoginScreen.enterEmail(DEFAULT_EMAIL);
        LoginScreen.enterPassword(DEFAULT_PASSWORD);
        LoginScreen.performLogin();
    }

    @TestStep("^I log in using \"([^\"]*)\" and \"([^\"]*)\"$")
    public void iLogInUsingGivenUsernameAndPassword(String email, String password) throws Throwable {
        LoginScreen.enterEmail(email);
        LoginScreen.enterPassword(password);
// Path: kheera-testrunner/src/main/java/com/kheera/internal/StepDefinition.java
// public interface StepDefinition {
//     void onCreate(Context context, TestRunnerConfig runnerConfig);
// }
// 
// Path: kheera-testrunner/src/main/java/com/kheera/internal/TestRunnerConfig.java
// public class TestRunnerConfig {
//     @SerializedName("Name")
//     public String Name;
// 
//     @SerializedName("Description")
//     public String Description;
// 
//     @SerializedName("TestData")
//     public String TestDataFile;
// 
//     @SerializedName("AppConfig")
//     public String AppConfigFile;
// 
//     @SerializedName("Screenshots")
//     public boolean Screenshots;
// 
//     @SerializedName("IncludeSkipped")
//     public boolean IncludeSkipped;
// 
//     @SerializedName("WriteTestReport")
//     public boolean WriteTestReport;
// 
//     @SerializedName("ReportLogPath")
//     public String ReportLogPath;
// 
//     @SerializedName("FilterBy")
//     public String FilterBy;
// 
//     @SerializedName("FilterType")
//     public String FilterType;
// 
//     @SerializedName("DetailedErrors")
//     public boolean DetailedErrors;
// 
//     @SerializedName("CoverageReport")
//     public boolean CoverageReport;
// 
//     @SerializedName("CoverageFile")
//     public String CoverageFile;
// 
//     @SerializedName("LogTag")
//     public String LogTag;
// }
// 
// Path: samples/src/androidTest/java/com/kheera/kheerasample/screens/LoginScreen.java
// public class LoginScreen {
//     public static Activity ActivityInstance;
// 
//     public static void open() {
// 
//             boolean mInitialTouchMode = false;
// 
//             getInstrumentation().setInTouchMode(mInitialTouchMode);
// 
//             Intent newIntent = new Intent(getInstrumentation().getTargetContext(), LoginActivity.class);
//             newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//             ActivityInstance = getInstrumentation().startActivitySync(newIntent);
// 
//             getInstrumentation().waitForIdleSync();
// 
//             ((KeyguardManager) getInstrumentation().getContext().getSystemService(KEYGUARD_SERVICE)).newKeyguardLock(KEYGUARD_SERVICE).disableKeyguard();
// 
//             //turn the screen on
//             ActivityInstance.runOnUiThread(new Runnable() {
//                 @Override
//                 public void run() {
//                     ActivityInstance.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
//                             | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
//                             | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
//                             | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
//                             | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
//                 }
//             });
//     }
// 
//     public static void enterEmail(String email) {
//         onView(withId(R.id.email)).perform(typeText(email));
//     }
// 
//     public static void enterPassword(String password) {
//         onView(withId(R.id.password)).perform(typeText(password));
//     }
// 
//     public static void performLogin() {
//         onView(withId(R.id.email_sign_in_button)).perform(click());
//     }
// }


// Path: samples/src/androidTest/java/com/kheera/kheerasample/stepdefs/LoginPageFeatureFile.java
import android.content.Context;
import android.os.Build;
import android.util.Log;
import com.kheera.annotations.OnFinishTest;
import com.kheera.annotations.OnStartTest;
import com.kheera.annotations.RetainAcrossTests;
import com.kheera.annotations.TestModule;
import com.kheera.annotations.TestStep;
import com.kheera.internal.StepDefinition;
import com.kheera.internal.TestRunnerConfig;
import com.kheera.kheerasample.R;
import com.kheera.kheerasample.screens.LoginScreen;
import java.util.concurrent.TimeUnit;
import androidx.test.espresso.IdlingPolicies;
import androidx.test.espresso.intent.Intents;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.hasErrorText;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

    @OnFinishTest()
    public void onFinishTest(String featureName, String scenarioName) {
        getInstrumentation().waitForIdleSync();

        if (LoginScreen.ActivityInstance != null) {

            if (Build.VERSION.SDK_INT > 20) {
                LoginScreen.ActivityInstance.finishAndRemoveTask();
            }
        }

        Intents.release();
    }

    @TestStep("^I am on the login page$")
    public void iAmOnTheLoginPage() throws Throwable {
        LoginScreen.open();
    }

    @TestStep("^I log in using my email and password$")
    public void iLogInUsingMyUsernameAndPassword() throws Throwable {
        LoginScreen.enterEmail(DEFAULT_EMAIL);
        LoginScreen.enterPassword(DEFAULT_PASSWORD);
        LoginScreen.performLogin();
    }

    @TestStep("^I log in using \"([^\"]*)\" and \"([^\"]*)\"$")
    public void iLogInUsingGivenUsernameAndPassword(String email, String password) throws Throwable {
        LoginScreen.enterEmail(email);
        LoginScreen.enterPassword(password);
        LoginScreen.performLogin();