How to define Global Variables within Scripts, i.e. "on the fly"?


#43

Do you use Git remote repository to share code with your collegue?
GitHub, Bitbucket on internet, or GigLab on your companies interanet?

So far, we haven’t. But for other purposes Bitbucket is already used in our company (only not yet by me). That’s why it’s exactly what we’re planning for the distributed work on Katalon Studio projects.


#44

I suppose my approach is not well fitting to your case. I suppose all
you need is some tool to copy the Groovy source codes you developed into
the target Katalon project, that’s all. Do you agree?

No, I don’t think so. In my other thread on this topic I had already described our situation in more detail:

I have developed some Custom Keywords for various Katalon Studio
projects in our company. Up to now I synchronized the contents of the
last edited project’s Keywords directory manually to the Keywords
directories of all other projects. However, this process is becoming
increasingly confusing and error-prone.

In addition, we will
continue to work on the projects in distributed teams in the future,
whereby I will take care of the further maintenance of the Custom
Keywords as well as the initial creation of new Test Suites. On the
other hand, the product managers and developers of the applications to
be tested should be able to edit the Test Suites (and especially the
included Test Cases) independently in the event of necessary adjustments
and, if necessary, also jump back to earlier versions of my Custom
Keywords basis.

Therefore I would like to maintain and version my
Custom Keywords a little more professionally as a general code base for
all projects. But as far as I understand the interaction between
Katalon Studio and Git so far, the testing projects can only be
versioned as a complete package, right?

So I guess the best way
to achieve my goal would be to pack my Custom Keywords into jar
libraries that could then be included in any other Katalon Studio
projects. Unfortunately, I have no experience with Java projects in
general or with Maven in particular - is this where Maven comes in? Or
is there another “best case” to implement this? And what exactly would I
have to do?

So two important requirements would be that the code for the Custom Keywords and, on the other hand, the code for the Test Suites (especially the Test Cases) as such …

  1. could be further developed independently of each other and
  2. could be combined with each other as desired.

I think that’s exactly why it will be necessary to pack the Custom Keywords into a jar file that I can version and distribute separately, don’t you think?

I’ve heard of Git also supporting so-called submodules for such purposes. However, I was strongly advised against using them because of their error-prone handling.

Finally, with all these thoughts in mind, I wonder how I could easily compile my Keywords Groovy files (without the entire Eclipse overhead, if possible) and and make them available as jar libraries to other teams using the Katalon Studio testing projects.


#45

this process is becoming increasingly confusing and error-prone.

Could you please describe a bit more? What sort of confusion have you ever got? What type of error you have got?


#46

The confusion arises from the manual process alone: Because I edit these “general” Custom Keywords in parallel, sometimes for one, sometimes for another Katalon testing project. Since each Katalon project has its own folder structure with its own Keywords directory, I have to make sure that I always work on the latest versions of my Groovy files. Therefore, of course, I think it makes sense to use some kind of versioning process, also for this Keywords basis in the future.


#47

I have an idea how to implement a way to share the custom keywords developed in your Katalon Studio project among other projects for your team members. The idea differs from the one I used in my “HappyMigrationSiteTest” project. Let me work out for a couple of days implementing my new idea.

Once done, I will create another post because it will be far off-topic from this thread.


#48

You are just incredible, you know that? :slight_smile: Thank you already for your great effort! Maybe you could consider leaving your follow-up post in my other thread, which I had actually opened just about this new topic:

How to create jar libraries from Custom Keywords?

Or is your idea about another topic?


#49

Drunda,

Just now I found that Katalon Studio ver 5.5 supported a feature Import/Export Keyword. I think this is exactly what you need.

I can imagine a scenario for you

  1. You create a Katalon Studio project called “OurCustomKeywords” where you develop a set of custom keywords which is designed for portability across your projects. You put the project into souce control by Git. You would post it to some remote repository such as GitHub and BitBucket on Internet or GitLab on your intranet.

  2. Your team would create some Katalon projects for your Web Applications. In each project, testers imports your custom keywords out of the “OurCustomKeywords” repository on BitBucket.

  3. You would do appropriate version control and putting tags to the “OurCustomKeywords” project. When you want to redistribute the upgrades, you would send a email to your team saying :

    The OurCustomKeywords ver X.X is released. Please import the lastest one into your testing project. URL is http://xxxxxxxxx and the package to import is xxx.xxx.xx.xxxxx.

The following figure shows what happens when you do ‘import Keywords’.

Reusing Custom Keywords across projects.png


#50

In the Katalon Forum I have found several posts asking how to share artifacts developed in a Katalon Studio project with others.

  1. Drunda Nibel wants automated code sharing
  2. how to create jar libraries from custom keywords
  3. Sharing test cases or keywords to multiple projects
  4. Sharing methods between tests
  5. Is it possible to share test case between different projects?
  6. sharing of test cases
  7. Is there any way to share test listeners and custom keywords code to multiple projects?

I suppose that many of the questioners above do not know what Git is and how it can help them.

Here I would define a word artifacts of a Katalon Studio project includes the following stuff:

  • Test Cases
  • Test Suites
  • Test Objects
  • Custom Keywords
  • Test Listeners

If you have a single Web Application and 2 or more people work together to test it, then the best solution is, as Vinh Nguyen mentioned in “Sharing test cases or keywords to multiple projects”, to create a Katalon Studio project and put it into a remote Git Repository. In the following figure, Alice and Bob share all artifacts of the project X via a Git remote repository. They will fully version-control the project and put tags to versions. The access to the Remote repository will be well administrated by the hosting services (GitHub, BitBucket etc)

