Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 84751

Looping and deleting folders in Kendo Treeview in automatic tests

$
0
0

hello again Cody,

sorry for bothering you again after all this time, up until now I still haven't managed to make this automation work, I am probably making some stupid mistake...

here you will find the code I am using, it's basically your own code with just the inclusion of the right element from my DOM instead of Pages.something.something (explored through the Test Studio tool and inserted in my Element repository):

 

#endregion
 
// Add your test methods here...
 
[CodedStep(@"definisce treeview e nodi")]
publicvoid_10_Cancellazione_ambiente_di_test_CodedStep()
{
    // A Kendo TreeView is an HTML ul element
    KendoTreeView treeView = Pages.CBoxEsploraCloud.TreeviewUnorderedList;
      
    // Taverse every item under the root node
    HtmlUnorderedList ul = treeView.BaseElement.As<HtmlUnorderedList>();
    foreach(HtmlListItem item inul.Items)
    {
        TraverseTreeNode(item.BaseElement.As<KendoTreeNode>());
    }
     
}  
 
/// <summary>
/// Delete the passed in node after traversing all subnodes, deleting them along the way,
/// contained under this node
/// </summary>
/// <param name="treeView">The node to be traversed then deleted</param>
privatevoidTraverseTreeNode(KendoTreeNode treeView)
{
    // Define the find expression used to locate the name of a node
    HtmlFindExpression nodeNameFindExpression = newHtmlFindExpression("tagname=span", "class=^k-in");
    // Locate the name of this node
    HtmlSpan nameSpan = treeView.Find.ByExpression<HtmlSpan>(nodeNameFindExpression);
 
    Log.WriteLine("Starting TraverseTreeNode for node: "+ nameSpan.InnerText);
    HtmlUnorderedList ul = treeView.Find.ByTagIndex<HtmlUnorderedList>("ul", 0);
    // traverse through all subnodes contained underneath this node
    foreach(HtmlListItem item inul.Items)
    {
        // Locate the name of the subnode
        HtmlSpan innerNameSpan = item.Find.ByExpression<HtmlSpan>(nodeNameFindExpression);
 
        // If this node is expandable, then expand it
        KendoTreeNode node = item.BaseElement.As<KendoTreeNode>();
        if(item.BaseElement.ContainsAttribute("aria-expanded"))
        {
            if(!node.Expanded)
            {
                node.Expand();
            }
        TraverseTreeNode(node);
        }
        else
        {
            //We found a leaf (non-expandable node). Delete it.
            DeleteNode(innerNameSpan, node, "leaf");
        }
    }
    // Finally delete the node we just finished traversing
    DeleteNode(nameSpan, treeView, "folder");
}
 
/// <summary>
/// Common function to delete a node
/// </summary>
/// <param name="nameSpan"></param>
/// <param name="node"></param>
/// <param name="nodeType"></param>
privatevoidDeleteNode(HtmlSpan nameSpan, KendoTreeNode node, stringnodeType)
{
    Log.WriteLine("Deleting a "+ nodeType + ": "+ nameSpan.InnerText);
    HtmlSpan deleteIcon = node.Find.ByExpression<HtmlSpan>("id=^delete-folder");
    deleteIcon.Click();
}

as I try to save the test, no errors are shown, as soon as I try to run it, the log tells me the program failed to compile at the very start, when we define the KendoTreeView variable (I set the line to bold, up here). The error log says (translated from my italian interface):

"[PATH_OF_MY_TEST_CASE/NAME_OF_TEST_CASE]: Line 53: (CS0266) Impossible to convert in an implicit way the type 'ArtOfTest.WebAii.Controls.HtmlControls.HtmlControl' in 'Telerik.TestingFramework.Controls.KendoUI.KendoTreeView'. It is present an explicit conversion. Probable missing cast."

It's as if it said to me: "this element is the wrong one, this one is not a HTML unordered list and you are treating it as such without a proper cast", but the tools to explore the DOM made me save that tag.

Any ideas?

again, thank you very much for all the trouble and for your support.


Viewing all articles
Browse latest Browse all 84751

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>