将TestNG包含在混合硒框架中

时间:2015-02-18 10:33:14

标签: selenium selenium-webdriver testng

我在driverscript中有以下代码。我需要将TestNG嵌入其中。我怎样才能做到这一点? ActionKeywords.java定义了所有操作关键字。 我应该在哪里给出TestNG注释?     import java.io.FileInputStream;     import java.lang.reflect.Method;     import java.util.Properties;

import org.apache.log4j.xml.DOMConfigurator;

import config.ActionKeywords;
import config.Constants;
import utility.ExcelUtils;
import utility.Log;

public class DriverScript {

    public static Properties OR;
    public static ActionKeywords actionKeywords;
    public static String sActionKeyword;
    public static String sPageObject;
    public static Method method[];


    public static int iTestStep;
    public static int iTestLastStep;
    public static String sTestCaseID;
    public static String sRunMode;
    public static String sData;
    public static boolean bResult;

    public DriverScript() throws NoSuchMethodException, SecurityException{
        actionKeywords = new ActionKeywords();
        method = actionKeywords.getClass().getMethods();    
    }

    public static void main(String[] args) throws Exception {
        ExcelUtils.setExcelFile(Constants.Path_TestData);
        DOMConfigurator.configure("log4j.xml");
        String Path_OR = Constants.Path_OR;
        FileInputStream fs = new FileInputStream(Path_OR);
        OR= new Properties(System.getProperties());
        OR.load(fs);        
        DriverScript startEngine = new DriverScript();
        startEngine.execute_TestCase();

    }

    private void execute_TestCase() throws Exception {
            int iTotalTestCases = ExcelUtils.getRowCount(Constants.Sheet_TestCases);
            System.out.println("Total TC count" + iTotalTestCases);  
            for(int iTestcase=1;iTestcase<iTotalTestCases;iTestcase++){
                bResult = true;
                sTestCaseID = ExcelUtils.getCellData(iTestcase, Constants.Col_TestCaseID, Constants.Sheet_TestCases); 
                sRunMode = ExcelUtils.getCellData(iTestcase, Constants.Col_RunMode,Constants.Sheet_TestCases);
                if (sRunMode.equals("Yes")){
                    Log.startTestCase(sTestCaseID);
                    iTestStep = ExcelUtils.getRowContains(sTestCaseID, Constants.Col_TestCaseID, Constants.Sheet_TestSteps);
                    iTestLastStep = ExcelUtils.getTestStepsCount(Constants.Sheet_TestSteps, sTestCaseID, iTestStep);
                    bResult=true;
                    for (;iTestStep<iTestLastStep;iTestStep++){
                        sActionKeyword = ExcelUtils.getCellData(iTestStep, Constants.Col_ActionKeyword,Constants.Sheet_TestSteps);
                        sPageObject = ExcelUtils.getCellData(iTestStep, Constants.Col_PageObject, Constants.Sheet_TestSteps);
                        sData = ExcelUtils.getCellData(iTestStep, Constants.Col_DataSet, Constants.Sheet_TestSteps);
                        execute_Actions();
                        if(bResult==false){
                            ExcelUtils.setCellData(Constants.KEYWORD_FAIL,iTestcase,Constants.Col_Result,Constants.Sheet_TestCases);
                            Log.endTestCase(sTestCaseID);
                            break;
                            }                       
                        }
                    if(bResult==true){
                    ExcelUtils.setCellData(Constants.KEYWORD_PASS,iTestcase,Constants.Col_Result,Constants.Sheet_TestCases);
                    Log.endTestCase(sTestCaseID);   
                        }                   
                    }
                }
            }   

     private static void execute_Actions() throws Exception {

        for(int i=0;i<method.length;i++){
            if(method[i].getName().equals(sActionKeyword)){
                method[i].invoke(actionKeywords,sPageObject, sData);
                if(bResult==true){              
                    ExcelUtils.setCellData(Constants.KEYWORD_PASS, iTestStep, Constants.Col_TestStepResult, Constants.Sheet_TestSteps);
                    break;
                }else{
                    ExcelUtils.setCellData(Constants.KEYWORD_FAIL, iTestStep, Constants.Col_TestStepResult, Constants.Sheet_TestSteps);
                    ActionKeywords.closeBrowser("","");
                    break;
                    }
                }
            }
     }

}

0 个答案:

没有答案