在硒中,作为使用testng的混合框架的一部分,如果在Excel工作表中对该测试用例设置了“否”,则应跳过该用例。
注意:测试用例名称和方法名称也相同。
就是这种情况:
我正在使用TestNG的BeforeMethod和Test批注。在Excel工作表中,我是这样的
TCID Description Runmode
TestCaseA1 vvvvvvvvvvvvvvvv N
TestCaseA2 vvvvvvvvvvvvvvvv Y
由于第一种情况设置为“否”,因此即使将下一种情况设置为“是”也将被跳过。
以下是代码。请提供解决问题的方法。
@BeforeMethod
public void checkTestSkip(Method method) throws IOException{
intialise();//to load the properties
String testName = method.getName();
if (!testUtil.isTestCaseRunnable(SuiteAXls,testName)) {
App_Logs.info("Skipping the case as set to No");
throw new SkipException("Skipping the case as set to No");
}
else {
App_Logs.info("Not Skipping");
}
}
@Test(priority=1)
public void TestCaseA1(){
System.out.println("test case A1");
}
@Test(priority=2)
public void TestCaseA2(){
System.out.println("test case A11");
}
}
********************************************
public static boolean isTestCaseRunnable(Xls_Reader xls,String testName){
boolean runmode=false;
int rwcnt=xls.getRowCount("Test Cases");
for(int j=2;j<=rwcnt;j++){
//for(int i=0;i<method.length;i++){
//System.out.println(method[i].getName());
System.out.println(xls.getCellData("Test Cases","TCID",j));
if(testName.equals(xls.getCellData("Test Cases","TCID",j))){
if(xls.getCellData("Test Cases","Runmode",j).equals("Y")){
System.out.println("runmode is yes");
runmode=true;
break;
}else{
System.out.println("runmode is false");
runmode=false;
break;
}
}
}
return runmode;
}
最佳答案
如果要将其作为TestNG函数进行操作,这并非易事-您必须以编程方式运行整个套件,通常需要进行大量重写。
但是,您可以仅使用布尔值来执行此操作,而将TestNG排除在外。
在用于测试是否将其设置为“ no”的if
子句中,您只需将静态变量设置为电子表格单元格的值即可。例如。
@BeforeSuite
public static boolean runTest = true;
...
if (!spreadsheet.says.yes)
runTest = false;
现在,在另一堂课中...
@Test
if (firstClass.runTest)
doTheThing()
else
System.out.println("[INFO] Skipping test...");
关于java - 如何仅跳过 Selenium 中的一种方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41887745/