This is a migrated thread and some comments may be shown as answers.

Getting items count of a combobox

3 Answers 188 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Anju
Top achievements
Rank 1
Anju asked on 31 Mar 2011, 09:04 PM
Hello Telerik Team,

I am using classic RadControls.  Can you please help me to provide some help on how to get the items count of the items in Radcombox with in the code.

I am trying the following code and getting error:
RadComboBox box = Find.ById<RadComboBox>("cboReqProviderID");

Exception thrown executing coded step: '[New_Test_CodedStep] : My test'.
InnerException:
System.NullReferenceException: Object reference not set to an instance of an object.

Can you please help me with the following:

1) Show in code how to get the items count of Radcombobox
2) Provide me with some documentation on how to debug code in WEBUI test studio QA edition
3) Log.WriteLine doesnot  write anything in the Log file.
Thanks,
Anju

3 Answers, 1 is accepted

Sort by
0
Stoich
Telerik team
answered on 01 Apr 2011, 12:41 PM
Hello Anju,
       1) Show in code how to get the items count of Radcombobox:
Test Studio is intended to save you the trouble of writing code. In this particular case I think you can put the Extraction feature to good use. Check out this article on the feature:
http://blogs.telerik.com/DanielLevy/Posts/10-11-10/q3_2010_-_element_extraction_allows_non-developers_to_work_with_variables.aspx

You can use the this feature to extract the number of (visible) items inside a RadComboBox and then use that value in your test. See screenshot 1. I'm recording against the RadComboBox here:
http://demos.telerik.com/aspnet-ajax/combobox/examples/default/defaultcs.aspx

Quick Tasks also contains Verifications of the number of items in a RadComboBox which you also might want to use.

If your automation task requires that you do this in code, here's an example. This piece of code gets the number of items from one of the CombBoxes in the above-mentioned sample page:
Find.ByExpression<Telerik.WebAii.Controls.Html.RadComboBox>("id=RadComboBoxDealer").Items.Count
As you can see I'm searching by the ID of this particular control.

2) Provide me with some documentation on how to debug code in WEBUI test studio QA edition
Debugging is not really possible in QA edition. Currently only Dev edition (which is basically a Visual Studio plug-in) has that capability. But once again I would like to stress that Test Studio is an immensely powerful even without writing a single line of code. I'm confident that almost all of your Automation tasks can be handled without code.

3) Log.WriteLine doesnot  write anything in the Log file.
I wasn't able to confirm this issue. Could you please recheck this:
Log.WriteLine("--TEST--");
Put this piece of code in a coded step, run the test and check whether it printed to the Log. Let me know if you're still having issues.

Hope to hear from you soon!

Best wishes,
Stoich
the Telerik team
0
Anju
Top achievements
Rank 1
answered on 04 Apr 2011, 05:57 PM
Hello Stoich,

Thanks for your reply. Issue#2 and #3 are clear.

Regarding Issue#1.: I am using classic RadControls for ASP.NET i.e., versions prior to 2008, so I have to write code to get the item count of RadComboBox. I am using the following code, and getting error
Telerik.WebAii.Controls.Html.RadComboBox combo =  Find.ByExpression<Telerik.WebAii.Controls.Html.RadComboBox>("id = cboReqProviderID");
int i = combo.items.Count; -- Error:  Failure Information:
~~~~~~~~~~~~~~~
Exception thrown executing coded step: '[New_Test_CodedStep] : New Coded Step'.
InnerException:
System.NullReferenceException: Object reference not set to an instance of an object.
   at TestProject2.New_Test.New_Test_CodedStep() in c:\Documents and Settings\amundada\My Documents\WebUI Test Studio Projects\TestProject2\New Test.aii.cs:line 93


I also tried using Find.ByExpression<Telerik.WebAii.Controls.Html.RadComboBox>("id = cboReqProviderID_wrapper"); this is also giving the same error on execution.
I tried using the following Find.ById<Telerik.WebAii.Controls.Html.RadComboBox>("CboReqProviderIDWrapperDiv");

Can you please tell me if i am missing on something? or doing something wrong.

Thanks,
Anju
0
Stoich
Telerik team
answered on 07 Apr 2011, 02:53 PM
Hello Anju,
    this error tells me that your find statement can't find the CombBox. Instead of try to write the Find statement yourself, you can add the ComboBox to your project manually and then access it via code. Here's a Jing video demonstrating how to do it:
http://www.screencast.com/users/TelerikTesting/folders/Jing/media/b2b6a423-d72a-403a-94a3-54e817f3ad2d

Let me know how it goes!

Greetings,
Stoich
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Anju
Top achievements
Rank 1
Answers by
Stoich
Telerik team
Anju
Top achievements
Rank 1
Share this question
or