Win a copy of Rust Web Development this week in the Other Languages forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

unable to print the annotation value

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi All,
I am using a selenium+cuke4duke tool to perform some GUI Testing and I am facing an issue with annotations

For a particular method i am using an assertion and this method calls another method of a different class
For e.g Method1 of class 1 is using assetion1 and Method1 calls Method2 which is in class2, now when the code is getting executed in method 2 what I want is that it should print the annotation of method1 .
Is there any way through which I can do it
The code for both the files are given below
StuffSteps.java---This file contains anotation
package com.pearson.psn.fixture.LRD;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import org.junit.AfterClass;
import org.junit.BeforeClass;

import junit.framework.Assert;


import com.pearson.psn.common.SuccessNetCommon;
import com.pearson.psn.dsl.SeleniumUtil;
import com.thoughtworks.selenium.SeleneseTestCase;

import cuke4duke.Given;
import cuke4duke.Then;
import cuke4duke.When;
import cuke4duke.After;
import cuke4duke.Before;

public class StuffSteps extends SeleneseTestCase{

public StuffSteps() throws Exception{
selenium = SuccessNetCommon.selenium;
}


@Given("I haveeee a saussage")
public void intentionallyPending() throws Exception{
}

@Then("I shouldfff have stomach")
public void iShouldHaveNCukes()throws Exception {

tpComm tp1= new tpComm();
tp1.comm();
}
@Given("I haveeee a saussage1")
public void intentionallyPending1() throws Exception{
}
@Then("I shouldfff have stomach1")
public void iShouldHaveNCukes1()throws Exception {

}
}


tpcomm ---- this is a temporary file for testing pupose here i tried to print the annonation @Then("I shouldfff have stomach") which is present in method iShouldHaveNCukes()

package com.pearson.psn.fixture.LRD;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class tpComm {



public void comm() throws Exception{

StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
StackTraceElement e=stacktrace[2];


Class clazz =Class.forName(e.getClassName());
System.out.println(clazz.getName());
Method m[] = clazz.getDeclaredMethods();
System.out.println(m[0].getName());
Method m1 = clazz.getMethod(m[0].getName());

Annotation[] annotations = clazz.getAnnotations();

for(Annotation anno : annotations) {

System.out.println("Annotation Type: " + anno.annotationType());

}

System.out.println(m1.getName());
System.out.println(annotations.length);

//System.out.println(m.getName());
String methodName = e.getMethodName();

String ClassName = e.getClassName();

//System.out.println(methodName);
//System.out.println(ClassName);

}
}


 
Sheriff
Posts: 22568
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please UseOneThreadPerQuestion. Let's continue here.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic