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

Newbie question around RadComboBox

4 Answers 98 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Darren
Top achievements
Rank 1
Darren asked on 17 Feb 2012, 06:46 PM
Hi

I am attempting to use the testing framework to write an UI test that is using the RadCombobox, However I am having trouble and looking for pointers in where I am going wrong. This may be the first of many posts ;-)

For this post, I am using this page for testing purposes: http://demos.telerik.com/aspnet-ajax/combobox/examples/populatingwithdata/autocompletesql/defaultcs.aspx

I have test class set up, and what I am attempting to do is search for a company, and then select the company from the list, however, I cannot get the number of items in the combobox after doing the filter.

This is an asp.net combobox, not silverlight. I am using the latest version of nunit, telerik asp.net and testing framework. I have viewed the samples for the test framework, but all the samples that I saw are testing this page: http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/keyboardsupport/defaultcs.aspx and dont appear relevant for what I want to do.

This is the test to indicate by problem: I have excluded setup and teardown for brevity.
[Test]
public void SearchForCompany()
{
    string companyToSearchFor = "H";
    RadComboBox comboBox = browser.Find.ById<RadComboBox>("RadComboBox1");
    comboBox.Click();
    comboBox.Text = companyToSearchFor;
    comboBox.ShowDropDown();
    browser.WaitUntilReady();
    browser.RefreshDomTree();
    var comboboxItems = comboBox.Items;
    Assert.That(comboboxItems.Count, Is.EqualTo(4));
    comboBox.SelectItemByIndex(1);
}


I cannot get past the assert to ensure that 4 items have been returned, as the value returned is always 0.

I know I have missed something simple. Thanks in advance

Darren

4 Answers, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 17 Feb 2012, 09:31 PM
Hello Darren,

Try this approach instead:

RadComboBox comboBox = Find.ByExpression<RadComboBox>("tagname=div", "id=RadComboBox1");
comboBox.SetText("H", 150);
 
System.Threading.Thread.Sleep(2000);
comboBox.Refresh();
 
HtmlDiv d = Find.ById<HtmlDiv>("RadComboBox1_DropDown");
IList<HtmlListItem> list = d.Find.AllByTagName<HtmlListItem>("li");
 
Log.WriteLine(list.Count.ToString());
Assert.IsTrue(list.Count == 4);
comboBox.SelectItemByIndex(3);
System.Threading.Thread.Sleep(2000);

Greetings,

Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Darren
Top achievements
Rank 1
answered on 20 Feb 2012, 12:54 PM
Hi Anthony,

thanks for the reply, but the test is unfortunately still not working for me.

When it gets to the line to determine the number of items, nothing is being returned and assert if failing because the count is zero.

This is all the code that I am using.

Base class that all tests will eventually inherit from

using ArtOfTest.WebAii.Core;
using ArtOfTest.WebAii.TestTemplates;
using NUnit.Core;
using NUnit.Framework;
 
namespace UITests.Helpers
{
    [TestFixture]
    public abstract class RadControlsBaseTest : BaseTest
    {
 
        [SetUp]
        public void TestBaseSetup()
        {
            var settings = GetSettings();
 
            settings.DefaultBrowser = BrowserType.InternetExplorer;
            settings.RecycleBrowser = true;
            settings.BaseUrl = "http://demos.telerik.com/aspnet-ajax";
            settings.ClientReadyTimeout = 60000;
            settings.ExecuteCommandTimeout = 60000;
            settings.AnnotateExecution = true;
            settings.AnnotationMode = AnnotationMode.All;
 
            this.Initialize(settings, TestExecutionContext.CurrentContext.Out.WriteLine);
 
            SetTestMethod(this, TestContext.CurrentContext.Test.Name);
 
        }
 
        [TearDown]
        public void TestBaseTearDown()
        {
            this.CleanUp();
        }
 
        [TestFixtureTearDown]
        public void TestBaseFixtureTearDown()
        {
            ShutDown();
        }
    }
}

and this is the test class that I am using

using System.Collections.Generic;
using ArtOfTest.WebAii.Controls.HtmlControls;
using NUnit.Framework;
using Telerik.WebAii.Controls.Html;
using TrainingAssistSite.UITests.Helpers;
 
namespace UITests
{
    [TestFixture]
    public class RadComboBoxTests : RadControlsBaseTest
    {
        [Test]
        public void SearchForCompany()
        {
            Manager.LaunchNewBrowser();
            ActiveBrowser.NavigateTo("/combobox/examples/populatingwithdata/autocompletesql/defaultcs.aspx");
            string companyToSearchFor = "H";
 
            RadComboBox comboBox = Find.ByExpression<RadComboBox>("tagname=div", "id=RadComboBox1");
            comboBox.SetText("H", 150);
            System.Threading.Thread.Sleep(2000);
            comboBox.Refresh();
 
            HtmlDiv d = Find.ById<HtmlDiv>("RadComboBox1_DropDown");
            IList<HtmlListItem> list = d.Find.AllByTagName<HtmlListItem>("li");
            Assert.IsTrue(list.Count == 4); -- The assert is failing as nothing being populated in the list
            comboBox.SelectItemByIndex(3);
            System.Threading.Thread.Sleep(2000);
 
            HtmlDiv d = Find.ById<HtmlDiv>("RadComboBox1_DropDown");
            IList<HtmlListItem> list = d.Find.AllByTagName<HtmlListItem>("li");
 
            Assert.IsTrue(list.Count == 4);
            comboBox.SelectItemByIndex(3);
            System.Threading.Thread.Sleep(2000);
        }
    }
}

I am at a loss as to why this is not working

Regards

Darren
0
Darren
Top achievements
Rank 1
answered on 20 Feb 2012, 01:09 PM
Also,

I am executing the tests using Resharpers test runner from inside Visual Studio

I am using Resharper 6, and Visual Studio has been started as an administrator
0
Anthony
Telerik team
answered on 20 Feb 2012, 06:23 PM
Hello Darren,

I am sorry but ReSharper is untested and unsupported. Instead we have our own unit test runner as a part of JustCode you can use instead.

I tested your full code using the NUnit test runner and from the Test View within Visual Studio and both worked as expected.

Greetings,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Darren
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Darren
Top achievements
Rank 1
Share this question
or