locked
BrowserWindow and AJAX RRS feed

  • Question

  • Hi, 

    I have a simple asp.net AJAX enabled site which has 2 combo boxes. 

    When i change value in the first combo box the values in the second one change. 

    Now i want to write a coded UI test to ensure that the data being populated in the second combobox is correct and is related to the value selected in the first one. 

     

    But when i try to set the value in the first combo box and try to get the values in the second i am unable to get anything at all. 

    Is there a way to make this work. I am very new to this framework so i am sure that i am missing somethign really simple. 

    My code looks like the following 

     

    <pre lang="x-c#">var browserWindow = BrowserWindow.Launch();
          
          browserWindow.NavigateToUrl(new Uri("weburl"));
    
    
          // Get All the car Makes
          var carMakeCombo = new HtmlComboBox(browserWindow);
    
          carMakeCombo.SearchProperties[HtmlControl.PropertyNames.Id] = "ddlVehicleMake";
    
    
          var carMakes = (from HtmlListItem item in carMakeCombo.Items
                  select item.DisplayText
                  into carMakeName where !"Select Vehicle".Equals(carMakeName) select new CarMake {Name = carMakeName,}).ToList();
    
          int i = 1;
    
          // Get All the car Models for the car Makes
          foreach(var carMake in carMakes)
          {
            carMakeCombo.SelectedItem = carMake.Name;
    
            browserWindow.WaitForControlReady();
            
            var carModelCombo = new HtmlComboBox(browserWindow);
    
            carModelCombo.SearchProperties[HtmlControl.PropertyNames.Id] = "ddlModel";
    
            
    
            foreach (HtmlListItem carModel in carModelCombo.Items)
            {
              // I never get any related values in the test. When i do these steps manually it works
              var carModelName = carModel.DisplayText;
              if (!"Select Model".Equals(carModelName))
              {
                carMake.Models.Add(new CarModel { Name = carModelName, });
              }
            }
          }
    
        }
    

     

    Tuesday, May 31, 2011 12:55 PM

Answers

  • 1st question with Ajax stuff is does your

        carMakeCombo.SelectedItem = carMake.Name;

    actually cause the item on the page to update. For me with dynamic pages I'm 50:50 on this working and have an alternate method to actually click the HtmlComboBox and then find(), ensureclickable() and click the HtmlListItem too.

     

    2: try to fall a Find() on the 2nd dropdown before attempting to access it, I've run into needing to do that on occasion.

     

    3: Is using your BrowserWindow.WaitForControlReady() working? Try to find a HtmlDocument object with the browser window as the parent and wait for that (and use it as the parent for the objects on the page)

     

    4: If you're not sure that you're getting the object you can try to DrawHighlight() it or use .CaptureImage().Save("c:/temp.jpg") and save an image of the object

    Tuesday, May 31, 2011 5:34 PM

All replies

  • 1st question with Ajax stuff is does your

        carMakeCombo.SelectedItem = carMake.Name;

    actually cause the item on the page to update. For me with dynamic pages I'm 50:50 on this working and have an alternate method to actually click the HtmlComboBox and then find(), ensureclickable() and click the HtmlListItem too.

     

    2: try to fall a Find() on the 2nd dropdown before attempting to access it, I've run into needing to do that on occasion.

     

    3: Is using your BrowserWindow.WaitForControlReady() working? Try to find a HtmlDocument object with the browser window as the parent and wait for that (and use it as the parent for the objects on the page)

     

    4: If you're not sure that you're getting the object you can try to DrawHighlight() it or use .CaptureImage().Save("c:/temp.jpg") and save an image of the object

    Tuesday, May 31, 2011 5:34 PM
  • Hi Mathew, 

     

    Thanks for your answer. I will try this tonight and update this forum by tomorrow...

     

    ~Abhishek

    Wednesday, June 1, 2011 12:51 PM