Page 1 of 1

how to periodically refresh browser and test for existence?

Posted: Fri Oct 09, 2015 6:00 pm
by amccollough
My use case: I am testing the execution of a SharePoint workflow which may take up to 10 minutes to complete. When this workflow completes, a refresh of the page will add an object which I have defined in my repository, and can then test for the object's existence.

The challenge I face is, I need to do what amounts to a "Do...Until" loop, where Ranorex will periodically refresh the page with an F5, once each minute would be fine, and test for the repository item to exist or not. If the object is not found after 10 minutes, fail the test.

How can I accomplish this?

Re: how to periodically refresh browser and test for existence?

Posted: Mon Oct 12, 2015 3:51 pm
by Support Team
Hello amccollough,

I would suggest implementing a User Code Action, which checks periodically if the object exists.

Please take a look at the sample method below.
Depending on your specific use case you probably have to modify the source code.

Prerequisites for the implementation below are two repository items:
1) The DOM-element, which contains the Sharepoint application
2) The Object, which needs to be checked

Code: Select all

public void CheckIfObjectExists()
{
        	bool objectExists = false;
        	
           //Try to reload and search for the element ten times
        	for ( int i = 0; i<=10 && objectExists == false; i++)
        	{        		
        		//Reload the current web page
        		repo.Sharepoint.Self.ExecuteScript("location.reload(true);");
        		
        		//Check whether the object exists
        		objectExists = repo.Sharepoint.ObjectInfo.Exists(3000);
        		
        		if ( objectExists == true )
        		{
        			//Objects exist, no more iterations needed
        			Report.Success("Object exists.");
        		}
        		else
        		{
        			//Object does not exist, wait for one minute and continue search
        			Report.Info("Object does not exist. Wait and reload page.");
        			Delay.Seconds(60);
        		}
        	}
        	
        	if ( objectExists == false )
        	{
        		Report.Failure("Object does not exist");
        	}
        	 
}
Please let me know if you need further assistance.

Regards,
Johannes

Re: how to periodically refresh browser and test for existence?

Posted: Thu Oct 15, 2015 5:12 pm
by amccollough
I do need help with this. You say I need two repository items, but exactly how do I pass those into the user code? I tried playing with the Args, and see from other online examples I can use Adapter or RepoItemInfo, but which?

Re: how to periodically refresh browser and test for existence?

Posted: Fri Oct 16, 2015 3:04 pm
by Support Team
Hello amccollough,

In the sample above the repository items are accessed directly from the repository, which is available as the 'repo'-object within recording modules.

Code: Select all

repo.Sharepoint
repo.Sharepoint.Object
repository.png
More information about using the repository within user code can be found in the user guide.

As you mentioned, another way would be to add parameters to the user code actions.
Please use the type 'Adapter' for the DOM-element and 'RepoItemInfo' for the corresponding object.
user_code_method_with_parameters.png
In this case you have to cast the DOM-element in order you can run the ExecuteScript()-method.

If you pass the items as arguments you have to adjust the code sample.
In this case, please use

Code: Select all

domElement.As<WebDocument>().ExecuteScript("location.reload(true);");
instead of

Code: Select all

repo.Sharepoint.Self.ExecuteScript("location.reload(true);");
and

Code: Select all

objectExists = testObject.Exists(3000);
instead of

Code: Select all

objectExists = repo.Sharepoint.ObjectInfo.Exists(3000);
Please let me know if you need more information.

Regards,
Johannes