0

We are having test automation project in selenum with testng. We have completed half of the automation project and running it successfully. Now, we have to add new feature to create flow of testing with multiple test methods. So, for this I have to create java ui which will display all the methods created for test, based on user requirement the methods will be selected for test flow, now when user click on save or run button I have to create the testng.xml file which will run the test for selected methods.

Now Questions I have is as follow: 1. Is it possible to generate dynamic xlm file? 2. In test class I have multiple methods which are depended on other methods of class, so if user select depended methods on ui how I should manage those methods? 3. How to show created methods from all the class on ui to generate flow? 4. Is it good to call bat file to run the generated flow?

I would appreciate your inputs.

Thanks, Karim

Karim Narsindani
  • 434
  • 3
  • 14
  • 38

3 Answers3

1

if i understanded your question you need to generate xml files that would be tested or something like this for [xml] (How to generate xml in Java?) or (Fastest and most efficient way to create XML) all you have to do to create a class similar to XMLEncoder and XMLDecoder wich use beans.

Community
  • 1
  • 1
1
  1. Is it possible to generate dynamic xlm file?

Yes. We do this, we generate the xml from a text file which lists the classes they want to run.

  1. In test class I have multiple methods which are depended on other methods of class, so if user select depended methods on ui how I should manage those methods?

Well you can add the dependent methods when the user selects a method automatically, in which case your code will need to have a map of dependent methods.

How to show created methods from all the class on ui to generate flow? 4. Is it good to call bat file to run the generated flow? - I didnt understand this part.

Shamik
  • 1,591
  • 2
  • 16
  • 36
  • How to show created methods from all the class on ui to generate flow?- We have multiple class which has test method like, testmethod1(), testmethod2(), testmethod3(). I want to show this method on GUI which I will create, so that my manager or client just need to select test method which they want to test. – Karim Narsindani Dec 31 '14 at 07:21
  • If your test classes are implementing iTestClass you can check this - > http://testng.org/javadocs/org/testng/ITestClass.html , there are host of methods , you can use getTestMethods() to get all the test methods. Check it. – Shamik Dec 31 '14 at 07:44
  • Hi thanks for your valued inputs, based on you answer I google it and I got the solution, well I am not able to past the code here but see the answer... many thanks – Karim Narsindani Dec 31 '14 at 17:40
1
Using below code you can get all the method with @Test annotation....

---
import java.lang.reflect.Constructor;

import java.lang.reflect.Method;
import java.util.Set;
import org.testng.IAnnotationTransformer;
import org.testng.annotations.ITestAnnotation;
import org.testng.annotations.Test;
import org.testng.internal.ClassHelper;
import org.testng.internal.annotations.AnnotationHelper;
import org.testng.internal.annotations.IAnnotationFinder;
import org.testng.internal.annotations.JDK15AnnotationFinder;

public class FindTestMethodsInTestClass {

    public static void main(String[] args) {
        IAnnotationFinder finder = new JDK15AnnotationFinder(new DummyTransformer());
        Set<Method> allMethods = ClassHelper.getAvailableMethods(MyFirstTestClass.class);
        for (Method eachMethod : allMethods) {
            ITestAnnotation value = AnnotationHelper.findTest(finder, eachMethod);
            if (value != null) {
                System.out.println(eachMethod.getName() + " is a test method");
            } else {
                System.out.println(eachMethod.getName() + " is NOT a test method");
            }

        }

    }

    public static class DummyTransformer implements IAnnotationTransformer {

        @SuppressWarnings("rawtypes")
        @Override
        public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor,
                Method testMethod) {
        }

    }

    public static class MyFirstTestClass {

        public void foobar() {

        }

        @Test
        public void foo() {

        }

        @Test
        public void bar() {

        }
    }

}

The reference of above code is from: https://groups.google.com/forum/#!topic/testng-users/WbR2kxpT-7o

Karim Narsindani
  • 434
  • 3
  • 14
  • 38