Radek
Radek

Reputation: 11121

how to write custom function/method in java? (RFT)

I need to process few lines of code over and over in RFT (java) so custom method/function/procedure is the best (and only) solution to this.

I have no java experience so I need some help with that.

The method will receive some parameters and will return no value.

Basically it will be entering new records into a database (web based application). How many records? It depends on data so I need to make it argument based.

the current code looks like

    text__firstname(ANY,NO_FLAGS).setText(dpString("StudentName"));
    text__surname(ANY,NO_FLAGS).setText(dpString("StudentSurnameName"));

in php the desired function would look like

   function add_student($first_name,$surname){
    text__firstname(ANY,NO_FLAGS).setText($first_name);
    text__surname(ANY,NO_FLAGS).setText($surname);
   }

so I can call it

   add_student(dpString("StudentName"),dpString("StudentSurnameName"));

Upvotes: 0

Views: 2594

Answers (3)

Sathish
Sathish

Reputation: 11

You can write a method like this..

public void setTextValues(TestObject firstName , TestObject surName){

while(dp.dpnext()){
firstName(ANY,NO_FLAGS).setText(dpString("StudentName")); 
    surName(ANY,NO_FLAGS).setText(dpString("StudentSurnameName"));


}

}

dpnext command automatically iterates to the next record in data pool.

Hope this helps you!!

Upvotes: 1

Radek
Radek

Reputation: 11121

so I was looking for something like that

private boolean add_student($first_name,$surname){

  text__firstname(ANY,NO_FLAGS).setText($first_name);
  text__surname(ANY,NO_FLAGS).setText($surname);
  return true;
}

Upvotes: -1

Beth Lang
Beth Lang

Reputation: 1905

I'm a .net person more than a Java person but it should go something like the below, I've also never used RFT so I'm assuming that the inner text works. You will have to replace the ReplaceWithType with whatever type text__firstname and text_surname are.

public void AddStudent(ReplaceWithType text__firstname, ReplaceWithType text__surname)
{
    text__firstname(ANY,NO_FLAGS).setText(dpString("StudentName")); 
    text__surname(ANY,NO_FLAGS).setText(dpString("StudentSurnameName"));
}

I would recommend that you take a look at the Java API and get a good Java book.

Upvotes: 1

Related Questions