Page 1 of 1

Waiting for t.chain to execute

Posted: Thu May 11, 2017 8:52 pm
by sqatester123
Hello,

Is there a way to wait for a t.chain() to finish before starting execution of another?

Take this code for example.
StartTest(function(t) {
        t.chain(
            {
                action: "type",
                target: "input[name=j_username]",
                text: "<user>"
            },
            {
                action: "type",
                target: "input[name=j_password]",
                text: "<password>"
            },
            {
                action: "click",
                target: "button[type=submit]"
            }
        )
        t.chain(
            {
                action: "click",
                target: "#main-nav-bar button[text=Alarms and Events] => .x-btn-inner-default-toolbar-small"
            }
        )
    }
)
The problem I'm having is that the second one starts before the first can finish so the next button isn't ready by the time the chain times out.

I know that I could combine the chains above, but this is a simplified example.

Re: Waiting for t.chain to execute

Posted: Fri May 12, 2017 9:29 am
by mats
Wrap the two chains in a 't.it(' statement, and they will run in sequence.

Re: Waiting for t.chain to execute

Posted: Fri May 12, 2017 8:12 pm
by sqatester123
I cannot wrap them together unfortunately. The two chains are created in different functions. I need to know that he first one has finished before I can start the second.

Re: Waiting for t.chain to execute

Posted: Sat May 13, 2017 5:37 am
by mats
I meant:
    StartTest(function(t) {
t.it('Do something here...', function(t) {
            t.chain(
                {
                    action: "type",
                    target: "input[name=j_username]",
                    text: "<user>"
                },
                {
                    action: "type",
                    target: "input[name=j_password]",
                    text: "<password>"
                },
                {
                    action: "click",
                    target: "button[type=submit]"
                }
            )
});

t.it('Do something after here...', function(t) {
            t.chain(
                {
                    action: "click",
                    target: "#main-nav-bar button[text=Alarms and Events] => .x-btn-inner-default-toolbar-small"
                }
            )
        }
    )

})

Re: Waiting for t.chain to execute

Posted: Sat May 13, 2017 9:44 am
by nickolay
You can also wrap the 2nd in the callback, and put this callback as the last step of the 1st chain.