Get help with testing, discuss unit testing strategies etc.


Post by zombeerose »

I am using the type() method to simulate a user entering text. However, I do not see a way to simulate the user pressing the caps-lock (or shift) key.

My test case is a password field that displays a warning message if it detects that the user is entering text with the caps lock on.

If this is already possible, please let me know. Thank you.

Post by zombeerose »

Another scenario would be simulating the Enter or Tab key, such as when typing into a combo-box that should auto-complete.

Post by mats »

Enter and Tab works, tried it? T.type('ENTER')

Post by nickolay »

We are planning to add native events simulation (using Java applet). It will support pressing any keys (I think). Applet won't work on mobile though..

Post by zombeerose »

@mats
Ok - I finally got the Tab key to work. The problem was because in speed run mode, the combo would not auto-complete before the field was tabbed. When I switched speed run off in the UI, then the test passed. Can speed run be disabled per test? It appears like the Harness.configure option does not take precedence over the UI dropdown menu "Speed run" check item. If I have speedRun:false in the configure object but the UI is true, the tests still run fast. Can you clarify?

I don't see this special syntax (e.g. '[TAB]') mentioned in the docs for t.type. Are the supported keys listed somewhere else?

Here is my code:
StartTest(function(t) {
    t.diag('Combo field');
   
    var store = Ext.create('Ext.data.ArrayStore',{
        fields: ['text'],
        data: [ 
            ['Form'],
            ['Grid'],
            ['Dirty']
        ]
    });
    
    var cmp = Ext.create('Ext.form.field.ComboBox',{
        fieldLabel: 'Combo',
        allowBlank: false,
        displayField: 'text',
        editable: true,
        forceSelection: true,
        queryMode: 'local',
        selectOnFocus: true,
        store: store, 
        typeAhead: true,
        valueField: 'text',
        renderTo: Ext.getBody()
    });
    
    t.pass('Rendered');
    
    var el = cmp.inputEl;
    t.click(el, function(){
        //simulate tab key for auto-complete
        t.type(el, 'Dir[TAB]', function(){ //type partial match
            t.is(cmp.getValue(), 'Dirty', 'Correct value in field');
        });
    });
});
Thanks!

Post by mats »

Speed run should not affect the outcome of a test. Which Siesta version are you running. The currently supported keys can be found in siesta\lib\Siesta\Test\Simulate\KeyCodes.js

Post by zombeerose »

Based on the changelog: 1.0.2 2011-12-06 19:22

I don't see a "KeyCodes" file under the API...only "Keyboard." Is it new?

Post by mats »

It's not part of the API docs actually, I meant the file system. It should be in docs, just isn't yet :)

Post by nickolay »

Updated the docs of `type` method (mentioned the support for some advanced keys) and listed all keys.

Btw, there's no need to manually extract the "inputEl" from field - Siesta can do that for you (for Ext.form.Field). If you will pass Ext.Component it will use its `getEl` method to get the DOM element.

About the `speedRun` issue - indeed, `speedRun` should not affect the outcome of the test. However in this particular case it does, because Ext has the "typeAheadDelay" parameter and the auto-suggestion will appear only after slight delay.

This works for me in speed run:
StartTest(function(t) {
    t.diag('Combo field');
   
    var store = Ext.create('Ext.data.ArrayStore',{
        fields: ['text'],
        data: [
            ['Form'],
            ['Grid'],
            ['Dirty']
        ]
    });
   
    var cmp = Ext.create('Ext.form.field.ComboBox',{
        fieldLabel      : 'Combo',
        allowBlank      : false,
        displayField    : 'text',
        editable        : true,
        forceSelection  : true,
        queryMode       : 'local',
        selectOnFocus   : true,
        store           : store,
        typeAhead       : true,
        valueField      : 'text',
        renderTo        : Ext.getBody()
    });
   
    t.pass('Rendered');
   
    t.click(cmp, function(){
        //Siesta makes a small pause after each action, like "type"
        t.type(cmp, 'Dir', function(){ //type partial match
            
            //simulate tab key for auto-complete
            t.type(cmp, '[TAB]', function(){ //type partial match
                t.is(cmp.getValue(), 'Dirty', 'Correct value in field');
            });
        });
    });
});

Post by nickolay »

zombeerose wrote: Can speed run be disabled per test?
Implemented this in the trunk - you can specify it in the test descriptor now. See the attached trial.
zombeerose wrote: It appears like the Harness.configure option does not take precedence over the UI dropdown menu "Speed run" check item. If I have speedRun:false in the configure object but the UI is true, the tests still run fast. Can you clarify?
Yes, thats intended, the idea is that you can temporarily change various options (like "transparentEx" is very useful for debugging) and keep their values after page refresh, w/o the need to modify the sources.
Attachments
siesta-1.0.3-trial.zip
(3.32 MiB) Downloaded 510 times

Post Reply