0

katalon tool

My setup is as following: A global variable defined as "name" with type string. Initial value is '' (empty) Testcase Registration, where name will be assigned a random value. Testcase Login, where the loginname is the global variable name. A test suite collection with these test cases and a few others What Im trying to achieve is to create a new test account every time the test suite collection runs.

The problem is when I run the test suite collection, the Login testcase will fail, because the global variable name that is used for the login is empty. But in the test case Registration, name is a random value.

I assumed that it would be possible to assign a new value to a global variable, when a test case would run. Is this assumption wrong and if so, what would be the best way of creating a new value for a global variable?

Or is the problem somewhere else?

fanlishen
  • 1
  • 1
  • 1
  • Welcome to [so]. Please review the [ask] section and provide a [mcve]. Moreover, please [edit] your question to conform with [formatting guidelines](https://stackoverflow.com/editing-help). – compor Sep 05 '18 at 09:03
  • Ugh, forgive this necro-posting, but.... ...why use and manipulate at runtime, global variables? Wouldn't using a [Test case variable](https://docs.katalon.com/docs/katalon-studio-enterprise/test-execution/data-driven-testing/test-case-variables) work better? – Mike Warren Jul 13 '22 at 05:13

4 Answers4

2

It is weird but you have to add Thread.sleep(5000) in your code. Somehow it takes time to get global variable which is set in another test case.

0

You can assign a non-empty value to GlobalVariable.name before running the test suite.

Then, when you run the test case, put:

GlobalVariable.name = 'newValue'

as the first line of the test script.

Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
0

Ugh, forgive this necro-posting, but....

...why use and manipulate at runtime, global variables?

What are you hoping to accomplish by tightly-coupling name (data) concerns to two completely different test cases (and use cases)?

Wouldn't using a Test case variable work better?

Namely something like:

Keyword com.yourProject.models.UserModel

import com.github.javafaker.Faker

public class UserModel {
    private final String username;
    // etc...

    public UserModel() { }

    public UserModel(String username) { 
        this.username = username;
    }

    public String getUsername() { 
        return this.username;
    }

    //...etc...

    public static UserModel GenerateRandom() {
        Faker faker = new Faker();

        return new UserModel(faker.name().username());
    }
}

in your profile:

  • click "Add" in Manual view
  • name this new variable userModel
  • go over to Script view and edit that new variable to have value new com.yourProject.models.UserModel("main_user")

and in the Variables (Script mode) section of your login test case, be like:

  • click "Add" on the Variables screen
  • name the test case variable model
  • set the variable type to "Global Variable"
  • in Default value column, select userModel

and in the registration test case, just hit UserModel.GenerateRandom(), and maybe write a handler for this, that will, whenever an already-existing user is entered for registration, log that user to spreadsheet and retry with random UserModel until we get a unique one. I have utils like that in my codebase. lmk if you want them. :)

Mike Warren
  • 3,796
  • 5
  • 47
  • 99
-2

Better and more logical place to put them is in the profiles tab. Clearly then, you can see all your variables in the one bucket, not hidden around a multitude of test cases.

double-beep
  • 5,031
  • 17
  • 33
  • 41
  • 1
    It is better to add example to your answer , welcome to SO! your answer should be comment, i know you dont have enough reputation, keep patience. – Dev Jul 13 '19 at 20:43