Java Code Examples for org.testng.ITestContext#getAttribute()
The following examples show how to use
org.testng.ITestContext#getAttribute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestCaseTestListener.java From agent with MIT License | 6 votes |
/** * 每个device结束测试调用的方法,这里可能有多个线程同时调用 * * @param testContext */ @Override public void onFinish(ITestContext testContext) { TestDescription testDesc = (TestDescription) testContext.getAttribute(TEST_DESCRIPTION); log.info("[{}]onFinish, deviceTestTaskId: {}", testDesc.getDeviceId(), testDesc.getDeviceTestTaskId()); CURRENT_TEST_CASE_ID.remove(); CONFIG_FAIL_ERR_INFO.remove(); DeviceTestTask deviceTestTask = new DeviceTestTask(); deviceTestTask.setId(testDesc.getDeviceTestTaskId()); deviceTestTask.setEndTime(new Date()); deviceTestTask.setStatus(DeviceTestTask.FINISHED_STATUS); ServerClient.getInstance().updateDeviceTestTask(deviceTestTask); }
Example 2
Source File: AllureTestListener.java From allure1 with Apache License 2.0 | 6 votes |
/** * Suppress duplicated configuration method events */ @SuppressWarnings("unchecked") private synchronized boolean isSuppressConfigEvent(ITestResult iTestResult) { Set<String> methodNames; ITestContext context = iTestResult.getTestContext(); String configType = getConfigMethodType(iTestResult).getName(); if (context.getAttribute(configType) == null) { methodNames = new HashSet<>(); methodNames.add(iTestResult.getName()); context.setAttribute(configType, methodNames); return false; } else { methodNames = (Set<String>) context.getAttribute(configType); if (!methodNames.contains(iTestResult.getName())) { methodNames.add(iTestResult.getName()); return false; } } return true; }
Example 3
Source File: CustomTestNgListener.java From heat with Apache License 2.0 | 5 votes |
/** * 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(FAILED_TEST_CASES) == null) { failedTc = new ArrayList(); } else { failedTc = (List<ITestResult>) testContext.getAttribute(FAILED_TEST_CASES); } failedTc.add(tr); testContext.setAttribute(FAILED_TEST_CASES, failedTc); } else { super.onTestFailure(tr); } }
Example 4
Source File: AllureTestListener.java From allure1 with Apache License 2.0 | 5 votes |
/** * Package private. Used in unit test. * * @return UID for the current suite */ String getSuiteUid(ITestContext iTestContext) { String uid; if (iTestContext.getAttribute(SUITE_UID) != null) { uid = (String) iTestContext.getAttribute(SUITE_UID); } else { uid = UUID.randomUUID().toString(); iTestContext.setAttribute(SUITE_UID, uid); } return uid; }
Example 5
Source File: GroovyServiceTest.java From everrest with Eclipse Public License 2.0 | 5 votes |
@Test public void testName(ITestContext context) throws Exception { JettyHttpServer httpServer = (JettyHttpServer)context.getAttribute(JETTY_SERVER); httpServer.publishPerRequestGroovyScript("a/b/GroovyResource1.groovy", "GroovyResource1"); expect() .statusCode(200) .body(Matchers.containsString("GroovyResource1")) .when() .get("/a/b"); }
Example 6
Source File: EverrestJetty.java From everrest with Eclipse Public License 2.0 | 5 votes |
public void onFinish(ITestContext context) { JettyHttpServer httpServer = (JettyHttpServer)context.getAttribute(JETTY_SERVER); if (httpServer != null) { try { httpServer.stop(); httpServer = null; } catch (Exception e) { LOG.error(e.getLocalizedMessage(), e); throw new RuntimeException(e.getLocalizedMessage(), e); } } }
Example 7
Source File: ZkTestBase.java From helix with Apache License 2.0 | 5 votes |
@AfterMethod public void endTest(Method testMethod, ITestContext testContext) { Long startTime = (Long) testContext.getAttribute("StartTime"); long endTime = System.currentTimeMillis(); System.out.println("END " + testMethod.getName() + " at " + new Date(endTime) + ", took: " + (endTime - startTime) + "ms."); }
Example 8
Source File: LinkHeaderGenerationTest.java From che with Eclipse Public License 2.0 | 5 votes |
@Test public void linksHeaderShouldBeCorrectlyGenerated(ITestContext ctx) throws Exception { final Response response = given() .auth() .basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD) .contentType("application/json") .when() .get(SECURE_PATH + "/test/paging/test-path-param?query-param=test-query-param"); assertEquals(response.getStatusCode(), 200); final String headerValue = response.getHeader("Link"); assertNotNull(headerValue, "Link header is missing in the response"); final Map<String, String> relToLinkMap = PagingUtil.parseLinkHeader(headerValue); final Set<String> expectedRels = new HashSet<>(asList("first", "last", "prev", "next")); assertEquals( relToLinkMap.keySet(), expectedRels, "Rels are different " + symmetricDifference(expectedRels, relToLinkMap.keySet())); final String expectedUri = "http://localhost:" + ctx.getAttribute(EverrestJetty.JETTY_PORT) + "/rest/private/test/paging/test-path-param"; for (String link : relToLinkMap.values()) { final URI uri = URI.create(link); final Map<String, List<String>> params = getQueryParameters(uri.toURL()); assertEquals(params.size(), 3); assertNotNull(params.get("skipCount")); assertNotNull(params.get("maxItems")); assertEquals(params.get("query-param").get(0), "test-query-param"); assertEquals(link, expectedUri + '?' + uri.getQuery()); } }
Example 9
Source File: AbstractSeleniumTest.java From xframium-java with GNU General Public License v3.0 | 5 votes |
/** * Gets the device data. * * @return the device data */ @DataProvider ( name = "deviceManager", parallel = true) public Object[][] getDeviceData( ITestContext testContext ) { String xFID = null; if ( Initializable.xFID == null || Initializable.xFID.get() == null ) xFID = (String) ((testContext.getAttribute( "xFID" ) != null)?(testContext.getAttribute( "xFID" )):testContext.getSuite().getAttribute( "xFID" )); else xFID = Initializable.xFID.get(); List<Device> deviceList = DeviceManager.instance( xFID ).getDevices(); return getDeviceData( deviceList, testContext, xFID ); }
Example 10
Source File: CustomJUnitReportListener.java From heat with Apache License 2.0 | 5 votes |
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; }
Example 11
Source File: CustomTestNgListener.java From heat with Apache License 2.0 | 5 votes |
/** * 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(SKIPPED_TEST_CASES); 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.info("*************[{}] SKIPPED Test Suite", testName, testContext.getAttribute(TestBaseRunner.SUITE_DESCRIPTION_CTX_ATTR)); logger.debug("*************[{}][{}] END Test Suite: Success: {} / Failed: {} / Skipped: {}", testName, testContext.getAttribute(TestBaseRunner.SUITE_DESCRIPTION_CTX_ATTR), numTestSuccess, numTestFailed, numTestSkipped); } else { logger.debug("*************[{}][{}] END Test Suite: Success: {} / Failed: {} / Skipped: {}", testName, testContext.getAttribute(TestBaseRunner.SUITE_DESCRIPTION_CTX_ATTR), 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()); } } }
Example 12
Source File: CustomTestNgListener.java From heat with Apache License 2.0 | 5 votes |
/** * 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.info("[{}][{}][{}] -- SKIPPED", testCaseCompleteID, testContext.getAttribute(TestBaseRunner.SUITE_DESCRIPTION_CTX_ATTR).toString(), testContext.getAttribute(TestBaseRunner.TC_DESCRIPTION_CTX_ATTR).toString()); if (testContext.getAttribute(SKIPPED_TEST_CASES) == null) { skippedTc = new ArrayList(); } else { skippedTc = (List<ITestResult>) testContext.getAttribute(SKIPPED_TEST_CASES); } skippedTc.add(tr); testContext.setAttribute(SKIPPED_TEST_CASES, 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(PASSED_TEST_CASES) == null) { passedTc = new ArrayList(); } else { passedTc = (List<ITestResult>) testContext.getAttribute(PASSED_TEST_CASES); } passedTc.add(tr); testContext.setAttribute(PASSED_TEST_CASES, passedTc); } } else { super.onTestSuccess(tr); } }
Example 13
Source File: AbstractSeleniumTest.java From xframium-java with GNU General Public License v3.0 | 4 votes |
/** * Before method. * * @param currentMethod * the current method * @param testArgs * the test args */ @BeforeMethod ( alwaysRun = true) public void beforeMethod( Method currentMethod, Object[] testArgs, ITestContext testContext ) { try { TestContainer tC = ((TestContainer) testArgs[0]); if ( testContext.getAttribute( "testContainer" ) == null ) testContext.setAttribute( "testContainer", tC ); TestPackage testPackage = tC.getTestPackage( currentMethod, true, xmlMode ); testPackageContainer.set( testPackage ); TestName testName = testPackage.getTestName(); if ( !xmlMode ) { // // Stub out the test and the execution context // ExecutionContextTest eC = new ExecutionContextTest(); eC.setxFID( tC.getxFID() ); eC.setTestName( currentMethod.getName() ); CloudDescriptor cD = CloudRegistry.instance(tC.getxFID()).getCloud(); if ( testPackage.getDevice().getCloud() != null && !testPackage.getDevice().getCloud().trim().isEmpty() ) cD = CloudRegistry.instance(tC.getxFID()).getCloud( testPackage.getDevice().getCloud() ); KeyWordTest kwt = new KeyWordTest( currentMethod.getName(), true, null, null, false, null, null, 0, currentMethod.getName() + " from " + currentMethod.getClass().getName(), null, null, null, ExecutionContext.instance(tC.getxFID()).getConfigProperties(), 0, null, null, null, null, 0, 0, TRACE.OFF.name() ); eC.setTest( kwt ); eC.setAut( ApplicationRegistry.instance(tC.getxFID()).getAUT() ); eC.setCloud( cD ); eC.setDevice( testPackage.getConnectedDevice().getPopulatedDevice() ); testPackage.getConnectedDevice().getWebDriver().setExecutionContext( eC ); testName.setTestName( currentMethod.getName() ); testName.setTest( eC ); File artifactFolder = new File( testPackage.getConnectedDevice().getDevice().getEnvironment(), testName.getTestName() ); testPackage.getConnectedDevice().getWebDriver().setArtifactFolder( artifactFolder ); } ConnectedDevice connectedDevice = testPackage.getConnectedDevice(); String contentKey = testName.getContentKey(); if ( (contentKey != null) && (contentKey.length() > 0) ) { ContentManager.instance(tC.getxFID()).setCurrentContentKey( contentKey ); } else { ContentManager.instance(tC.getxFID()).setCurrentContentKey( null ); } if ( connectedDevice != null ) { if ( testName.getTestName() == null || testName.getTestName().isEmpty() ) testName.setTestName( currentMethod.getDeclaringClass().getSimpleName() + "." + currentMethod.getName() ); testName.setFullName( testArgs[0].toString() ); if ( testFlow.isInfoEnabled() ) testFlow.info( Thread.currentThread().getName() + ": acquired for " + currentMethod.getName() ); } } catch ( Exception e ) { testFlow.fatal( Thread.currentThread().getName() + ": Fatal error configuring test", e ); } }
Example 14
Source File: DefaultHttpJsonRequestTest.java From che with Eclipse Public License 2.0 | 4 votes |
private String getUrl(ITestContext ctx) { return "http://localhost:" + ctx.getAttribute(EverrestJetty.JETTY_PORT) + "/rest/test"; }
Example 15
Source File: RemoteServiceDescriptorTest.java From che with Eclipse Public License 2.0 | 4 votes |
private String getServerUrl(ITestContext ctx) { return "http://localhost:" + ctx.getAttribute(EverrestJetty.JETTY_PORT) + "/rest"; }
Example 16
Source File: OmidTestBase.java From phoenix-omid with Apache License 2.0 | 4 votes |
InMemoryCommitTable getCommitTable(ITestContext context) { return (InMemoryCommitTable) context.getAttribute("commitTable"); }
Example 17
Source File: BaseStageTest.java From helix with Apache License 2.0 | 4 votes |
@AfterMethod public void endTest(Method testMethod, ITestContext testContext) { Long startTime = (Long) testContext.getAttribute("StartTime"); long endTime = System.currentTimeMillis(); System.out.println("END " + testMethod.getName() + " at " + new Date(endTime) + ", took: " + (endTime - startTime) + "ms."); }
Example 18
Source File: OmidTestBase.java From phoenix-omid with Apache License 2.0 | 4 votes |
TSOClient getClient(ITestContext context) { return (TSOClient) context.getAttribute("client"); }
Example 19
Source File: OmidTestBase.java From phoenix-omid with Apache License 2.0 | 4 votes |
private TSOServer getTSO(ITestContext context) { return (TSOServer) context.getAttribute("tso"); }