+ Start a Discussion
Yassine ZouagYassine Zouag 

Test class - how to simulate a radio button selection ?


In my VisualForce page, in order to be able to search by name or phone, I used selectRadio tag to only dispaly the name field or the phone field using : "rendered="{!searchBy=='phone'}" for example.
<apex:selectRadio value="{!searchBy}" id="searchBy" onclick="searchByClick();"> 
<apex:selectOption itemValue="name" itemLabel="Search by Name" /> 
<apex:selectOption itemValue="phone" itemLabel="Search by Phone" /> 
In the test method, how to simulate click on the radio button ?

I tried : 
But it doesn't work.
Any ideas ?
You don't simulate the action of the user, instead you prime the controller to reflect those user actions.

So in this case you'd instantiate the controller and then set the 'searchBy' property to 'name' or 'phone', then execute your action method.