Forum Discussion

IgorVM's avatar
IgorVM
New Contributor
12 years ago

Calling function from another project

Can I call function from another project, except copying Script from one project to another(I mean this article http://support.smartbear.com/viewarticle/11306/) I have function in Script at another Project, and I want to use them in my Project. A both projects are in one Suite.

4 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Igor,



    Two options are possible:

    a) Add the unit as Existing One (as described in the help article referenced by you). This will not create a copy, but reference existing unit from another project. Changes made to the script code will be available in both projects. And

    b) Move the needed code to the Script Extension. You will have to install this Script Extension on all machines running tests that make use of extension's functionality, but, on the other hand, no referencing from within test project(s) is required.
    • vik33's avatar
      vik33
      Occasional Contributor

      i have a realted issue:

       

      I have tried both the methods to call a function from another project. Call goes fine but script execution fails due to object not found error. How would i make use of the NameMapping objects that belong to Project 2.

      To make it simple:

      ' Unit A has a reference for unit B
      'Unit A is in Project A
      'call is from unit A to --> sub B of unit B

       

      Unit A
      'calling sub B from unit A (below statement)
      unit B.Sub B

      -------------------------------

      'Unit B is in a Project B and has its own Namemapping.
      Unit B

      Sub B
      ' here obj_B is getting used.
      end sub

       

      Here is the issue:
      NameMapping for Project A has something like:
      Aliases.Process_A.obj_Parent.obj_A

       

      NameMapping for Project B has something like:
      Aliases.Process_A.obj_Parent.obj_B

       

      The script tries to find obj_B in the NameMapping for Project A which is what causing it to fail.

      How would i make sure that obj_B should be found in NameMapping of Project B?

       

      Please note that if i execute Sub B from project B on its own (without calling it from Proj A) then it passes without any issues.

      Please help.

      Many thanks.

      -vik

      • NisHera's avatar
        NisHera
        Valued Contributor

        In simple terms Project A uses mappings in project A not B

        Even if it reffers project B.

         

        So you should have Aliases.Process_A.obj_Parent.obj_B in  project A.

        You can merge Mapping of B with Mapping A link

         

        what I do is keep common namemapping file so that project A,B, and C all refres to one file