Java Code Examples for org.testng.ITestResult#getName()
The following examples show how to use
org.testng.ITestResult#getName() .
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: ScreenshotListener.java From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License | 6 votes |
@Override public void onTestFailure(ITestResult failingTest) { try { WebDriver driver = getDriver(); String screenshotDirectory = System.getProperty("screenshotDirectory", "target/screenshots"); String screenshotAbsolutePath = screenshotDirectory + File.separator + System.currentTimeMillis() + "_" + failingTest.getName() + ".png"; File screenshot = new File(screenshotAbsolutePath); if (createFile(screenshot)) { try { writeScreenshotToFile(driver, screenshot); } catch (ClassCastException weNeedToAugmentOurDriverObject) { writeScreenshotToFile(new Augmenter().augment(driver), screenshot); } System.out.println("Written screenshot to " + screenshotAbsolutePath); } else { System.err.println("Unable to create " + screenshotAbsolutePath); } } catch (Exception ex) { System.err.println("Unable to capture screenshot: " + ex.getCause()); } }
Example 2
Source File: ScreenshotListener.java From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License | 6 votes |
@Override public void onTestFailure(ITestResult failingTest) { try { WebDriver driver = getDriver(); String screenshotDirectory = System.getProperty("screenshotDirectory", "target/screenshots"); String screenshotAbsolutePath = screenshotDirectory + File.separator + System.currentTimeMillis() + "_" + failingTest.getName() + ".png"; File screenshot = new File(screenshotAbsolutePath); if (createFile(screenshot)) { try { writeScreenshotToFile(driver, screenshot); } catch (ClassCastException weNeedToAugmentOurDriverObject) { writeScreenshotToFile(new Augmenter().augment(driver), screenshot); } System.out.println("Written screenshot to " + screenshotAbsolutePath); } else { System.err.println("Unable to create " + screenshotAbsolutePath); } } catch (Exception ex) { System.err.println("Unable to capture screenshot: " + ex.getCause()); } }
Example 3
Source File: ScreenshotListener.java From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License | 6 votes |
@Override public void onTestFailure(ITestResult failingTest) { try { WebDriver driver = getDriver(); String screenshotDirectory = System.getProperty("screenshotDirectory", "target/screenshots"); String screenshotAbsolutePath = screenshotDirectory + File.separator + System.currentTimeMillis() + "_" + failingTest.getName() + ".png"; File screenshot = new File(screenshotAbsolutePath); if (createFile(screenshot)) { try { writeScreenshotToFile(driver, screenshot); } catch (ClassCastException weNeedToAugmentOurDriverObject) { writeScreenshotToFile(new Augmenter().augment(driver), screenshot); } System.out.println("Written screenshot to " + screenshotAbsolutePath); } else { System.err.println("Unable to create " + screenshotAbsolutePath); } } catch (Exception ex) { System.err.println("Unable to capture screenshot..."); ex.printStackTrace(); } }
Example 4
Source File: ScreenshotListener.java From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License | 6 votes |
@Override public void onTestFailure(ITestResult failingTest) { try { WebDriver driver = getDriver(); String screenshotDirectory = System.getProperty("screenshotDirectory", "target/screenshots"); String screenshotAbsolutePath = screenshotDirectory + File.separator + System.currentTimeMillis() + "_" + failingTest.getName() + ".png"; File screenshot = new File(screenshotAbsolutePath); if (createFile(screenshot)) { try { writeScreenshotToFile(driver, screenshot); } catch (ClassCastException weNeedToAugmentOurDriverObject) { writeScreenshotToFile(new Augmenter().augment(driver), screenshot); } System.out.println("Written screenshot to " + screenshotAbsolutePath); } else { System.err.println("Unable to create " + screenshotAbsolutePath); } } catch (Exception ex) { System.err.println("Unable to capture screenshot: " + ex.getCause()); } }
Example 5
Source File: ScreenshotListener.java From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License | 6 votes |
@Override public void onTestFailure(ITestResult failingTest) { try { WebDriver driver = getDriver(); String screenshotDirectory = System.getProperty("screenshotDirectory", "target/screenshots"); String screenshotAbsolutePath = screenshotDirectory + File.separator + System.currentTimeMillis() + "_" + failingTest.getName() + ".png"; File screenshot = new File(screenshotAbsolutePath); if (createFile(screenshot)) { try { writeScreenshotToFile(driver, screenshot); } catch (ClassCastException weNeedToAugmentOurDriverObject) { writeScreenshotToFile(new Augmenter().augment(driver), screenshot); } System.out.println("Written screenshot to " + screenshotAbsolutePath); } else { System.err.println("Unable to create " + screenshotAbsolutePath); } } catch (Exception ex) { System.err.println("Unable to capture screenshot: " + ex.getCause()); } }
Example 6
Source File: TestNGRunner.java From buck with Apache License 2.0 | 6 votes |
/** Compute the "full name" of a test method, including its parameters, if any. */ private static String getTestMethodNameWithParameters(ITestResult iTestResult) { Object[] parameters = iTestResult.getParameters(); String name = iTestResult.getName(); if (parameters == null || parameters.length == 0) { return name; } StringBuilder builder = new StringBuilder(name).append(" ("); builder.append( Arrays.stream(parameters) .map( parameter -> { try { return String.valueOf(parameter); } catch (Exception e) { return "Unstringable object"; } }) .collect(Collectors.joining(", "))); builder.append(")"); return builder.toString(); }
Example 7
Source File: ScreenshotListener.java From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License | 6 votes |
@Override public void onTestFailure(ITestResult failingTest) { try { WebDriver driver = getDriver(); String screenshotDirectory = System.getProperty("screenshotDirectory", "target/screenshots"); String screenshotAbsolutePath = screenshotDirectory + File.separator + System.currentTimeMillis() + "_" + failingTest.getName() + ".png"; File screenshot = new File(screenshotAbsolutePath); if (createFile(screenshot)) { try { writeScreenshotToFile(driver, screenshot); } catch (ClassCastException weNeedToAugmentOurDriverObject) { writeScreenshotToFile(new Augmenter().augment(driver), screenshot); } System.out.println("Written screenshot to " + screenshotAbsolutePath); } else { System.err.println("Unable to create " + screenshotAbsolutePath); } } catch (Exception ex) { System.err.println("Unable to capture screenshot: " + ex.getCause()); } }
Example 8
Source File: ScreenshotListener.java From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License | 6 votes |
@Override public void onTestFailure(ITestResult failingTest) { try { WebDriver driver = getDriver(); String screenshotDirectory = System.getProperty("screenshotDirectory", "target/screenshots"); String screenshotAbsolutePath = screenshotDirectory + File.separator + System.currentTimeMillis() + "_" + failingTest.getName() + ".png"; File screenshot = new File(screenshotAbsolutePath); if (createFile(screenshot)) { try { writeScreenshotToFile(driver, screenshot); } catch (ClassCastException weNeedToAugmentOurDriverObject) { writeScreenshotToFile(new Augmenter().augment(driver), screenshot); } System.out.println("Written screenshot to " + screenshotAbsolutePath); } else { System.err.println("Unable to create " + screenshotAbsolutePath); } } catch (Exception ex) { System.err.println("Unable to capture screenshot: " + ex.getCause()); } }
Example 9
Source File: ScreenshotListener.java From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License | 6 votes |
@Override public void onTestFailure(ITestResult failingTest) { try { WebDriver driver = getDriver(); String screenshotDirectory = System.getProperty("screenshotDirectory", "target/screenshots"); String screenshotAbsolutePath = screenshotDirectory + File.separator + System.currentTimeMillis() + "_" + failingTest.getName() + ".png"; File screenshot = new File(screenshotAbsolutePath); if (createFile(screenshot)) { try { writeScreenshotToFile(driver, screenshot); } catch (ClassCastException weNeedToAugmentOurDriverObject) { writeScreenshotToFile(new Augmenter().augment(driver), screenshot); } System.out.println("Written screenshot to " + screenshotAbsolutePath); } else { System.err.println("Unable to create " + screenshotAbsolutePath); } } catch (Exception ex) { System.err.println("Unable to capture screenshot: " + ex.getCause()); } }
Example 10
Source File: ScreenshotListener.java From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License | 6 votes |
@Override public void onTestFailure(ITestResult failingTest) { try { WebDriver driver = getDriver(); String screenshotDirectory = System.getProperty("screenshotDirectory", "target/screenshots"); String screenshotAbsolutePath = screenshotDirectory + File.separator + System.currentTimeMillis() + "_" + failingTest.getName() + ".png"; File screenshot = new File(screenshotAbsolutePath); if (createFile(screenshot)) { try { writeScreenshotToFile(driver, screenshot); } catch (ClassCastException weNeedToAugmentOurDriverObject) { writeScreenshotToFile(new Augmenter().augment(driver), screenshot); } System.out.println("Written screenshot to " + screenshotAbsolutePath); } else { System.err.println("Unable to create " + screenshotAbsolutePath); } } catch (Exception ex) { System.err.println("Unable to capture screenshot: " + ex.getCause()); } }
Example 11
Source File: ScreenshotListener.java From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License | 6 votes |
@Override public void onTestFailure(ITestResult failingTest) { try { WebDriver driver = getDriver(); String screenshotDirectory = System.getProperty("screenshotDirectory", "target/screenshots"); String screenshotAbsolutePath = screenshotDirectory + File.separator + System.currentTimeMillis() + "_" + failingTest.getName() + ".png"; File screenshot = new File(screenshotAbsolutePath); if (createFile(screenshot)) { try { writeScreenshotToFile(driver, screenshot); } catch (ClassCastException weNeedToAugmentOurDriverObject) { writeScreenshotToFile(new Augmenter().augment(driver), screenshot); } System.out.println("Written screenshot to " + screenshotAbsolutePath); } else { System.err.println("Unable to create " + screenshotAbsolutePath); } } catch (Exception ex) { System.err.println("Unable to capture screenshot: " + ex.getCause()); } }
Example 12
Source File: ScreenshotListener.java From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License | 6 votes |
@Override public void onTestFailure(ITestResult failingTest) { try { WebDriver driver = getDriver(); String screenshotDirectory = System.getProperty("screenshotDirectory", "target/screenshots"); String screenshotAbsolutePath = screenshotDirectory + File.separator + System.currentTimeMillis() + "_" + failingTest.getName() + ".png"; File screenshot = new File(screenshotAbsolutePath); if (createFile(screenshot)) { try { writeScreenshotToFile(driver, screenshot); } catch (ClassCastException weNeedToAugmentOurDriverObject) { writeScreenshotToFile(new Augmenter().augment(driver), screenshot); } System.out.println("Written screenshot to " + screenshotAbsolutePath); } else { System.err.println("Unable to create " + screenshotAbsolutePath); } } catch (Exception ex) { System.err.println("Unable to capture screenshot: " + ex.getCause()); } }
Example 13
Source File: TestNGListener.java From product-microgateway with Apache License 2.0 | 5 votes |
@Override public void onTestFailure(ITestResult tr) { String testCase = tr.getName(); Throwable e = tr.getThrowable(); LoggerFactory.getLogger(tr.getTestClass().getRealClass()) .error(BOLD + testCase + ": " + RED + BOLD + "FAILED" + " -> " + e.getMessage() + RESET); }
Example 14
Source File: JUnitXMLReporter.java From jgroups-raft with Apache License 2.0 | 5 votes |
protected static String getMethodName(ITestResult tr) { String method_name=tr.getName(); Object[] params=tr.getParameters(); if(params != null && params.length > 0) { String tmp=null; if(params[0] instanceof Class<?>) tmp=((Class<?>)params[0]).getSimpleName(); else if(params[0] != null) tmp=params[0].getClass().getSimpleName(); if(tmp != null) method_name=method_name + "-" + tmp; } return method_name; }
Example 15
Source File: TestNGTestResultProcessorAdapter.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
private String calculateTestCaseName(ITestResult iTestResult) { Object[] parameters = iTestResult.getParameters(); String name = iTestResult.getName(); if (parameters != null && parameters.length > 0) { StringBuilder builder = new StringBuilder(name). append("["). append(iTestResult.getMethod().getCurrentInvocationCount()). append("]"); StringBuilder paramsListBuilder = new StringBuilder("("); int i = 0; for (Object parameter : parameters) { if (parameter == null) { paramsListBuilder.append("null"); } else { try { paramsListBuilder.append(parameter.toString()); } catch (Exception e) { // This may be thrown by the caller of this method at a later time iTestResult.setThrowable(new UnrepresentableParameterException(iTestResult, i, e)); return builder.toString(); } } if (++i < parameters.length) { paramsListBuilder.append(", "); } } paramsListBuilder.append(")"); return builder.append(paramsListBuilder.toString()).toString(); } else { return name; } }
Example 16
Source File: AbstractDifidoReporter.java From difido-reports with Apache License 2.0 | 4 votes |
@Override public void onTestStart(ITestResult result) { if (!result.getTestClass().getName().equals(testClassName)) { testClassName = result.getTestClass().getName(); startClassScenario(result); } String testName = result.getName(); List<String> testParameters = getTestParameters(result); if (!testParameters.isEmpty()) { StringBuilder sb = new StringBuilder(); sb.append(testName); sb.append("("); String tempString = testParameters.toString().replaceFirst("\\[", ""); sb.append(tempString.substring(0, tempString.length() - 1)); sb.append(")"); testName = sb.toString(); } currentTest = new TestNode(index++, testName, executionUid + "-" + index); currentTest.setClassName(testClassName); final Date date = new Date(result.getStartMillis()); currentTest.setTimestamp(TIME_FORMAT.format(date)); currentTest.setDate(DATE_FORMAT.format(date)); currentClassScenario.addChild(currentTest); testDetails = new TestDetails(currentTest.getUid()); if (result.getMethod().getDescription() != null) { currentTest.setDescription(result.getMethod().getDescription()); } addPropertyIfExist("Class", result.getTestClass().getName()); addPropertyIfExist("Groups", Arrays.toString(result.getMethod().getGroups())); int paramCounter = 0; for (String paramValue : testParameters) { currentTest.addParameter("param" + paramCounter++, paramValue); } int numOfAppearances = getAndUpdateTestHistory(result.getTestClass().getName() + testName); if (numOfAppearances > 0) { currentTest.setName(currentTest.getName() + " (" + ++numOfAppearances + ")"); } updateTestDirectory(); writeExecution(execution); flushBufferedElements("Setup"); writeTestDetails(testDetails); }
Example 17
Source File: TestNGListener.java From product-microgateway with Apache License 2.0 | 4 votes |
@Override public void onTestStart(ITestResult result) { String testCase = result.getName(); LoggerFactory.getLogger(result.getTestClass().getRealClass().getSimpleName()).info( BOLD + testCase + ": " + BLUE + BOLD + "RUNNING" + RESET); }
Example 18
Source File: TestNGListener.java From product-microgateway with Apache License 2.0 | 4 votes |
@Override public void onTestSkipped(ITestResult tr) { String testCase = tr.getName(); LoggerFactory.getLogger(tr.getTestClass().getRealClass()).info( BOLD + testCase + ": " + YELLOW + BOLD + "SKIPPED" + RESET); }
Example 19
Source File: AbstractTestListener.java From carina with Apache License 2.0 | 4 votes |
private String skipItem(ITestResult result, Messager messager) { String test = TestNamingListener.getTestName(); String errorMessage = getFailureReason(result); if (errorMessage.isEmpty()) { // identify is it due to the dependent failure or exception in before suite/class/method String[] methods = result.getMethod().getMethodsDependedUpon(); // find if any parent method failed/skipped boolean dependentMethod = false; String dependentMethodName = ""; for (ITestResult failedTest : result.getTestContext().getFailedTests().getAllResults()) { for (int i = 0; i < methods.length; i++) { if (methods[i].contains(failedTest.getName())) { dependentMethodName = failedTest.getName(); dependentMethod = true; break; } } } for (ITestResult skippedTest : result.getTestContext().getSkippedTests().getAllResults()) { for (int i = 0; i < methods.length; i++) { if (methods[i].contains(skippedTest.getName())) { dependentMethodName = skippedTest.getName(); dependentMethod = true; break; } } } if (dependentMethod) { errorMessage = "Test skipped due to the dependency from: " + dependentMethodName; } else { // Try to find error details from last configuration failure in this thread TestResultItem resultItem = getConfigFailure(); if (resultItem != null) { errorMessage = resultItem.getFailReason(); } } } String deviceName = getDeviceName(); messager.warn(deviceName, test, DateUtils.now(), errorMessage); EmailReportItemCollector .push(createTestResult(result, TestResultType.SKIP, errorMessage, result.getMethod().getDescription())); result.getTestContext().removeAttribute(SpecialKeywords.TEST_FAILURE_MESSAGE); return errorMessage; }
Example 20
Source File: TestNGListener.java From product-microgateway with Apache License 2.0 | 4 votes |
@Override public void onTestSuccess(ITestResult tr) { String testCase = tr.getName(); LoggerFactory.getLogger(tr.getTestClass().getRealClass().getSimpleName()).info( BOLD + testCase + ": " + GREEN + BOLD + "PASSED" + RESET); }