I'm working on a way to automate testing for mobile app development. I am creating a generic function that should take in a repo element, go into a try catch statement to determine what to do if the element cannot be found. This is to ensure that the test will continue if it fails the check, allow for specific debugging messages and make the higher level code more flexible. If the container is visible, it will click on the container and return. It will catch the exception, log the error and return back.
Ideally, I want to be able to pass in both containers/Elements so that this framework is compatible with both iOS and Android. The android and iOS have enough differences that I made two public classes that will be calling these generic functions in a third class. The android and iOS classes both have a separate repo object and therefore have to pass it into the generic as a parameter.
Here is the function I am calling
Code: Select all
public static void checkAndClick(Ranorex.Container repoElement)
{
try
{
if(repoElement.Valid)
{
repoElement.Touch();
}
return;
}
catch(ElementNotFoundException)
{
Report.Log(ReportLevel.Info, "Status", "Error: Element Catch");
return;
}
}
When I pass in a container that is visible, the try catch works as expected.
However, if I pass in a container that exists in the repository but is not visible on the screen, it fails as a parameter. Any log statements that are in the function will not be reached and Ranorex errors out with the ElementNotFoundException. I believe this is because the element does not exists when passing it into the function and therefore makes the try useless.
I also tried passing in the parameter as a RepoItemInfo and was met with the same error with this code.
Code: Select all
public static void checkAndClick(RepoItemInfo repoInfo)
{
var element = repoInfo.CreateAdapter<Unknown>(true);
try
{
if (element.Visible)
{
element.Touch();
}
}
catch(ElementNotFoundException)
{
Report.Log(ReportLevel.Info, "Element catch");
}
}