Java 类org.testng.ITestClass 实例源码

项目:AppiumTestDistribution    文件:AppiumParallelTestListener.java   
@Override
public void onBeforeClass(ITestClass testClass) {
    try {
        String device = testClass.getXmlClass().getAllParameters().get("device").toString();
        String className = testClass.getRealClass().getSimpleName();
        deviceAllocationManager.allocateDevice(device,
                deviceAllocationManager.getNextAvailableDeviceId());
        if (getClass().getAnnotation(Description.class) != null) {
            testDescription = getClass().getAnnotation(Description.class).value();
        }
        reportManager.createParentNodeExtent(className,
                testDescription);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:allure-java    文件:AllureTestNg.java   
public void onBeforeClass(final ITestClass testClass) {
    final String uuid = UUID.randomUUID().toString();
    final TestResultContainer container = new TestResultContainer()
            .withUuid(uuid)
            .withName(testClass.getName());
    getLifecycle().startTestContainer(container);
    classContainerUuidStorage.put(testClass, uuid);
}
项目:allure-java    文件:AllureTestNg.java   
public void onAfterClass(final ITestClass testClass) {
    if (!classContainerUuidStorage.containsKey(testClass)) {
        return;
    }
    final String uuid = classContainerUuidStorage.get(testClass);
    getLifecycle().stopTestContainer(uuid);
    getLifecycle().writeTestContainer(uuid);
}
项目:ats-framework    文件:AtsTestngClassListener.java   
/**
 * Invoked when tests from a new class are about to start 
 * @param testClass the class under test
 */
public void onStart( ITestClass testClass ) {

    if (ActiveDbAppender.getCurrentInstance() != null) {

        String suiteName = testClass.getName();
        String suiteSimpleName = suiteName.substring(suiteName.lastIndexOf('.') + 1);

        String packageName = getPackageName(suiteName);
        logger.startSuite(packageName, suiteSimpleName);
        lastSuiteName = suiteName;
    }
}
项目:TestNG-Foundation    文件:ListenerChain.java   
/**
 * [IClassListener]
 * Invoked after the test class is instantiated and before
 * {@link org.testng.annotations.BeforeClass @BeforeClass} 
 * configuration methods are called.
 * 
 * @param testClass TestNG representation for the current test class
 */
@Override
public void onBeforeClass(ITestClass testClass) {
    synchronized (classListeners) {
        for (IClassListener classListener : Lists.reverse(classListeners)) {
            classListener.onBeforeClass(testClass);
        }
    }
}
项目:TestNG-Foundation    文件:ListenerChain.java   
/**
 * [IClassListener]
 * Invoked after all of the test methods of the test class have been invoked
 * and before {@link org.testng.annotations.AfterClass @AfterClass}
 * configuration methods are called.
 * 
 * @param testClass TestNG representation for the current test class
 */
@Override
public void onAfterClass(ITestClass testClass) {
    synchronized (classListeners) {
        for (IClassListener classListener : classListeners) {
            classListener.onAfterClass(testClass);
        }
    }
}
项目:seletest    文件:InitListener.java   
@Override
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
    PreConfiguration preconfigure = null;
    ITestClass testClass=method.getTestMethod().getTestClass();
    Class<?> webClass=testClass.getRealClass();

    if(testResult.getMethod().isBeforeClassConfiguration() && testResult.getMethod().getMethodName().equalsIgnoreCase("beforeClass")) {
        preconfigure=webClass.getAnnotation(PreConfiguration.class);
    }

    //Set session as testNG attribute for after configuration methods
    try{
        testResult.setAttribute("session", SessionContext.session());}
    catch(Exception ex) {}

    if(method.getTestMethod().isTest()){
        log.debug("Set assertion type parameter for test method: {}!!!", method.getTestMethod().getMethodName());
        SeleniumTest seleniumTest=AnnotationUtils.findAnnotation(method.getTestMethod().getConstructorOrMethod().getMethod(), SeleniumTest.class);
        ApplicationContextProvider.getApplicationContext().getBean(ApplicationContextProvider.class).publishTestNGEvent(seleniumTest, "Initialize objects for the @Test method: "+method.getTestMethod().getMethodName()); 
        preconfigure = method.getTestMethod().getConstructorOrMethod().getMethod().getAnnotation(PreConfiguration.class);
    }

    //Execute Method from Page Object or Page Facade prior to @Test execution
    if(preconfigure!=null && method.getTestMethod().getCurrentInvocationCount()==0) {
        log.debug("Preconfiguration steps will be executed now for @Test {} !!!",method.getTestMethod().getMethodName());
        executionConfiguration(preconfigure);
    }
}
项目:allure-java    文件:AllureTestNg.java   
@Override
@SuppressWarnings({"Indentation", "PMD.ExcessiveMethodLength"})
public void onTestStart(final ITestResult testResult) {
    Current current = currentTestResult.get();
    if (current.isStarted()) {
        current = refreshContext();
    }
    current.test();
    final String parentUuid = getUniqueUuid(testResult.getTestContext());
    final ITestNGMethod method = testResult.getMethod();
    final ITestClass testClass = method.getTestClass();
    final List<Label> labels = new ArrayList<>();
    labels.addAll(Arrays.asList(
            //Packages grouping
            new Label().withName("package").withValue(testClass.getName()),
            new Label().withName("testClass").withValue(testClass.getName()),
            new Label().withName("testMethod").withValue(method.getMethodName()),

            //xUnit grouping
            new Label().withName("parentSuite").withValue(safeExtractSuiteName(testClass)),
            new Label().withName("suite").withValue(safeExtractTestTag(testClass)),
            new Label().withName("subSuite").withValue(safeExtractTestClassName(testClass)),

            //Timeline grouping
            new Label().withName("host").withValue(getHostName()),
            new Label().withName("thread").withValue(getThreadName())
    ));
    labels.addAll(getLabels(testResult));
    final List<Parameter> parameters = getParameters(testResult);
    final TestResult result = new TestResult()
            .withUuid(current.getUuid())
            .withHistoryId(getHistoryId(method, parameters))
            .withName(getMethodName(method))
            .withFullName(getQualifiedName(method))
            .withStatusDetails(new StatusDetails()
                    .withFlaky(isFlaky(testResult))
                    .withMuted(isMuted(testResult)))
            .withParameters(parameters)
            .withLinks(getLinks(testResult))
            .withLabels(labels);
    processDescription(getClass().getClassLoader(), method.getConstructorOrMethod().getMethod(), result);
    getLifecycle().scheduleTestCase(parentUuid, result);
    getLifecycle().startTestCase(current.getUuid());

    final String uuid = current.getUuid();
    Optional.of(testResult)
            .map(ITestResult::getMethod)
            .map(ITestNGMethod::getTestClass)
            .map(classContainerUuidStorage::get)
            .ifPresent(testClassContainerUuid -> getLifecycle().updateTestContainer(
                    testClassContainerUuid,
                    container -> container.getChildren().add(uuid)
            ));
}
项目:allure-java    文件:AllureTestNg.java   
private static String safeExtractSuiteName(final ITestClass testClass) {
    final Optional<XmlTest> xmlTest = Optional.ofNullable(testClass.getXmlTest());
    return xmlTest.map(XmlTest::getSuite).map(XmlSuite::getName).orElse("Undefined suite");
}
项目:allure-java    文件:AllureTestNg.java   
private static String safeExtractTestTag(final ITestClass testClass) {
    final Optional<XmlTest> xmlTest = Optional.ofNullable(testClass.getXmlTest());
    return xmlTest.map(XmlTest::getName).orElse("Undefined testng tag");
}
项目:allure-java    文件:AllureTestNg.java   
private static String safeExtractTestClassName(final ITestClass testClass) {
    return firstNonEmpty(testClass.getTestName(), testClass.getName()).orElse("Undefined class name");
}
项目:TestNG-Foundation    文件:ChainedListener.java   
@Override
public void onBeforeClass(ITestClass testClass) {
    beforeClass.add(testClass.getRealClass().getSimpleName());
}
项目:TestNG-Foundation    文件:ChainedListener.java   
@Override
public void onAfterClass(ITestClass testClass) {
    afterClass.add(testClass.getRealClass().getSimpleName());
}
项目:DolphinNG    文件:EmailableReporter.java   
/**
 * @param tests
 */
private void resultSummary(IResultMap tests, String testname, String style, String details)
{
    if (tests.getAllResults().size() > 0)
    {
        StringBuffer buff = new StringBuffer();
        String lastClassName = "";
        int mq = 0;
        int cq = 0;
        for (ITestNGMethod method : getMethodSet(tests))
        {
            m_row += 1;
            m_methodIndex += 1;
            ITestClass testClass = method.getTestClass();
            String className = testClass.getName();
            if (mq == 0)
            {
                titleRow(testname + " &#8212; " + style + details, 4);
            }
            if (!className.equalsIgnoreCase(lastClassName))
            {
                if (mq > 0)
                {
                    cq += 1;
                    m_out.println("<tr class=\"" + style
                            + (cq % 2 == 0 ? "even" : "odd") + "\">" + "<td rowspan=\""
                            + mq + "\">" + lastClassName + buff);
                }
                mq = 0;
                buff.setLength(0);
                lastClassName = className;
            }
            Set<ITestResult> resultSet = tests.getResults(method);
            long end = Long.MIN_VALUE;
            long start = Long.MAX_VALUE;
            for (ITestResult testResult : tests.getResults(method))
            {
                if (testResult.getEndMillis() > end)
                {
                    end = testResult.getEndMillis();
                }
                if (testResult.getStartMillis() < start)
                {
                    start = testResult.getStartMillis();
                }
            }
            mq += 1;
            if (mq > 1)
            {
                buff.append("<tr class=\"" + style + (cq % 2 == 0 ? "odd" : "even")
                        + "\">");
            }
            String description = method.getDescription();
            String testInstanceName = resultSet.toArray(new ITestResult[]{})[0].getTestName();
            buff.append("<td><a href=\"#m" + m_methodIndex + "\">"
                    + qualifiedName(method)
                    + " " + (description != null && description.length() > 0
                    ? "(\"" + description + "\")"
                    : "")
                    + "</a>" + (null == testInstanceName ? "" : "<br>(" + testInstanceName + ")")
                    + "</td>" + "<td class=\"numi\">"
                    + resultSet.size() + "</td><td class=\"numi\">" + (end - start)
                    + "</td></tr>");
        }
        if (mq > 0)
        {
            cq += 1;
            m_out.println("<tr class=\"" + style + (cq % 2 == 0 ? "even" : "odd")
                    + "\">" + "<td rowspan=\"" + mq + "\">" + lastClassName + buff);
        }
    }
}
项目:carbon-identity-framework    文件:CarbonBasedTestListener.java   
@Override
public void onAfterClass(ITestClass iTestClass, IMethodInstance iMethodInstance) {
    MockInitialContextFactory.destroy();
}
项目:tempto    文件:DelegateTestNGMethod.java   
@Override
public ITestClass getTestClass()
{
    return delegate.getTestClass();
}
项目:tempto    文件:DelegateTestNGMethod.java   
@Override
public void setTestClass(ITestClass cls)
{
    delegate.setTestClass(cls);
}
项目:AppiumTestDistribution    文件:AppiumParallelTestListener.java   
@Override
public void onAfterClass(ITestClass iTestClass) {
    ExtentManager.getExtent().flush();
    deviceAllocationManager.freeDevice();
}
项目:seletest    文件:InitListener.java   
@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
    PostConfiguration postconfigure = null;
    ITestClass testClass=method.getTestMethod().getTestClass();
    Class<?> webClass=testClass.getRealClass();

    if(testResult.getMethod().isAfterClassConfiguration() && testResult.getMethod().getMethodName().equalsIgnoreCase("afterClass")) {
        postconfigure=webClass.getAnnotation(PostConfiguration.class);
    }

    try{
        testResult.setAttribute("session", SessionContext.session());}
    catch(Exception ex){}

    if(method.getTestMethod().isTest()){

        //Wait for verifications to complete before finishing @Test (only for SoftAssert)
        if(SessionContext.getSession().getAssertion().getAssertion() instanceof SoftAssert){
            for(Future<?> a : (ArrayList<Future<?>>) SessionContext.getSession().getVerifications()){
                while(!a.isDone()){
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        log.error("Exception waiting future task to complete: "+e);
                    }
                }
            }
            log.debug("Async verifications finished for @Test {}",method.getTestMethod().getMethodName());
        }

        postconfigure = method.getTestMethod().getConstructorOrMethod().getMethod().getAnnotation(PostConfiguration.class);
        PerformanceUtils perf=SessionContext.session().getPerformance();
        SessionControl.verifyController().assertAll();
        if(perf!=null) {
            perf.getPerformanceData(perf.getServer());
            perf.writePerformanceData(new File("./target/surefire-reports/logs/"+testResult.getName()+".har").getAbsolutePath(), perf.getHar());
            perf.stopServer(perf.getServer());
            log.debug("Performance data collected for test method: {} !!!",method.getTestMethod().getMethodName());
        }
    }

    //Execute Method from Page Object or Page Facade prior to @Test execution
    if(postconfigure!=null && method.getTestMethod().getCurrentInvocationCount()==0) {
        log.debug("Postconfiguration steps will be executed now for @Test {} !!!",method.getTestMethod().getMethodName());
        executionConfiguration(postconfigure);
    }
}