Get help with testing, discuss unit testing strategies etc.


Post by claudia_ »

Inside my test suite I have some setup code which should execute prior to any beforeEach call.

The point is this global setup code contains some asynchronous code and I have managed to do this by using beginAsync(...) and endAsync(...) as well.

However when I execute my tests the beforeEach(..) is executed before the end of my initial setup code and it seems to ignore the async declaration.

I've already seen there is another method, setupEarlier() but this cannot fit in my project since I need to execute some code located within my application and setupEarlier seems to execute before the application is loaded.

I've also tried to use generic setup() method and also overrides for isReady() and start() methods but both do not have the application loaded when they execute.

I've attached a ZIP showing the context of this.

Let me know if you need more details.
Claudia
Attachments
BeforeEach.zip
(2.22 KiB) Downloaded 231 times
Last edited by claudia_ on Fri May 18, 2018 11:46 am, edited 1 time in total.

Post by nickolay »

Hi,

The "setup" method will have preloads already loaded (inlcuding loading app page), but the test itself not started yet, so it definitely should work. Make sure you call the "setup" callback in right moment, after your initilization has complete.

Also make sure you've checked this guide: https://www.bryntum.com/docs/siesta/#!/ ... test_class, which describes how to access the test page scope from the test method (test code is running in different iframe, but it has access to test page via "t.global", which inside the test method becomes "this.global". Most notable thing is that you need to alias globals from the test page to operate with them, like Data, Object, etc.

Post by claudia_ »

Thanks for the information.
However I've already implemented two solutions which both seem to not solve my requirements.

1. About putting my global setup code into an external file (as seen into the attachment above) and then calling inside the "startTest" but prior to the "beforeEach" method I get that even I specify the "beginAsync/endAsync" commands in the end the "beforeEach" starts before the end of my global setup code execution.
Is it possibile in this scenario to wait until my setup code has completed its execution before starting with "beforeEach" ?

2. When I use the "setup" method as an overriden method inside a custom TestClass (I've already followed the guide https://www.bryntum.com/docs/siesta/#!/ ... test_class) then inside the "setup" method execution our application libraries are not yet loaded and so I cannot put my setup code here.

Post by nickolay »

our application libraries are not yet loaded
Are these libraries listed in `preload` config or loaded dynamically? Can you just wait until they will be loaded and then do the setup?

Post by claudia_ »

My libraries are loaded in the "preload" config (harness file index.js).
But it's not clear how to wait (and exactly where in the code) for these to be loaded and then call the"setup" method.
Can you provide a simple example ?

Post by nickolay »

By the time `setup` method is executed, the preloads are already loaded, thats for sure. But anyway, you can wait for any condition _inside_ the setup method. See an example here: https://www.bryntum.com/docs/siesta/#!/ ... thod-setup
where `setup` method waits until the ajax request completes. Another example:
Class('My.Test.Class', {

    isa         : Siesta.Test.Browser,

    override : {

        setup : function (callback, errback) {
            var counter = 0

            // NEED TO USE `this.global.Ext` to access test page
        
            var interval = setInterval(function () {
                if (some_condition) {
                    clearInterval(interval)
                
                    doSomething()

                    callback()
                }

                if (counter++ > 100) {
                    //timeout
                    errback()
                }
            }, 100)
        
        }
    },

    ....
})

Post by claudia_ »

When using the overriden testClass and after adding your suggested code about wait (eg. for any condition) inside the setup method,
my external libraries are still not available.

Is it possible that my libraries, which are not Ext classes,
are not available since they are located in a different context which is not reachable from the setup method ?

Also, I've tried moving the code for the execution of my libraries inside the 'beforeEach' of the test suite
but it seems that in this context (e.g inside the 'beforeEach') the asynchronous execution is not managed thus my asynchronous functions do execute but without waiting and getting the necessary response from the server.

I've even tried to use the beginAsyn/endAsync inside the beforeEach in order to control the asynchronous flow but then the execution order doesn't wait for the asynchronous callbacks.

Do you still suggest to use the setup override method (and if yes, how to get access to my external functions) or some other solution should be done ?

thanks in advance for any hint.

Post by nickolay »

The docs for "beforeEach" contains description how to make "beforeEach" function asynchronous: https://www.bryntum.com/docs/siesta/#!/ ... beforeEach

If you can post a whole zip file with your setup with the description what exactly does not work, I can take a look. Otherwise its hard to tell what's wrong. The "setup" method does have access to the test page, at the time it is executed, preloads are loaded. If your preloads do not create global variables though - those won't be visible.

Post Reply