c# - Coded UI Control.Exists. System.NullReferenceException -
i want check window exists after actions. try:
protected override boolean ispresent() { if (_mainwindow == null) { _mainwindow = new winwindow(); _mainwindow.searchproperties[winwindow.propertynames.controlname] = "mainwindow"; } return _mainwindow.exists; }
but if control not exist mainwindow.exists
throws system.nullreferenceexception. can't understand why happens because mainwindow reference in code can't null. how can verify _mainwindow founded or not?
i've did wait window loading timeout. i've tried use mainwindow.findmainwindow().waitforcontrolexist(100000)
doesn’t wait needed timeout. code not set needed timout:
playback.playbacksettings.searchtimeout = 100000; playback.playbacksettings.waitforreadytimeout = 100000;
i use vs2013.
upd:
this code nre check:
protected override boolean ispresent() { if (_mainwindow == null) { _mainwindow = new winwindow(); _mainwindow.searchproperties[winwindow.propertynames.controlname] = "mainwindow"; } try { return _mainwindow.tryfind(); //todo wtf? } catch (nullreferenceexception e) { console.writeline("we've got nullreferenceexception"); console.writeline("_mainwindow reference " + ((_mainwindow == null) ? "null" : "not null")); throw e; //line 41 } }
and result:
we've got nullreferenceexception _mainwindow reference not null attachments: file:///project/testresults/user_win-fp7fmm7pub1%202017-04-09%2015_57_34/in/4acd6ac8-92ce-4746-8787-3aecfd63bdd8/win-fp7fmm7pub1/successlogintest.png test method uitest.autotests.logintests.successlogintest threw exception: system.nullreferenceexception: object reference not set instance of object. in uitest.locators.mainwindow.ispresent() in mainwindow.cs: line 41 in uitest.locators.basewindow.wait() in basewindow.cs: line 34 in uitest.locators.mainwindow..ctor() in mainwindow.cs: line 18 in uitest.locators.loginwindow.clickenterbutton() in loginwindow.cs: line 57 in uitest.autotests.logintests.successlogintest() in logintests.cs: line 32
exists not want use. can use tryfind() instead.
protected override boolean ispresent() { if (_mainwindow == null) { _mainwindow = new winwindow(); _mainwindow.searchproperties[winwindow.propertynames.controlname] = "mainwindow"; } return _mainwindow.tryfind(); }
for more examples of how use coded ui various tasks, see website codeduiexamples.com
Comments
Post a Comment