system
January 13, 2025, 6:58am
1
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?
system
January 13, 2025, 9:26am
2
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.
system
January 13, 2025, 9:51am
3
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?
system
January 13, 2025, 9:59am
4
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
system
January 13, 2025, 10:12am
5
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
system
January 13, 2025, 10:12am
6
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
system
January 13, 2025, 10:39am
7
Originally posted by rraghvani on January 13, 2025
Using the example shown in stackoverflow, it will be
myInstance.publicMethod1()
And also shown here
system
January 13, 2025, 12:23pm
9
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
system
January 15, 2025, 1:03am
10
Originally posted by mengbinhao on January 14, 2025
This works for me, Thank you ~
system
January 15, 2025, 1:04am
11
Originally posted by mengbinhao on January 14, 2025
This works for me, Thank you ~