Forum Discussion

TSchlick's avatar
TSchlick
Occasional Contributor
9 months ago

Can I make class objects global to all projects in a project suite?

I am taking over a Project Suite and implementing Page object model. Currently the object class are within a single project and other projects that use those class objects import them from the original project. The issue is that the imported file can be changed and the original will remain the same. I want to be able to have the class objects global to all the projects without having to import them. Can this be done?

10 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    See Import Functions Dialog

     

    I have a project called Common, which has various methods in a singleton class called Settings. The module export is defined as module.exports.Settings = Settings;

    In another project called Dashboard, I import Common. So that I can access the methods that I need via var settings = Common.Settings.getInstance(); settings.Wait(); 

    • TSchlick's avatar
      TSchlick
      Occasional Contributor

      Yes this is how I have it now. The issue is that across the projects that import that class changes have been implemented to the imported versions and those changes are not updating original. So as I look through this project I see redundant functionally implemented various different ways across all the projects in the imported versions of the class. So would it be posable to have the classes global so they do not have to have to have imported versions to start with?

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    If I understand correctly, it's not possible. If for example, you did have a "global class", how would other projects use or reference this class if it's in another project? Also, how would developers know if there's an existing method? It might be documented, but these days no one reads specs!

     

    My team of developers always discuss if there are any existing methods which they can use to perform a particular task, before creating a new method. But this requires knowledge of the software. 

     

    Testers may create a function on the project they are working on, I'll review their code and I will usually point out there's an existing method in the Common project that they can use. Again, this requires knowledge of the software i.e. being test automation framework.

    • TSchlick's avatar
      TSchlick
      Occasional Contributor

      Thank you for help. Unfortunately when I took over the project there was no handoff and it had testers writing redundant functionality for years everywhere with no oversight. I am just trying to figure out a way forward that will keep the project clean.  Thanks Again!

  • TSchlick's avatar
    TSchlick
    Occasional Contributor

    Thanks, a refactor is the path I am taking. I have found that VS code works really well with the TestComplete extension. It gives you a little more then Notepad++ can. 

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I'm slightly confused.

     

    You use the import function, to call routines that are declared in another unit. This adds a reference to the other units to the current script unit. Similar to USEUNIT. Also, it's similar to import in Python, using in C#, #include in C++ etc.

     

    If I add or edit a method which is used throughout all projects, then I have to make the changes to Common unit in Common project.

    • TSchlick's avatar
      TSchlick
      Occasional Contributor

      I understand that this is where the changes should happen but across the developers that worked on this project prior to me this is not how it was being done. My hope was that there is a way to make the classes global so there is not an imported version that can be altered allowing for buried redundant code. If this is not posable please just let me know. Thanks

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    You can do code refactoring, but it requires careful thinking. Unfortunately, TestComplete is not Visual Studio, so it won't provide you with function/method statistics of usage.

     

    You'll have to do search/find for functions and see if it's being used anywhere in code. This can be easily done in Notepad++ e.g. searching in all JavaScript files.

     

    I've written my automation from scratch, and I've refactored it a few times. It's been designed in a way, where other testers can write scripts based on existing format/structure etc, and I also perform code review, to ensure they are following the format/structure.