0

I'm having trouble rewriting java test cases in robot framework.

in order to do this, i need to create new java keywords, but the way tests are implemented, don't make it easy !

this is an example of script that i need to rewrite in RF :

try
{
  ServerSocket server = Utils.startSocketServer; 
  while(true)
  {
    Socket socket = server.accept();
    ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
    RequestX request = (RequestX) ois.readObject();
    if(request.getSource().equals(String.INFO)
    {  
      /** do something  **/
    }
    else if(request.getSource().equals(String.X)
    {
     /** do something  **/
    }
    else 
    {
     /** do something  **/
    }
    /** break on condition **/
  }
    Utils.closeSocketServer(server);

}catch(Exception e)
{
   /** do something **/ 
}

Any suggestion on how i can make this into a RF test case !

Make the whole script into a single keyword is not an option because somewhere in that loop, in the do something comment, i also need to call keywords.

The main idea is to fragment this script into functions so that i can use them as java keywords in RF but i still can't figure this out!

khaled
  • 33
  • 3
  • 7
  • Can you add the robot script that you currently have? At [SO] it is expected that the user has invested some time in their solution prior to posting a question on [SO] and shares these details in their question. In the [How do I do X](https://meta.stackoverflow.com/questions/253069/whats-the-appropriate-new-current-close-reason-for-how-do-i-do-x) discussion more information on this expectation can be read. – A. Kootstra Mar 04 '18 at 19:34
  • i did, now i'm trying something else. will post update soon ! thanks for reply – khaled Mar 05 '18 at 09:49

1 Answers1

0

So, i did further researches and this is what i came up with :

Split this code into functions so that i can call and use them as keywords in robot framework. So code became like this :

public static String SendTask(String taskFile)
{
  ServerSocket server = null;
  try
  {
    server = startSocketServer();
    if (taskFile != null)
    {
       Utils.sendJMSWakeUp();
       while(true)
       { 
         Socket socket = server.accept();
         ObjectInputStream ois = getInputStream(socket);
         RequestX request = (cast)ois.readObject();
         if (getSource(request,Strings.INFO)
         {
          /** log info **/
         }
          /** if the current jms queue is Scheduler then send task !*/
         else if (getSource(request,Strings.SCHEDULER))
         {
          /** send task **/
          break;
         }
       }
   }
   else   
   {
      assertion(false, "Illegal Argument Value null");
   }  
  }catch (Exception e)
  {
    /** log errors **/
  }finally
  {
   /** close socket server & return a task id **/
  }
}

the same goes for every JMS queue that I am listening to

public static String getTaskAck(String taskId);

public static String getTaskresult(String taskId);

it did work in my case for synchronous task execution. But this is very incovenient for asynchronous task execution. Because each time i'll have to wait for response on keyword, so the next keyword may fail because the response that he is supposed to read was already sent !

i could look into process BuiltIn library or RobotFramework-Async library for parallel keyword execution but it will be harder to process for many asynchronous jms messages.

After further investigation, i think i will look into robotframework-jmsLibrary. some developpment enhancement has to be done like adding activeMq. This way, i can send and consume many asynchronous messages via activeMq then process every message via robotframework-jmsLibrary Example : RF-jmsLibrary <==> synchronous <==> activeMq <==> asynchronous <==> system

khaled
  • 33
  • 3
  • 7