How cant I define a param using in different testcase?

Originally posted by mengbinhao on January 12, 2025

Hi there,

I have a TC project which has several testcase (wrote by JaveScript),   I need to init a big Object before my Project, It only should be inited once, I know TC has a Event named OnTestStart executing before each  testcase run, which is not suitable for my case,  Does TC have a Event only trigger once like JUnit "BeforeAll"  annotation?

Originally posted by rraghvani on January 13, 2025

Refer to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static you can create a static class, which will be the first thing that will be called before any test scripts are run.

Originally posted by mengbinhao on January 13, 2025

Could you show me a simple example? After I define a static class, How do I use it?

Run static class first , then other testcase can get real-time value of Object inited by this static class?

Originally posted by rraghvani on January 13, 2025

There’s a number of examples shown here https://stackoverflow.com/questions/1479319/simplest-cleanest-way-to-implement-a-singleton-in-javascript which uses singleton class

Originally posted by mengbinhao on January 13, 2025

I know how to define static class or single design pattern, I just don’t know how to get static class value in TestCompelte

Originally posted by mengbinhao on January 13, 2025

I know how to define static class or single design pattern, I just don’t know how to get static class value in TestCompelte

Originally posted by rraghvani on January 13, 2025

Using the example shown in stackoverflow, it will be

myInstance.publicMethod1()

And also shown here

Originally posted by mengbinhao on January 13, 2025

I’ll try this, Thanks!

Originally posted by rraghvani on January 13, 2025

It’s a bit tricky to explain, since this is specific to JavaScript coding. I suggest you try the example, and within your unit test, the first line should call,

var test = SingletonFactory.getInstance()

The SingletonFactory class can be stored in a different project within the project suite, and you can call this via https://support.smartbear.com/testcomplete/docs/scripting/calling-routines/index.html

Originally posted by mengbinhao on January 14, 2025

This works for me, Thank you ~

Originally posted by mengbinhao on January 14, 2025

This works for me, Thank you ~