当前位置: 首页>>代码示例>>Java>>正文


Java ITestContext.getAttribute方法代码示例

本文整理汇总了Java中org.testng.ITestContext.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java ITestContext.getAttribute方法的具体用法?Java ITestContext.getAttribute怎么用?Java ITestContext.getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.testng.ITestContext的用法示例。


在下文中一共展示了ITestContext.getAttribute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
    }
}
 
开发者ID:HotelsDotCom,项目名称:heat,代码行数:30,代码来源:CustomTestNgListener.java

示例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);
    }
}
 
开发者ID:HotelsDotCom,项目名称:heat,代码行数:46,代码来源:CustomTestNgListener.java

示例3: afterInvocation

import org.testng.ITestContext; //导入方法依赖的package包/类
@Override
public void afterInvocation(final IInvokedMethod method, final ITestResult testResult, final ITestContext context) {
    final String testName = getTestName(testResult);
    final Boolean isTestFailed = (Boolean) context.getAttribute(format("%s postpone fail", testName));
    final Boolean isBeforeGroupFailed = (Boolean) context.getAttribute(format("%s postpone fail", "E4BeforeGroups"));
    if ((isTestFailed != null && isTestFailed) || (isBeforeGroupFailed != null && isBeforeGroupFailed)) {
        testResult.setStatus(FAILURE);
        testResult.setThrowable(new PostponedFailureException(getErrorMessage(testName)));
    }
}
 
开发者ID:WileyLabs,项目名称:teasy,代码行数:11,代码来源:ProcessPostponedFailureListener.java

示例4: onFinish

import org.testng.ITestContext; //导入方法依赖的package包/类
/**
 * This method is invoked at the end of each test suite. Is useful to create console output logs, in terms of summary of the output
 * of the test suite just executed. In particular it prints the lists of success test cases, failing ones and skipped ones.
 * Data about the test case outputs are collected in 'onTestSuccess' and 'onTestFailure' methods.
 * @param testContext test context - testNG handling
 */
@Override
public void onFinish(ITestContext testContext) {
    String testName = testContext.getCurrentXmlTest().getName(); //test suite name
    int numTestSuccess = testContext.getPassedTests().size(); //number of successful test cases in the current test suite
    int numTestFailed = testContext.getFailedTests().size(); //number of failed test cases in the current test suite
    List<ITestResult> localSkippedTests = (List<ITestResult>) testContext.getAttribute("skippedTestCases");
    int numTestSkipped = localSkippedTests.size() + testContext.getSkippedTests().size(); //number of skipped test cases in the current test suite
    if (!localSkippedTests.isEmpty()) {
        numTestSuccess = numTestSuccess - numTestSkipped;
    }
    if (numTestSkipped > 0 && numTestSuccess == 0 && numTestFailed == 0) {
        // test suite totally skipped
        logger.trace("*************[{}][Suite description: {}] SKIPPED Test Suite", testName, testContext.getAttribute(TestBaseRunner.SUITE_DESCRIPTION_CTX_ATTR).toString());
        logger.info("*************[{}][{}] END Test Suite: Success: {} / Failed: {} / Skipped: {}",
            testName, testContext.getAttribute(TestBaseRunner.SUITE_DESCRIPTION_CTX_ATTR).toString(), numTestSuccess, numTestFailed, numTestSkipped);
    } else {
        logger.debug("*************[{}][{}] END Test Suite: Success: {} / Failed: {} / Skipped: {}",
            testName, testContext.getAttribute(TestBaseRunner.SUITE_DESCRIPTION_CTX_ATTR).toString(), numTestSuccess, numTestFailed, numTestSkipped);
    }

    if (numTestFailed > 0) {
        Iterator testFailedIterator = testContext.getFailedTests().getAllResults().iterator();
        while (testFailedIterator.hasNext()) {
            ITestResult singleResult = (ITestResult) testFailedIterator.next();
            logger.error("******* TC FAILED >> {}",
                    singleResult.getThrowable().getMessage());
        }
    }
}
 
开发者ID:HotelsDotCom,项目名称:heat,代码行数:36,代码来源:CustomTestNgListener.java

示例5: getList

import org.testng.ITestContext; //导入方法依赖的package包/类
private List<ITestResult> getList(String listName, ITestContext context) {
    List<ITestResult> outputList = new ArrayList<>();
    if (context.getAttributeNames().contains(listName)) {
        outputList = (List<ITestResult>) context.getAttribute(listName);
    }
    return outputList;
}
 
开发者ID:HotelsDotCom,项目名称:heat,代码行数:8,代码来源:CustomJUnitReportListener.java


注:本文中的org.testng.ITestContext.getAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。