The final step is to define XTrackWebARTInterface, which will hold the new methods we'll write to interface to XTrack using the WebART tool. Exactly what these new methods do depends on how you need to interface to a particular tool. Unfortunately, there's no free lunch. While the direct-call method requires exact knowledge of the system code, the test-tool method requires expert knowledge of that test tool. You need to know not just how to use the tool but how to interact with the tool from the language of the executable tests in this case, Java. One of the reasons we picked WebART for this illustration is that a Java package is available (jWebART) that makes the interface to the tool fairly painless (although it's still necessary to know how to use WebART itself to drive the system). Using jWebART, XTrackWebARTInterface looks like Listing 23.4. Listing 23.4 XTrackWebARTInterfaceimport jWebART.*; public class XTrackWebARTInterface extends XTrackTestInterface { public XTrackWebARTInterface() { super(); project = new WebARTProject("XTRACK"); script = new WebARTPersistentScript(project,"XTRACKIF"); } public boolean login( String id,String psw) { return script.invoke("login","psw=" + psw); } public boolean createUserId( String id, String psw, String email) { return script.invoke("createUserId", "psw=" + psw, "email=" + email); } public boolean deleteUserId( String id) { return script.invoke("deleteUserId", "docText">Starting with the first line, the import jWebART.*; statement tells the Java compiler where to find the code for interfacing to WebART in Java. Next, the XTrackWebARTInterface class is defined as extending the XTrackTestInterface class. This is just like the XTrackDirectInterface class.
In other words, if this interface is instantiated (XTrackTest.setTestInterface is called with a value of webart), it will start WebART, set the project to XTRACK, and start the XTRACKIF script. Of course, the XTRACK project and the XTRACKIF script will have to already exist, and we'll have to take care of that within the WebART tool itself. Finally, we have the login, createUserId, and deleteUserId methods. These call the invoke method in the WebARTPersistentScript object to pass their arguments to a subscript in the XTRACKIF script. The first parameter of invoke is the name of the subscript, and subsequent parameters are the names and values of the parameters to be passed to the subscript. At this point, we've completed interfacing our tests with the WebART tool. If we compile all our tests again, they'll still go through the direct interface because of the setTestInterface("direct"); in XTrackTest. It would be good practice to do that and make sure the tests all still pass before going on. Now we change XTrackTest to setTestInterface("webart"); , recompile it, and all the same tests now go to the WebART tool. Most of them fail, because we haven't done any work in WebART to set up the XTRACK project or create the XTRACKIF script. The next chapter will show you how to do that. Don't worry, things will get easier. We'll start our downhill run pretty soon! |