Get help with testing, discuss unit testing strategies etc.


Post by chirag »

I m using sencha 4.1.3 & siesta 1.1.2.
.
.
I m having a gridpanel.
I have shown an alert on clicking save button.
.
.
I have used MessageBox like this:
Ext.Msg.show({
			   msg: data,
			   buttons : Ext.MessageBox.OK,
			   icon: Ext.Msg.ERROR
		    });
After click on save button, I want to click the OK button of MessageBox.
Somehow I have achieved that by using the id that is generated in DOM like this:
{
	action : 'click',
	target : 'button[id="button-1005-btnEl"]'
}
id="button-1005-btnEl" But this id is not permanent. It changes everytime I run my testcase.
So i want a solution that is permanent..

Please help me out..
Thanks in advance

Post by mats »

You're right, never rely on autogenerated id's. And try not to use css/DOM properties if possible. You should aim to use component queries, or composite queries.

Try as target:
'messagebox button'
which is a Component Query meaning "a button component inside a component with xtype messagebox'. You can find the xtypes to use in the Sencha docs, and more about components here:

https://docs.sencha.com/ext-js/4-1/#!/gu ... -section-2

Post by chirag »

hey thanks mats..
.
.
I tried as yu said like this:
{
	action : 'click',
	target : 'messagebox button'
}
But unfortunately its not working.. Plz let me know if i am making any mistake??
.
M stuck here..help me out of dis...
Thanks.

Post by mats »

Sorry, my mistake - a ComponentQuery target must begin with '>>'. This works:

StartTest(function(t) {
    
    Ext.Msg.alert('Works?', 'Foo');

    t.chain(
        {
            action      : 'click',
            target      : '>> messagebox button'
        }
    )
});

Post by chirag »

hey thanks mats it works perfectly... :)

Post by chirag »

hey mats I have used MessageBox like dis:
Ext.MessageBox.show({
					msg: 'You are about to delete your record. Are you sure?',
					icon: Ext.Msg.WARNING,
					buttons: Ext.MessageBox.YESNO
				});
In this case it has 2 buttons (Yes/No)..Now if I use componentquery like dis:
{
	action : 'click',
	target : '>> messagebox button'
}
It will reference which button?? I have tried giving buttonText button it doesn't work..
.
.
How will I click Yes button in Msgbox..
Please help me..

Thanks

Post by mats »


Ext.MessageBox.show({
               msg: 'You are about to delete your record. Are you sure?',
               icon: Ext.Msg.WARNING,
               buttons: Ext.MessageBox.YESNO
            });

Ext.ComponentQuery.query('messagebox button[text=Yes]')
Here's a simple example, use the full power of Component Query.

https://docs.sencha.com/ext-js/4-1/#!/ap ... onentQuery

Post Reply