Forum Discussion

Adagio's avatar
Adagio
Frequent Contributor
7 years ago
Solved

Reuse/Reference a common library in TestComplete projects

Hi,

 

I have a set of few .js (javascript) files which have reusable routines. These are good enough to be used a set of libraries across different projects.

Here are a couple things that I'm trying to do:

 

1. Reference these files in many different projects

2. Make updates or add more routines to these files for any project in TestComplete, and save these changes.

3. Whenever the new changes are saved to these files, I should be able to commit these changes to update the git repo, so that other people who are using these files would be able to fetch the latest code from the repo.

 

I've not been able to accomplish any of the above-mentioned steps yet. If anyone has done this before or can give some ideas, that would be really great!

 

any help would be greatly appreciated!

 

Thank you

Abhi

  • I do it all the time.

     

    The easiest way is to, in any project you want to use the reusable routine, right click on the Script node, select "Add -> Existing Item", navigate to the item and click OK.  The file is now associated with the project.  Now, whenever you make a change to that file, any project that uses the file will get the updates immediately.  As long as the path where the file resides is part of your git repo, it should be available to git.

     

    So... the question is... you say you've tried stuff and not been able to do it... what have you tried? What errors are you getting? What problems are you having?  What you've described is a fairly standard use case for TestComplete so I'm curious as to why it's not working for you.

5 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    I do it all the time.

     

    The easiest way is to, in any project you want to use the reusable routine, right click on the Script node, select "Add -> Existing Item", navigate to the item and click OK.  The file is now associated with the project.  Now, whenever you make a change to that file, any project that uses the file will get the updates immediately.  As long as the path where the file resides is part of your git repo, it should be available to git.

     

    So... the question is... you say you've tried stuff and not been able to do it... what have you tried? What errors are you getting? What problems are you having?  What you've described is a fairly standard use case for TestComplete so I'm curious as to why it's not working for you.

    • Adagio's avatar
      Adagio
      Frequent Contributor

      Hey Robert! Thanks for quick response. What I've tried so far and still want to do is, keep the 'reusable' project separate. That would have .mds file. Now, I want to import this 'reusable' project in the different project suites, and reuse the .js files from 'reusable' project. Any updates made to those files would be saved, and can be committed to the repo. 

       

      right now, I'm not able to use that project and reference the files in different project suites.

       

      Thank you

      Abhi

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Correct... Projects cannot be imported into other projects, only the JS script files themselves.  You need to include the JS files in each project.  Now, when you make a change to the JS file, it WILL affect all projects it is included in. 

         

        Think of each project in the same way as you would think of an application.  If you have shared code you want to share across applications, you include the source code in each application, you don't include the application.  So, if you want to use script code in multiple projects, you need to include the script code in each project.  As noted in my earlier message "Add -> Existing Item" is the way to do this.

         

        Now... another way of doing this is to wrap each JS file as a ScriptExtension.  Now, note that the script extension uses JScript as the code base so there are certain JavaScript things you can't do as ScriptExtensions.  But the end result is that you will have these sets of objects that will be automatically included in any project. When you update the code in the extension, it is automatically available to any machine with that extension installed.

    • Adagio's avatar
      Adagio
      Frequent Contributor

      Thank you, Robert! This works.