package com.qa.framework.factory;

import com.qa.framework.bean.TestData;
import com.qa.framework.config.PropConfig;
import com.qa.framework.core.ParamValueProcessor;
import com.qa.framework.core.TestBase;
import com.qa.framework.testnglistener.PowerEmailableReporter;
import com.qa.framework.testnglistener.TestResultListener;
import org.testng.ITestContext;
import org.testng.ITestNGMethod;
import org.testng.annotations.*;

import java.lang.reflect.Method;

/**
 * The type Executor.
 */
@Listeners({TestResultListener.class, PowerEmailableReporter.class})
public class Executor extends TestBase {
    private TestData testData;
    private String url;
    private String httpMethod;

    /**
     * Instantiates a new Executor.
     *
     * @param testData   the test data
     * @param url        the url
     * @param httpMethod the http method
     */
    public Executor(TestData testData, String url, String httpMethod) {
        this.testData = testData;
        this.url = url;
        this.httpMethod = httpMethod;
    }

    /**
     * Gets test data.
     *
     * @return the test data
     */
    public TestData getTestData() {
        return testData;
    }

    /**
     * Data object [ ] [ ].
     *
     * @return the object [ ] [ ]
     */
    @DataProvider
    public Object[][] data() {
        return new Object[][]{
                {testData, url, httpMethod},
        };
    }

    @BeforeMethod(alwaysRun = true)
    public void BeforeMethod(Method method, Object[] para) throws Exception {
    }

    @BeforeSuite
    public void beforeSuite(ITestContext context) {
        ITestNGMethod currentTestNGMethod = null;
        for (ITestNGMethod testNGMethod : context.getAllTestMethods()) {
            if (testNGMethod.getInstance() == this) {
                currentTestNGMethod = testNGMethod;
                break;
            }
        }
        if (currentTestNGMethod != null) {
            currentTestNGMethod.setInvocationCount(this.testData.getInvocationCount());
        }
    }

    /**
     * Testcase.
     *
     * @param testData   the test data
     * @param url        the url
     * @param httpMethod the http method
     */
    @Test(dataProvider = "data")
    public void testcase(TestData testData, String url, String httpMethod) {
        if (PropConfig.isSingle()) {
            ParamValueProcessor.processSingleTestdata(testData);
        } else {
            processSetupResultParam(testData);
        }
        processHeader(testData);
        String content = request(url, testData.getParams(), httpMethod, testData.isStoreCookie(), testData.isUseCookie());
        verifyResult(testData, content);

    }
}
@@ -1513,22 +1513,51 @@
 ption %7B%0A
+        logger.info(%22test%22);%0A
     %7D%0A
-
 %0A    @Be
@@ -1622,58 +1622,8 @@
 ) %7B%0A
-        ITestNGMethod currentTestNGMethod = null;%0A
     
@@ -1707,191 +1707,66 @@
     
-if (testNGMethod.getInstance() == this) %7B%0A                currentTestNGMethod = testNGMethod;%0A                break;%0A            %7D%0A        %7D%0A        if (currentTestNGMethod != null) %7B
+Executor executor = (Executor) testNGMethod.getInstance();
 %0A   
@@ -1778,16 +1778,9 @@
     
-currentT
+t
 estN
@@ -1806,29 +1806,38 @@
 onCount(
-this.t
+executor.getT
 estData
+()
 .getInvo

fix invocation bug