gpt4 book ai didi

java - 如何获取另一个扩展类中一个类的变量

转载 作者:行者123 更新时间:2023-12-01 10:05:56 26 4
gpt4 key购买 nike

在下面的测试脚本中,我想将 suiteResult 的值从类 SuiteOneBase 传递到类 SuiteOneCaseOne 。我该如何执行此操作。假设如果我得到 suiteResult =true 那么我应该在类 SuiteOneCaseOne 中得到 true 。但现在每次我只得到错误

头等舱

public class SuiteOneBase extends SuiteBase{ 
boolean suiteResult;
@BeforeSuite
public void checkSuiteToRun() throws IOException{
init();
//To set TestSuiteList.xls file's path In FilePath Variable.
FilePath = TestSuiteListExcel;
SheetName = "SuitesList";
SuiteName = "SuiteOne";
ToRunColumnName = "SuiteToRun";
suiteResult= SuiteUtility.checkToRunUtility(FilePath, SheetName,ToRunColumnName,SuiteName);

if(!suiteResult){

SuiteUtility.WriteResultUtility(FilePath, SheetName, "Skipped/Executed", SuiteName, "TestSuite Skipped");
throw new SkipException(SuiteName+"'s SuiteToRun Flag Is 'N' Or Blank. So Skipping Execution Of "+SuiteName);
}
SuiteUtility.WriteResultUtility(FilePath, SheetName, "Skipped/Executed", SuiteName, "TestSuite Executed");

}
}

二等

 public class SuiteOneCaseOne extends SuiteOneBase{

@BeforeTest
public void checkCaseToRun() throws IOException{


System.out.println("suiteResult "+suiteResult );
if(!suiteResult){
if(!SuiteUtility.checkToRunUtility(FilePath, SheetName,ToRunColumnNameTestCase,TestCaseName)){

SuiteUtility.WriteResultUtility(FilePath, SheetName, "Pass/Fail/Skip", TestCaseName, "TESTCASE SKIP");

throw new SkipException(TestCaseName+"'s CaseToRun Flag Is 'N' Or Blank. So Skipping Execution Of "+TestCaseName);
}
}

TestDataToRun = SuiteUtility.checkToRunUtilityOfData(FilePath, TestCaseName, ToRunColumnNameTestData);

}

套件库

package com.stta.TestSuiteBase;

import java.io.IOException;
import com.stta.utility.Read_XLS;

public class SuiteBase {
public static Read_XLS TestSuiteListExcel=null;
public static Read_XLS TestCaseListExcelOne=null;
public static Read_XLS TestCaseListExcelTwo=null;

public void init() throws IOException{

TestSuiteListExcel = new Read_XLS(System.getProperty("user.dir")+"\\src\\com\\stta\\ExcelFiles\\TestSuiteList.xls");

TestCaseListExcelOne = new Read_XLS(System.getProperty("user.dir")+"\\src\\com\\stta\\ExcelFiles\\SuiteOne.xls");

TestCaseListExcelTwo = new Read_XLS(System.getProperty("user.dir")+"\\src\\com\\stta\\ExcelFiles\\SuiteTwo.xls");

}
}

最佳答案

您可以使用ITestContext为此目的:

public class SuiteOneBase extends SuiteBase { 

@BeforeSuite
public void checkSuiteToRun(ITestContext context) throws IOException {
// [...]
boolean suiteResult = SuiteUtility.checkToRunUtility(FilePath, SheetName,ToRunColumnName,SuiteName);
// [...]
context.setAttribute("suiteResult", suiteResult);
}
}

还有

public class SuiteOneCaseOne extends SuiteOneBase {

@BeforeTest
public void checkCaseToRun(ITestContext context) throws IOException {
boolean suiteResult = context.getAttribute("suiteResult");
System.out.println("suiteResult "+suiteResult );
// [...]
}
}

关于java - 如何获取另一个扩展类中一个类的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36477245/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com