Forum Discussion

tomaszarmata's avatar
tomaszarmata
Contributor
9 years ago

Extending classes in Script Library

Hello,   There is a way to extend class from other file in script library?   For example I have 2 files: class1.groovy and class2.groovy. And inside class2.groovy I want to write class2 which wil...
  • nmrao's avatar
    9 years ago

    You can do every thing in groovy that you do in Java.

     

    I know you may use these classes in ReadyAPI-<version>/bin/script directory

    For eg:

    Person.groovy

     

    class Person {
      def firstname
      def lastname
      def age
    }

    Student.groovy

     

    import Person
    
    class Student extends Person {
       def class
       def department
    }
        

    You may have both in scripts directory or you can use them in groovy step as well.

     

    Say, below is your groovy script test step which shows how to use above created classes.

     

    import Student
    import Person
    
    def person = new Person(firstname: 'John', lastname: 'Miller')
    def student = new Student(firstname: 'Philips', lastname: 'Mark', class: 'B.S', department: 'Mathematics')