kazurayam / VisualTestingInKatalonStudio

This is a Katalon Studio project which performs 2 ways of screenshot-comparison testing for WebUI in full automation. Twins mode compares 2 host names at a time. Chronos mode compares the current view of a AUT to the previous one. You can make your own Katalon Studio project capable of the same screenshot-comparison. approach. Instruction provided.
https://forum.katalon.com/t/visual-testing-in-katalon-studio/13361
GNU General Public License v3.0
22 stars 3 forks source link

GlobalVariablesPersistence class passes the values of GlobalVariables set by preceding Test Suites #19

Open kazurayam opened 4 years ago

kazurayam commented 4 years ago

In the ver 1.19.5 com.kazurayam.visualtesting.VisualTestingListenerImpl class has such code fragment:

    void beforeTestSuite(TestSuiteContext testSuiteContext) {
        // read TestSuiteId and ExecutionProfile of the last executed test suite
        // from GlobalVariables.json file
        if (Files.exists(GLOBAL_VARIABLES_JSON)) {
            List<String> names = [MGV.LAST_EXECUTED_TESTSUITE_ID.getName(), MGV.LAST_APPLIED_EXECUTION_PROFILE.getName()]
            Reader reader = new InputStreamReader(new FileInputStream(GLOBAL_VARIABLES_JSON.toFile()), "utf-8")
            Map<String, Object> gvs = GlobalVariableHelpers.read(names, reader)
            for (String name in gvs.keySet()) {
                GlobalVariableHelpers.ensureGlobalVariable(name, gvs.get(name))
                WebUI.comment("GlobalVariable.${name} has value \"${gvs.get(name)}\" loaded from ${GLOBAL_VARIABLES_JSON}")
            }
        } else {
            WebUI.comment("${GLOBAL_VARIABLE_JSON} file is not found")
        }
void afterTestSuite(TestSuiteContext testSuiteContext) {

// write the id of Test Suite which was last executed into a GlobalVariable, and write it into json file.
        // write the Execution Profile name as well.
        // It is necessary to pass the info via file to the next TestSuite run.
        // Because a GlobalVariable is TestSuite-scoped; it is not automatically passed across TestSuite boundaries.
        def lastExecutedTestsuiteId     = this.getRelativeTestSuiteId(testSuiteContext)
        def lastAppliedExecutionProfile = RunConfiguration.getExecutionProfile()
        GVH.ensureGlobalVariable(ManagedGlobalVariable.LAST_EXECUTED_TESTSUITE_ID, lastExecutedTestsuiteId)
        GVH.ensureGlobalVariable(ManagedGlobalVariable.LAST_APPLIED_EXECUTION_PROFILE, lastAppliedExecutionProfile)
        WebUI.comment("GlobalVariable.${ManagedGlobalVariable.LAST_EXECUTED_TESTSUITE_ID} is set to ${lastExecutedTestsuiteId}")
        WebUI.comment("GlobalVariable.${ManagedGlobalVariable.LAST_APPLIED_EXECUTION_PROFILE} is set to ${lastAppliedExecutionProfile}")

        //
        Files.createDirectories(GLOBAL_VARIABLES_JSON.getParent())
        List<String> names = [MGV.LAST_EXECUTED_TESTSUITE_ID.getName(), MGV.LAST_APPLIED_EXECUTION_PROFILE.getName()]
        Writer writer = new OutputStreamWriter(new FileOutputStream(GLOBAL_VARIABLES_JSON.toFile()), "utf-8")
        GVH.write(names, writer)

These codes are very important. But difficult to explain to others. Too messy for others to understand.

I should make a new class com.kazurayam.visualtesting.GlobalVariablesPersistence. I should move these code into the GlobalVariablesPersistence class. I should write unit-tests for the new class. And I should write clear description about the class; what it is designed for.

kazurayam commented 4 years ago

https://forum.katalon.com/t/what-is-the-scope-of-globalvariables/42378 raises an interesting question.

A Test Suite Collection has 2 mode of execution:

  1. Sequential
  2. Parallel

If a Test Suite Collection executes child Test Suites in Parallel mode, how the GlobalVarialbes are persisted by each indivisual Test suites? Does the GlobalVariables collide each other?