Coded UI Tests with Kendo Controls

7 posts, 0 answers
  1. Chelsea
    Chelsea avatar
    34 posts
    Member since:
    Nov 2015

    Posted 11 Dec 2015 Link to this post

    I tried writing Cided UI Tests with Visual Studio 2015 on this webpage: http://demos.telerik.com/aspnetajax/button/examples/radiosandcheckboxes/defaultcs.aspx

    where it is supposed to click the checkbox, but I keep receiving an error as it doesn't recognize the kendo control. How am I able to select it without using the recording options? Here is the error:

    Test Name: CodedUITestMethod1
    Test FullName: CodedUITestProject_test.CodedUITest1.CodedUITestMethod1
    Test Source: C:\Team Projects 2015\Demo\CodedUITestProject_test\CodedUITestProject_test\CodedUITest1.cs : line 28
    Test Outcome: Failed
    Test Duration: 0:01:46.516549
    Result Message: 
    Test method CodedUITestProject_test.CodedUITest1.CodedUITestMethod1 threw exception:
    Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException: The playback failed to find the control with the given search properties. Additional Details:
    TechnologyName:  'Web'
    ControlType:  'CheckBox'
    TagName:  'INPUT'
    Id:  'RadButton6'
     Failed to find any control that matched the value RadButton6 for the search property Id. ---> System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.

     

    Here is my code:

    public void CodedUITestMethod1()
    {
    Playback.PlaybackSettings.SearchInMinimizedWindows = false;

    string Home = "http://demos.telerik.com/aspnet-ajax/button/examples/radiosandcheckboxes/defaultcs.aspx";

    BrowserWindow b = BrowserWindow.Launch(Home);
    Playback.PlaybackSettings.DelayBetweenActions = 100000;
    b.resizedWindow(1920, 1080); //function to make the window full screen
                
    HtmlCheckBox cbBox = new HtmlCheckBox(b);

    //I had used the ID from the Developer Options under F12 initially then changed it to RadButton6 but it doesn't work
    cbBox.SearchProperties.Add(HtmlCheckBox.PropertyNames.Id, "RadButton6");

    Mouse.Click(cbBox);

    }

     

  2. Joana
    Admin
    Joana avatar
    70 posts

    Posted 15 Dec 2015 Link to this post

    Hi Chelsea,

    RadButton is rendered as a span element and it cannot be recognized as HtmlCheckBox. Give a try the following code:

    var radButton = new HtmlSpan(b);
    radButton.SearchProperties.Add(HtmlSpan.PropertyNames.Id, "ctl00_ContentPlaceholder1_RadButton16");
    Mouse.Click(radButton);

    I hope this is what you're looking for.

    Regards,
    Joana
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. Kendo UI is VS 2017 Ready
  4. Chelsea
    Chelsea avatar
    34 posts
    Member since:
    Nov 2015

    Posted 15 Dec 2015 in reply to Joana Link to this post

    Hi Joana,

    What is there is no ID for the element? How would you go about clicking it?

     

  5. Chelsea
    Chelsea avatar
    34 posts
    Member since:
    Nov 2015

    Posted 15 Dec 2015 in reply to Joana Link to this post

    Hi again,

    I have another question regarding a hyperlink. As it is in a Kendo grid, when

    I run the CodedUI test, it fails because the element can't be found:

    var cbBox = new HtmlHyperlink(b);
    cbBox.SearchProperties.Add(HtmlHyperlink.PropertyNames.Id, "btnAdd");
    Mouse.Click(cbBox);

     How do I make the test pass?

     

  6. Joana
    Admin
    Joana avatar
    70 posts

    Posted 16 Dec 2015 Link to this post

    Hello,

    Regarding the first question if there is no ID for the element: you could use any of the the SearchProperties that will match the exact element. You could see more examples here.

    Most likely, it doesn't matter if the hyperlink is placed in grid or not.  You should be able to successfully locate it if the id is correct. Have you inspected it in the Developer Toolbar? If you send me a live url or some example, I would be able to give you more guidelines how to write the test.

    Regards,
    Joana
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  7. Chelsea
    Chelsea avatar
    34 posts
    Member since:
    Nov 2015

    Posted 16 Dec 2015 in reply to Joana Link to this post

    I have attached screenshots of the Dev Toolbar and the webpage itself. It is a hyperlink inside a kendo grid. As you can see, the Id is btnAdd. The error I receive is that the element with that Id is not found so I assumed it was because it is nested in the kendo grid. The code I have been using is:

     

    BrowserWindow b = BrowserWindow.Launch(Home);
    var cbBox = new HtmlHyperlink(b);
    cbBox.SearchProperties.Add(HtmlHyperlink.PropertyNames.Id, "btnAdd");
    Mouse.Click(cbBox);

     

  8. Joana
    Admin
    Joana avatar
    70 posts

    Posted 21 Dec 2015 Link to this post

    Hi Chelsea,

    Locate the parent HTML element of the anchor and search for a child element that has id btnAdd. Try using HtmlCustom instead of HtmlHyperlink. Please note, that getting reference to a HTML elements is not related to the Telerik controls, but general knowledge in writing tests in code.

    Regards,
    Joana
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top
Kendo UI is VS 2017 Ready