vendredi 4 mai 2018

Use reflection to create a dynamic object of a Class with Parameterized constructor

I have a enum of that has locator,classname.

public enum listofclasses{
    note(By.css(".notes", "NotesPage"),
    document(By.css".docs", DocumentsPage");
}

Public NotesPage a extends BasecustomerPage{
    public a(BasePage owningPage){
    }

    public pageisdisplayed(){
    }
}

when i Am running the test with Junit my test has to create dynamic object of the class based on string passed.

@Test
public class test(){
    for(listofclasses list : listofclasses.values ){
        String className = getclass(list);

        Class<?> cls = Class.forName(className);
        Object clsInstance = (Object) cls.newInstance();
    }

How do I get the parameterized constructor and access the methodsof the class





Aucun commentaire:

Enregistrer un commentaire