Axe Test Automation PlatformGeneral discussion relating to the Axe Test Automation Platform from Odin Technology |
||
Posts by Odin employees marked:
|
AXE V3.2 Selenium (JAVA)
Hi I have previously added a load function to generate today's date in the format "dd-MM-yyyy": Dispatch.put(axe, "Data", new SimpleDateFormat("dd/MM/yyyy hh:mm a").format(Calendar.getInstance().getTime())) with the imports: import java.text.SimpleDateFormat; import java.util.Calendar; The next step is date manipulation as this application will require functions to set dates based on the current system date plus/ minus dd MM or yyyy I would like to generate a function where the user specifies: Parameter 1 as the format (will be either "dd-MM-yyyy", "dd", "MM" or "yyyy") Parameter 2 as the date-part to add/ subtract values from (DAY_OF_MONTH, MONTH, YEAR) Parameter 3 as the value to add/ subtract from that date-part Could you suggest a useful function? I can't seem to amend my existing function. Here follows the point I have got up to (this returns a java:223 'void' type not allowed here error): Dispatch.put(axe, "Data", new SimpleDateFormat("%PARAM1%").format(Calendar.getInstance().add(Calendar.%PARAM2%, %PARAM3%))) Many thanks in advance!
Hi Mark,
There is a bug in your java code; the add method is a void, so you need to invoke it on an instance of a Calendar object. It is always best to unit test any custom function in isolation from Axe, prior to wiring them up via the ActionMap. This will make debugging problems like this much easier since it is clearer where any problems lie. Here is a working example of using the Java add() method: Calendar c = Calendar.getInstance(); c.add(Calendar.DATE, 1); System.out.println("time: " + new SimpleDateFormat("dd/MM/yyyy hh:mm a").format(c.getTime())); So to integrate this with Axe I would recommend that you encapsulate this in a method in your own local function library. Sam
Thanks Sam
I have a class file and a java file which you provided for the custom library at present (and can create a jar file using a batch file you previously provided). I have eclipse set up and I know how to add a function to the .java file - however I am not sure how the .class file is created Thanks Mark
Mark,
Do you have access to anyone on your team with java experience who can help you? I could enhance the earlier sample I gave you but cant commit to a date as we are in the final stages of the Axe 3.3 release. Sam
Hi Mark,
Here is a full example. Custom method for local java function library: public static String dateAdd(int fieldNumber, int delta, String format) { Calendar cal = Calendar.getInstance(); cal.add(fieldNumber, delta); return new SimpleDateFormat(format).format(cal.getTime()); } ActionMap entry: class: N/A action: load.future(days) command: Dispatch.put(axe, "Data", CustomLib.dateAdd(Calendar.DATE, %PARAM1%, "dd/MM/yyyy hh:mm a")) documentation: Get a date that is %PARAM1% day(s) in the future Sample step to get a date 7 days ahead: load.future(7) |