Generic Method for Checking Repository items

Ask general questions here.
erikjwagner
Posts: 4
Joined: Thu Oct 15, 2015 8:12 pm

Generic Method for Checking Repository items

Post by erikjwagner » Thu Oct 15, 2015 8:24 pm

Hi,
I tried searching for this and found several similar things but nothing on point; admittedly I could have been searching using wrong terms.
I have a large automation project that is being worked on by several different dev teams who don't communicate changes to me so I have been running into a lot of instances where my tests fail because a repository item no longer exists or has been moved or has had the attribute that I'm checking changed.
What I have started to do is make a 'checker' test that simply goes through and checks the info.Exists() status on each repository item with the idea that this could be run once a week and remediation would be more manageable.
I'm currently having to do these checks in a brute force manner of checking each repository item in an if/else block. What I would like to be able to do is write a generic method that has a repository item as a parameter to be passed into it and that method would then check the ..Info.Exists() state. So, what I would like to do is have something like

Code: Select all

public bool Check_RepoItem(RepositoryItem current)
{
  if (current.Exists())
  {
    return true;
  }
  else
  {
    return false;
  }
}
Is what I'm trying to accomplish possible and if so how? Thanks
erik

jma
Posts: 107
Joined: Fri Jul 03, 2015 9:18 am

Re: Generic Method for Checking Repository items

Post by jma » Mon Oct 19, 2015 2:20 pm

Hi Erik,

In order to make such a function generic you could pass a RepoItemInfo-object to the method.

Please have a look at the sample below.
Additionally, you could adjust the search timeout for the Exists()-method.

Code: Select all

public bool Check_RepoItem(Ranorex.Core.Repository.RepoItemInfo item)
{
      if ( item.Exists(5000) )
      {
        	Report.Info("Item exists!");
        	return true;
      }
      else
      {
        	Report.Error("Item does not exist!");
        	return false;
      }
}
When you call the method you have to pass the RepoItemInfo-object of the corresponding repository item as a parameter.

Code: Select all

Check_RepoItem(repo.MainWindow.TextBoxInfo);

erikjwagner
Posts: 4
Joined: Thu Oct 15, 2015 8:12 pm

Re: Generic Method for Checking Repository items

Post by erikjwagner » Tue Oct 20, 2015 2:49 pm

@jma Excellent! That is *exactly* what I was looking for, couldn't quite figure out the 'type' of the object to be passed, thanks very much!