function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Yassine ZouagYassine Zouag 

Test class - how to simulate a radio button selection ?

Hello,

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" /> 
​</apex:selectRadio>
In the test method, how to simulate click on the radio button ?

I tried : 
myVisualForceController.getParameters().put('searchBy','phone');
But it doesn't work.
Any ideas ?
Thanks
bob_buzzardbob_buzzard
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.