本文整理汇总了Java中org.testng.ITestContext.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java ITestContext.setAttribute方法的具体用法?Java ITestContext.setAttribute怎么用?Java ITestContext.setAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.testng.ITestContext
的用法示例。
在下文中一共展示了ITestContext.setAttribute方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onTestFailure
import org.testng.ITestContext; //导入方法依赖的package包/类
/**
* This method is useful to print the output console log in case of test failed.
* We are assuming that we put in the context an attribute whose name is the complete test case ID (example: TEST_SUITE.001) and whose value is
* 'PASSED' or 'SKIPPED' or 'FAILED'.
* @param tr test case result - testNG handling
*/
@Override
public void onTestFailure(ITestResult tr) {
if (tr.getParameters().length > 0) {
Map<String, String> paramMap = (HashMap<String, String>) tr.getParameters()[0];
ITestContext testContext = tr.getTestContext();
//testCaseCompleteID - Example: TEST_SUITE.001
String testCaseCompleteID = testContext.getName() + TestBaseRunner.TESTCASE_ID_SEPARATOR + testContext.getAttribute(TestBaseRunner.ATTR_TESTCASE_ID);
logger.error("[{}][{}][{}] -- FAILED", testCaseCompleteID,
testContext.getAttribute(TestBaseRunner.SUITE_DESCRIPTION_CTX_ATTR).toString(),
testContext.getAttribute(TestBaseRunner.TC_DESCRIPTION_CTX_ATTR).toString());
if (testContext.getAttribute("failedTestCases") == null) {
failedTc = new ArrayList<>();
} else {
failedTc = (List<ITestResult>) testContext.getAttribute("failedTestCases");
}
failedTc.add(tr);
testContext.setAttribute("failedTestCases", failedTc);
} else {
super.onTestFailure(tr);
}
}
示例2: onTestSuccess
import org.testng.ITestContext; //导入方法依赖的package包/类
/**
* This method is useful to print the output console log in case of test success or test skipped.
* We are assuming that we put in the context an attribute whose name is the complete test case ID (example: TEST_SUITE.001) and whose value is
* 'PASSED' or 'SKIPPED' or 'FAILED'.
* @param tr test case result - testNG handling
*/
@Override
public void onTestSuccess(ITestResult tr) {
if (tr.getParameters().length > 0) {
Map<String, String> paramMap = (HashMap<String, String>) tr.getParameters()[0];
ITestContext testContext = tr.getTestContext();
//testCaseCompleteID - Example: TEST_SUITE.001
String testCaseCompleteID = testContext.getName() + TestBaseRunner.TESTCASE_ID_SEPARATOR + testContext.getAttribute(TestBaseRunner.ATTR_TESTCASE_ID);
if (testContext.getAttributeNames().contains(testCaseCompleteID)
&& TestBaseRunner.STATUS_SKIPPED.equals(testContext.getAttribute(testCaseCompleteID))) {
logger.trace("[{}][{}][{}] -- SKIPPED", testCaseCompleteID,
testContext.getAttribute(TestBaseRunner.SUITE_DESCRIPTION_CTX_ATTR).toString(),
testContext.getAttribute(TestBaseRunner.TC_DESCRIPTION_CTX_ATTR).toString());
if (testContext.getAttribute("skippedTestCases") == null) {
skippedTc = new ArrayList<>();
} else {
skippedTc = (List<ITestResult>) testContext.getAttribute("skippedTestCases");
}
skippedTc.add(tr);
testContext.setAttribute("skippedTestCases", skippedTc);
} else {
logger.info("[{}][{}][{}] -- PASSED", testCaseCompleteID,
testContext.getAttribute(TestBaseRunner.SUITE_DESCRIPTION_CTX_ATTR).toString(),
testContext.getAttribute(TestBaseRunner.TC_DESCRIPTION_CTX_ATTR).toString());
if (testContext.getAttribute("passedTestCases") == null) {
passedTc = new ArrayList<>();
} else {
passedTc = (List<ITestResult>) testContext.getAttribute("passedTestCases");
}
passedTc.add(tr);
testContext.setAttribute("passedTestCases", passedTc);
}
} else {
super.onTestSuccess(tr);
}
}
示例3: onStart
import org.testng.ITestContext; //导入方法依赖的package包/类
@Override
public void onStart(ITestContext testContext) {
String testName = testContext.getCurrentXmlTest().getName();
MDC.put("testName", testName);
List<ITestResult> localSkippedTests = new ArrayList<>();
testContext.setAttribute("skippedTestCases", localSkippedTests);
}
示例4: setUp
import org.testng.ITestContext; //导入方法依赖的package包/类
@BeforeSuite(alwaysRun = true)
public void setUp(ITestContext context) throws Exception {
app.init();
context.setAttribute("app", app);
}