2017-05-19 81 views
-1

假設我已經在Selenium中使用TestNG編寫了4個測試用例,並且希望運行Excel中提供的運行模式爲「是」的任何2個測試用例。請讓我知道,我如何設計我的代碼,以便從TestNG測試用例列表中執行任何運行模式爲「是」的測試用例。 Screenshot from Excel是否可以從Excel驅動TestNG測試用例?

public class classname { 
    @Test public void testcase1() { 
     //Test steps here.. 
    } 
    @Test public void testcase2() { 
     //Test steps here.. 
    } 
    @Test public void testcase3() { 
     //Test steps here.. 
    } 
    @Test public void testcase4() { 
     //Test steps here.. 
    } 
} 
+0

你可以考慮向我們展示硒你的用例的依賴? – DebanjanB

+0

當然,任何事情都是可能的!請通讀[詢問]說明。 – SiKing

回答

0

IAnnotationTransformer應該可以幫助您:

public class MyTransformer implements IAnnotationTransformer { 

    private final List<String> activatedTest; 

    public MyTransformer() { 
     activatedTest = new ArrayList<>(); 
     // 1. Open Excel file 
     // 2. Iterate on lines an add all activated test cases according to the naming convention of test method names (lower case + remove spaces) 
     // With you example, the list will containt: "testcase1", "testcase3" 
    } 

    public void transform(ITest annotation, Class<?> testClass, 
     Constructor testConstructor, Method testMethod) { 
    if (activatedTest.contains(testMethod.getName())) { 
     annotation.setEnabled(true); 
    } else { 
     annotation.setEnabled(false); 
    } 
    } 
} 
相關問題