Reply To: How to test whether multiple elements were selected?

PennController for IBEX Forums Support How to test whether multiple elements were selected? Reply To: How to test whether multiple elements were selected?

#7463
Jeremy
Keymaster

Hello Ana-Maria,

Your reasoning is on the right track, but things work slightly differently: tests embedded in a success command won’t count as conjoined to the main test. For that, you have the and command. You can do this:

newTrial(
    newScale("comprehensibility_prac1", 8).print(),
    newScale("comprehensibility_prac2", 8).print(),
    newScale("comprehensibility_prac3", 8).print()
    ,
    newButton("validation", "Confirm")
        .center()
        .print()
        .wait( 
            getScale("comprehensibility_prac3" ).test.selected()
            .and( getScale("comprehensibility_prac2").test.selected() )
            .and( getScale("comprehensibility_prac1").test.selected() )
            .failure(
                newText("timedout","<b>Please use all the scales!</b>")
                    .css("font-size", "19px")
                    .css("font-family","times-new")
                    .color("red")
                    .center()
                    .print()     
            )
        )
)

Note that the error message will appear whenever any scale is unselected

If you want scale-specific messages, you could conjoin all three tests to a main test, so you can apply test-specific failures:

newTrial(
    newScale("comprehensibility_prac1", 8).print(),
    newScale("comprehensibility_prac2", 8).print(),
    newScale("comprehensibility_prac3", 8).print()
    ,
    defaultText
        .css("font-size", "19px")
        .css("font-family","times-new")
        .color("red")
        .center()
    ,
    newButton("validation", "Confirm")
        .center()
        .print()
        .wait( 
            newVar("dummy", 1).test.is(1)
                .and( getScale("comprehensibility_prac3" ).test.selected().failure( 
                    newText("timedout3","<b>Please use scale 3!</b>").print()
                ) )
                .and( getScale("comprehensibility_prac2" ).test.selected().failure( 
                    newText("timedout2","<b>Please use scale 2!</b>").print()
                ) )
                .and( getScale("comprehensibility_prac1" ).test.selected().failure( 
                    newText("timedout1","<b>Please use scale 1!</b>").print()
                ) )
        )
)

Jeremy