Sharing project by remote Git repository

Perfect solution, isn’t it?

However, what would happen if your team has multiple Web applications to test and therefore you have created 2 or more Katalon Studio projects? It is quite likely, you would want to reuse some artifacts across projects.

In my humble opinion, among the types of test artifacts in Katalon Studio, only Custom Keywords is designed to be portable across projects. All the other types (Test Cases, Test Suites, Test Objects, Test Listeners) are not. I would not discuss this point here. I think this design decision is reasonable. I would be happy if only I can safely reuse my custom keywords across projects.

Here comes the new feature “Import/Export Keywords” comes in.


#51

Just for your reference: my re-invented wheel is here


#52

Kaz, this should be written (edited) to add to the website. Superb and detailed explanation.


#53

Kazurayam,

Sorry for beeing late, I was and still am currently on vacation. You did a great work! I’m very sorry that your efforts were in vain. But actually you seem to be right that the new “Import from Git” function is exactly what I need!

I’ll try that once I get back to work, but I think it really does fit the concept of how we want our teams to work together on projects and custom keywords in the future.

Thanks a lot, dear kazurayam, one more time! :slight_smile:


#54

I’d like to give you a little summary after using the new Katalon Keywords import function as kazurayam indicated above. I.e., I version my central Keywords projects using Git (Bitbucket), where I omit the contents of all other, not needed subdirectories except the Keywords subdirectory via .gitignore.

But the catch is:
When importing such a Keywords project versioned by the Katalon built-in Git client into the target Keywords folder, the original Keywords root folder itself is of course also imported, so that one “Keywords” directory level is created too much. Of course, this can be easily fixed in the target project by renaming the Keywords package name directly in Katalon Studio. But this doesn’t seem to be a very well thought-out solution. The alternative would be to use an external Git client to version only the central Keywords subdirectory itself and not its entire project folder.


#55

I know. “Import Keywords from Git” is badly designed. See my previous post:

I was amazed at this oddity.

However I found “Import Keywords from Folder” is useful as it enables me to choose which folder to import.


#56

I am now trying to combine a Katalon Studio project and a Gradle project into one file-tree which is version-controlled by Git. Gradle is the de-facto standard “build automation tool” for Java/Groovy world.

Importing/Exporting Keywords is in fact just copying a file tree from xxx to yyy. Gradle can manage copying/deleting/renaming/zipping/unzipping files far better than Katalon. I would like to make use of Gradle functionality to supplement Katalon Studio in managing test fixtures and test results in 100% customizable way.

The problem I am currently focused is: Export/Import Browser Cookie.

I want to execute Katalon test using Browser with pre-cached Cookies. Some web application provides “customized view per each user” using Cookie as session control information. I want to test if the session control is properly designed and functioning with dirty Cookies. In order to test it session control by dirty Cookies, I need to “Export/Import Browser Cookie” for Katalon project. I believe I can manage preparing the test fixture using Gradle.


#57

Oh, is this another new feature I’ve overlooked so far? I’m not at work at the moment and can’t look at it until later …


#58

As I unfortunately only noticed now, Sergii Tyshchenko had already presented the solution for my original problem, how to declare global variables dynamically at runtime (without any manual preparation in the profile menus of Katalon Studio). Nevertheless, this is still a very useful insight for me!


#59

TIme passed and the Forum system changed. New URL to Sergii’s post is here

I was surprised to find the post is dated at Jun, 2018 — also surprised that I made some comment to the same discussion but I forgot it at all. ---- in fact, I did not know Groovy metaprogramming then and could not understand Sergi’s code.

The pioneer of metaprogramming in Katalon Studio is here, Sergii.


#60

kazurayam,

because I just stumbled across this old thread again and your plan at that time regarding Gradle: Did you pursue this any further? I ask, because beyond the version control with Git, which is actually needed for teamwork, I could never really get to grips with the idea to redundantly copy any artifacts (be it required jar libraries, data files, browser extensions or even keywords files) from their respective sources into the individual project (sub)directories.

Have you ever considered using symlinks for this? I don’t know under which operating system you work, but for me it was just a surprising revelation that symlinks are as powerful on Windows as they are on Linux - and make permanent synchronization completely superfluous. That’s why I now work with an overall setup where the central development and versioning of my keywords takes place in separate projects. Thanks to the symlinks, the respective development status there is always immediately available in all my test-suite development projects. But of course I don’t push the keywords into their remote Git repositories until they has been sufficiently tested so that I can release them for productive purposes. So it is of course no problem to manage these central keywords development projects with an external Git client in such a way that only the respective keywords subdirectory is contained in the corresponding repository and can therefore be easily imported from there into the productive test-suite projects with exact that function which ist provided therefore in Katalon Studio.

In the end quite simply and effectively solved, don’t you think?


#61

Depencencies to external jar files can be resolved by com.katalon.gradle-plugin. Have a look at the following topic:


#62

No.

How do you automate setting up symlinks for you? Unless automated, it would not be a favorable solution for you. Katalon Studio will NOT help for managing symlinks at all. Then how?

Will you use Gradle to automate symlinks management? It would be possible. But Gradle is a huge accumulation of tools. You may find it difficult to learn.