As we mentioned in “how to start guide” you can generate Java Class from *.graphml file which you created in yEd. First let’s go through the process of making one basic *.graphml file.
Let’s say that we want to make one login smoke test for a random website. The model can be look like the following:


The first think that you can notice, that you have to use just elements Rectangle (vertex in Graphwalker context) and Line (edge in Graphwalker context) of yEd Graph Editor to build a model file for test purpose. Edges are used for making one or more actions on a webpage. Vertices are used to make check of consequence from actions done by edge. Vertex in JUnit tests would be an Assertion. The correct routine is that you start the name of edges with letter ‘e’ (event) and the name of vertices with letter ‘v’ (verification). You also must start your model with a vertex called “Start”. This is one of the few rules that Graphwalker API have.

In this concrete situation we want to start a new browser, load our website, login to the website, and logout. The next step would be creating a Java *.class file from this *.graphml file. For this action we need to have three files in the same folder:

Now you can open Command Prompt (Windows) or Terminal (Linux) and locate your position to the folder where you have above mentioned three files. Run the next command:

  • In general situation:
  • java -jar graphwalker.jar source -f 'your graphml filename'.graphml -t ModelAPI.template > 'your Java class name'.java

  • In our situation:
  • java -jar graphwalker.jar source -f LoginModel.graphml -t ModelAPI.template >

It looks good, doesn’t it?!
If you open your Java class file, you can see that every edge and vertex are represented by one method in Java world. Your next step is to fill all of the methods with your java code. As we mentioned good routine is that you add actions to your “edge” methods, and assertions to your “vertex” methods. As you can see, you don’t have any methods with @Test annotation in this class. You have to create another class where you are going to put a method with @Test annotation and connect your *.graphml file and generated java *.class file. For this situation the method with @Test annotation should be the following:

ModelHandler modelHandler = new ModelHandler();
File loginModelFile = new File("'your location for the graphml file'/LoginModel.graphml");
Test testModel = new Test(loginModelFile, true, new A_StarPathGenerator(new EdgeCoverage(1.0)), false);
modelHandler.add("Test", testModel);
String actualResult = modelHandler.getStatistics();

You also have some combinations of stop criteria’s and path generators. We will describe it soon in our next posts.

Posted By Szabolcs Berkó

    One Response to “Graphwalker – how to make *.graphml file to use with Graphwalker API”

  1. Tom Cauley says:

    I used the code above with graphwalker 2.xx and it worked great – thank you. Now with graphwalker 3.4.2 modelhandler no longer exists. Have you figured out the code for the @Test annotated class to execute the tests in eclipse?

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>