1. Listing Profiles and GlobalVariables defined in the Profiles storage
When you want to use GlobalVariables in a Katalon Studio project, you need to work in the Katalon Studio GUI and create a Profile in the Profiles
directory. In Profiles you will declare some GlobalVariable (s) with name and initial values.
If you have got many Profiles and many GlobalVariables defined, you are likely to get lost where a specific name of GlobalVariable is defined. Unfortunately Katalon Studio provides no API which scans through the entities contained in the Profiles
directory. So, this library provides some Custom Keywords that enable your test scripts look over the Profiles and the GlobalVariables defined in the .glbl
files under the Profiles
directory.
1.1 List all Profiles
Given that there are many Execution Profiles defined in a project, for example like this:
Problem to solve:
I want my test script get a list of all names of Execution Profiles and print them in the console.
Sample Test Case:
// Test Cases/main/1_listing/1_listAllProfiles
List<String> profiles = CustomKeywords.'com.kazurayam.ks.globalvariable.LookOverExecutionProfilesKeyword.listAllProfiles'()
for (String profile in profiles) {
println profile
}
Output:
2022-05-06 22:32:10.453 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2022-05-06 22:32:10.458 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/main/1_listing/1_listAllProfiles
2022-05-06 22:32:11.169 INFO k.k.c.m.CustomKeywordDelegatingMetaClass - com.kazurayam.ks.globalvariable.ProfilesHelper.listAllProfiles is PASSED
default
demoDevelopmentEnvironment
demoProductionEnvironment
main_category0
main_category1
main_category2
main_category3
main_envDevelopment
main_envProduction
main_envStaging
main_includeSheets_ALL
main_includeSheets_CompanyA
main_includeSheets_CompanyB
main_includeSheets_CompanyC
main_includeSheets_GroupG
main_includeURLs_ALL
main_includeURLs_login
main_includeURLs_top
test_A
test_B
test_C
2022-05-06 22:32:11.228 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/main/1_listing/1_listAllProfiles
1.2 List profiles filtered by name with regex
Problem to solve:
I want my test script to select some of Execution Profiles filtered by name with Regular Expression.
Sample Test Case:
// Test Cases/main/1_listing/2_listProfiles
List<String> filtered = CustomKeywords.'com.kazurayam.ks.globalvariable.LookOverExecutionProfilesKeyword.listProfiles'("test_\\w+")
for (String profile in filtered) {
println profile
}
Please note, "test_\\w+"
is a Pattern of Regular Expression in Java. It matches with a Profile name that starts with a string “test_” followed by 1 or more alpha-numeric characters. For example, the Profile test_A
does match, but the Profile default
doesn’t.
Output:
2022-05-07 09:35:09.118 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2022-05-07 09:35:09.122 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/main/1_listing/2_listProfilesFiltered
2022-05-07 09:35:09.767 INFO k.k.c.m.CustomKeywordDelegatingMetaClass - com.kazurayam.ks.globalvariable.ProfilesHelper.listProfiles is PASSED
test_A
test_B
test_C
2022-05-07 09:35:09.822 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/main/1_listing/2_listProfilesFiltered
1.3 List all GlobalVariables defined in the Profiles directory
Problem to solve:
I want my test script to list all GlobalVariables defined in all Execution Profiles. If a single GlobalVariable name appears in 2 Profiles, I want 2 lines of the GlobalVariable with different Profile name are associated.
The output line should show the following items
- name of GlobalVariable
- name of Execution Profile which contains the GV
- initial value of the GV declared in the Profile
These 3 items should be delimited by TAB characters.
Sample code:
// Test Cases/main/1_listing/3_listAllGlobalVariable
List<String> gvipStrList =
CustomKeywords.'com.kazurayam.ks.globalvariable.LookOverExecutionProfilesKeyword.listAllGlobalVariables'()
for (String gvipStr in gvipStrList) {
println gvipStr
}
Output:
2022-05-07 20:20:17.797 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2022-05-07 20:20:17.804 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/main/1_listing/3_listAllGlobalVariableInProfile
2022-05-07 20:20:19.259 INFO k.k.c.m.CustomKeywordDelegatingMetaClass - com.kazurayam.ks.globalvariable.ProfilesHelper.listAllGlobalVariableInProfile is PASSED
AVAR1 test_A 'I\'m from test_A'
AVAR2 test_A 999
AVAR3 test_A [('keyA') : 'valueA', ('keyB') : true]
BVAR1 test_B 'I\'m from test_B'
CATEGORY default 0
CATEGORY main_category0 0
CATEGORY main_category1 1
CATEGORY main_category2 2
CATEGORY main_category3 3
CONFIG default './Include/fixture/Config.xlsx'
DEBUG_MODE default false
EMPTY_VARIABLE test_C ''
ENVIRONMENT default ''
ENVIRONMENT main_envDevelopment 'Development'
ENVIRONMENT main_envProduction 'Production'
ENVIRONMENT main_envStaging 'Staging'
Hostname default 'demoaut.katalon.com'
INCLUDE_SHEETS default []
INCLUDE_SHEETS main_includeSheets_ALL []
INCLUDE_SHEETS main_includeSheets_CompanyA ['CompanyA']
INCLUDE_SHEETS main_includeSheets_CompanyB ['CompanyB']
INCLUDE_SHEETS main_includeSheets_CompanyC ['CompanyC']
INCLUDE_SHEETS main_includeSheets_GroupG ['CompanyL', 'CompanyM', 'CompanyN']
INCLUDE_URLS default []
INCLUDE_URLS main_includeURLs_ALL []
INCLUDE_URLS main_includeURLs_login ['login.html']
INCLUDE_URLS main_includeURLs_top ['top.html']
NULL_VARIABLE test_C null
SAVE_HTML default false
TIMEOUT default 10
URL1 demoDevelopmentEnvironment 'http://demoaut-mimic.kazurayam.com/'
URL1 demoProductionEnvironment 'http://demoaut.katalon.com/'
myList test_C ['I\'m from test_C', 8090]
2022-05-07 20:20:19.388 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/main/1_listing/3_listAllGlobalVariableInProfile
1.4 List GlobalVariables filtered by its name
Problem to solve:
I want my test script to list GlobalVariables filtered by its name with Regular Expression.
Sample code:
// Test Cases/main/1_listing/4_listGlobalVariable
List<String> gvipList = CustomKeywords.'com.kazurayam.ks.globalvariable.LookOverExecutionProfilesKeyword.listGlobalVariables'('ENV.*')
for (String gvip in gvipList) {
println gvip
}
The Regular Expression ENV.\*
matches with a GlobalVariable name which starts with a string “ENV” followed by zero or more any characters.
Output:
2022-05-07 20:53:12.722 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2022-05-07 20:53:12.727 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/main/1_listing/4_listGlobalVariableInProfile
2022-05-07 20:53:13.800 INFO k.k.c.m.CustomKeywordDelegatingMetaClass - com.kazurayam.ks.globalvariable.ProfilesHelper.listGlobalVariableInProfile is PASSED
ENVIRONMENT default ''
ENVIRONMENT main_envDevelopment 'Development'
ENVIRONMENT main_envProduction 'Production'
ENVIRONMENT main_envStaging 'Staging'
2022-05-07 20:53:13.853 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/main/1_listing/4_listGlobalVariableInProfile
1.5 List GlobalVariables filtered by the GV name and the Profile name with Regex
Problem to solve:
I want my test script to list GlobalVariables while filtering by both of the GlobalVariable name and by the Profile name.
Sample code:
// Test Cases/main/1_listing/4_listGlobalVariable
List<String> gvipList = CustomKeywords.'com.kazurayam.ks.globalvariable.LookOverExecutionProfilesKeyword.listGlobalVariablesInProfiles'(
'ENV.*|URL.*', 'd.*')
for (String gvip in gvipList) {
println gvip
}
The listGlobalVariablesInProfiles
method takes 2 arguments. The 1st argument is a regex that matches with the name of GlobalVariable. The 2nd argument is a regex that matches with the name of Profile.
Output:
2022-05-08 21:36:22.747 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2022-05-08 21:36:22.750 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/docs/1_looking-over_Profiles/5_listGlobalVariablesInProfiles
2022-05-08 21:36:23.974 INFO k.k.c.m.CustomKeywordDelegatingMetaClass - com.kazurayam.ks.globalvariable.LookOverExecutionProfilesKeyword.listGlobalVariablesInProfiles is PASSED
ENVIRONMENT default ''
URL1 demoDevelopmentEnvironment 'http://demoaut-mimic.kazurayam.com/'
URL1 demoProductionEnvironment 'http://demoaut.katalon.com/'
2022-05-08 21:36:24.016 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/docs/1_looking-over_Profiles/5_lis