c# - Unable to identify WinEdit control in CodedUI test -
i'm trying hand-code simple codedui test in vs 2013. have simple windows forms app 3 textboxes (txta, txtb , txtc) , button (btnadd) on form. on clicking button, app add numbers entered in txta , txtb , show result in txtc below:
var = convert.toint32(txta.text); var b = convert.toint32(txtb.text); txtc.text = (a + b).tostring();
and coded ui test follows :
[testmethod] public void codeduitestmethod1() { applicationundertest app = applicationundertest.launch(@"c:\users\dileep\documents\visual studio 2013\projects\codeduidemo\simplecalculator\bin\debug\simplecalculator.exe"); winedit txta = new winedit(app); winedit txtb = new winedit(app); winedit txtc = new winedit(app); winbutton btnadd = new winbutton(app); txta.searchproperties.add(winedit.propertynames.name, "txta"); txtb.searchproperties.add(winedit.propertynames.name, "txtb"); txtc.searchproperties.add(winedit.propertynames.name, "txtc"); btnadd.searchproperties.add(winbutton.propertynames.name, "btnadd"); txta.text = "50"; txtb.text = "50"; mouse.click(btnadd); var result = txtc.getproperty("text").tostring(); assert.areequal("100", result); }
when run test, launches app, waits while , fails following error :
result message:
test method semiauto.codeduitest1.codeduitestmethod1 threw exception: microsoft.visualstudio.testtools.uitest.extension.uitestcontrolnotfoundexception: playback failed find control given search properties. additional details: technologyname: 'msaa' controltype: 'edit' name: 'txta' ---> system.runtime.interopservices.comexception: error hresult e_fail has been returned call com component. result stacktrace:
@ microsoft.visualstudio.testtools.uitest.playback.engine.iscreenelement.findalldescendants(string bstrqueryid, object& pvarreskeys, int32 creskeys, int32 nmaxdepth) @ microsoft.visualstudio.testtools.uitest.playback.screenelement.findallscreenelement(string queryid, int32 depth, boolean singlequeryid, boolean throwexception, boolean resetskipstep) @ microsoft.visualstudio.testtools.uitest.playback.screenelement.findscreenelement(string queryid, int32 depth, boolean resetskipstep) @ microsoft.visualstudio.testtools.uitesting.uitestcontrol.findfirstdescendant(string queryid, int32 maxdepth, int32& timeleft) --- end of inner exception stack trace --- @ microsoft.visualstudio.testtools.uitesting.playback.mapcontrolnotfoundexception(comexception ex, iplaybackcontext context) @ microsoft.visualstudio.testtools.uitesting.playback.mapandthrowcomexception(comexception innerexception, iplaybackcontext context) @ microsoft.visualstudio.testtools.uitesting.playback.mapandthrowexception(exception exception, iplaybackcontext context) @ microsoft.visualstudio.testtools.uitesting.playback.mapandthrowexception(exception exception, string queryid) @ microsoft.visualstudio.testtools.uitesting.uitestcontrol.findfirstdescendant(string queryid, int32 maxdepth, int32& timeleft) @ microsoft.visualstudio.testtools.uitesting.searchhelper.getelement(boolean usecache, isearchargument searcharg) @ microsoft.visualstudio.testtools.uitesting.searchhelper.search(isearchargument searcharg) @ microsoft.visualstudio.testtools.uitesting.uitestcontrol.findinternal() @ microsoft.visualstudio.testtools.uitesting.uitestcontrol.findcontrolifnecessary() @ microsoft.visualstudio.testtools.uitesting.uitestcontrol.setpropertyprivate(string propertyname, object value) @ microsoft.visualstudio.testtools.uitesting.uitestcontrol.<>c__displayclass3e.b__3d() @ microsoft.visualstudio.testtools.uitesting.codeduitestmethodinvoker.invokemethod[t](func`1 function, uitestcontrol control, boolean fireplaybackerrorevent, boolean logasaction) @ microsoft.visualstudio.testtools.uitesting.uitestcontrol.setproperty(string propertyname, object value) @ microsoft.visualstudio.testtools.uitesting.wincontrols.winedit.set_text(string value) @ semiauto.codeduitest1.codeduitestmethod1() in c:\users\dileep\documents\visual studio 2013\projects\codeduidemo\semiauto\codeduitest1.cs:line 41
i tried using setproperty method doesn't work.
if run recorder , generate code, wraps controls in winwindow control. example, txta textbox control wrapped in uimap class :
public class uitxtawindow : winwindow { public uitxtawindow(uitestcontrol searchlimitcontainer) : base(searchlimitcontainer) { this.searchproperties[winwindow.propertynames.controlname] = "txta"; this.windowtitles.add("form1"); } public winedit uitxtaedit { { if ((this.muitxtaedit == null)) { this.muitxtaedit = new winedit(this); this.muitxtaedit.windowtitles.add("form1"); } return this.muitxtaedit; } } private winedit muitxtaedit; }
i don't understand why done this. can explain this,please ?
thanks dileep krishnan
you need add filter properties of control . me must first use recorder if new , check properties missing have better idea how coded ui search mechanism works .
Comments
Post a Comment