Wednesday, 15 April 2015

c# - How can Viewbox/Canvas/Path elements be retrieved for Coded UI testing? -



c# - How can Viewbox/Canvas/Path elements be retrieved for Coded UI testing? -

when performing coded ui tests on wpf application, wpf button need can found in next way:

wpfbutton button = new wpfbutton(mainwindow); button.searchproperties[wpfbutton.propertynames.automationid] = "btn"; button.windowtitles.add("mainwindow");

after initialization can perform checks , validations.

the problems begin when i'm trying check state of viewbox element, contains canvas, which, in turn, contains path. no 1 of these elements has analog type microsoft.visualstudio.testtools.uitesting.wpfcontrols namespace. after short investigation i've found out these types don't have oncreateautomationpeer method overridden.

so, convenient way retrieve canvas or viewbox, or path ui testing?

maybe, i've missed compatible type microsoft.visualstudio.testtools.uitesting.wpfcontrols namespace or, maybe, should derive custom type (for example, canvas) , override oncreateautomationpeer method in it, , create automation peer derivedcanvas class? i'm newcomer coded ui testing, if sec solution solves problem, how can implemented?

i've found answer. appears simple. first, new automatisablecanvas class should derived canvas:

public class automatisablecanvas : canvas { protected override automationpeer oncreateautomationpeer() { homecoming new canvasautomationpeer(this); } }

second, new canvasautomationpeer class should derived frameworkelementautomationpeer:

class canvasautomationpeer : frameworkelementautomationpeer { public canvasautomationpeer(canvas owner) : base(owner) { } protected override automationcontroltype getautomationcontroltypecore() { homecoming automationcontroltype.custom; } }

and automatisablecanvas command can found follows:

wpfcustom canvas = new wpfcustom(mainwindow); canvas.searchproperties[wpfcustom.propertynames.automationid] = "an automationid you've specified automatisablecanvas instance"; canvas.windowtitles.add("mainwindow");

c# wpf ui-automation coded-ui-tests

No comments:

Post a Comment