Forum Discussion
function CheckPropertyExists(ObjPropNameArray:OleVariant,ObjPropValuesArray:OleVariant,DispMsg:OleVariant=nil,Parent:OleVariant=nil,WaitTime:OleVariant=nil,IsLogError:boolean=true):boolean; var objToChk : OleVariant; i:integer; warningTxt,propName,propVal:string; begin try try if IsNullNil(DispMsg) then DispMsg := 'Waiting for the object to appear on the screen'; Indicator.Show; Indicator.PushText(TidyString(DispMsg)); objToChk := Utils.CreateStubObject; if IsNullNil(Parent) then begin Parent := LOTS_Main_GetLotsParentObj; if not Parent.exists then exit; end; if IsNullNil(WaitTime) then begin WaitTime := Project.Variables.WaitTime; end else WaitTime := VarToInt(WaitTime); for i : = 0 to WaitTime/1000 do begin if not Parent.exists then break; objToChk := Parent.FindChild(ObjPropNameArray,ObjPropValuesArray,1000,false); Parent.Refresh; if ((objToChk.Exists) and (objToChk.Visible)) then break; aqUtils.Delay(2000,Indicator.Text); end; //check to see if the property is visivle on screen {if objToChk.Exists then begin if not objToChk.VisibleOnScreen then Log.Warning('The object exists but is not visible on screen'); end;} for i := VarArrayHighBound(ObjPropNameArray, 1) downto 0 do begin propName := #13#10+propName+' Property Name ' + TidyString(i+1) +': '+ TidyString(ObjPropNameArray[i])+' '+#13#10; propVal := #13#10+propVal+' Property Value ' + TidyString(i+1) + ': ' +TidyString(ObjPropValuesArray[i])+' '+#13#10; end; warningTxt := 'Unable to find the propety with Property Details' + #13#10 + 'Object Property Names : ' + #13#10 + propName + #13#10 + + 'Object Property Values : ' + #13#10 +propVal + #13#10 +' Total Delay Used : ' + TidyString(WaitTime); except Log.Error('Exception in CheckPropertyExists routiene,click on addtional Information tab for details... ',exceptionmessage); end; finally if not objToChk.Exists then begin if IsLogError then begin Log.Error('Failed to find the Property,click on addtional Information tab for details... ' ,warningTxt,300,nil,Sys.Desktop.Picture()); end; result := false; end else begin result := true; end; Indicator.PopText(); end; end;
- marinb9 years agoContributor
Kinda using something like this in many of my scripts (jscript), which works like a charm and you're able to give a maximum waiting time.
function WaitForObject(Object, MaxWait) { for (var i=0;i<MaxWait;i++) { if (Object.Exists) { if (Object.VisibleOnScreen && Object.Enabled) { Log.Message("Object found & enabled on screen!");
return Object; } } }
Log.Error("Object not found in max number of iterations!"); return false; }- Kate8 years agoContributor
How do you guys handle errors that go to the Log?
I would love to see my test green, but with checking while an element is visible or not visible I am getting this red error signs there, while overall test passes.
- marinb8 years agoContributor
Never try to execute actions on objects that may not exist yet.
so no
x = <function/command to find the object>
x.click
but
x = <function/command to find the object>
if (<check if x exists returns true>)
{ x.click }
else
{ Log.Error("Couldnt click x because the object was not found") }
Could be that the various TestComplete built-in checks like CheckProperty returns errors when they fail, but I try to refrain from using them unless they don't fill my log with green checks or red errors.
Related Content
- 2 years ago
- 6 months ago
Recent Discussions
- 4 days ago
- 4 days ago
- 7 days ago