Press Back key until something comes - issues

Mobile Testing, Android App Testing.
User avatar
sandamal
Posts: 28
Joined: Wed Jul 08, 2015 7:50 am

Press Back key until something comes - issues

Post by sandamal » Tue Nov 22, 2016 6:24 am

Hi ,

I created below code to press Android mobile back button until it comes to a particular window with label "Unassigned" and it is working for the purpose.

below are the issues i'm facing,

1) Report mark this as a Fail step since in several cases it fails Validate. method. I want to avoid that
2) validating take some standard time (around 1.5 mins ) , i want to avoid that, can i override validation time in code
3) is there other better workaround to fit for purpose.

please advice :shock: :shock:


Code: Select all


 public void Invoke_Action_MobileApp()
 {
      while(Validate_Unassigned_Labe_Not_Exist())
        {
            Report.Log(ReportLevel.Info, "Invoke Action", "Invoking PressBackKey() on item 'MobileApp'.", repo.MobileApp.SelfInfo);
            repo.MobileApp.Self.As<AndroidApp>().PressBackKey();
        }
 }
        
       

public Boolean Validate_Unassigned_Label_Not_Exist()
{
      try{
            Validate.Attribute(repo.MobileApp.RefImplOrderListActivity.Unassigned1Info, "Text", "Unassigned");
            Validate.Attribute(
          } catch(Exception e)
        	{
        		return true;
        	}
        	return false;
        }


Martin
Posts: 152
Joined: Fri Aug 15, 2014 12:24 pm

Re: Press Back key until something comes - issues

Post by Martin » Tue Nov 22, 2016 9:13 am

I modified your methods a bit and now you will not get a failed step in reports if the element doesn't exist.
public void Invoke_Action_MobileApp()
{
	while (!Validate_Unassigned_Label_Exist())
	{
		Report.Log(ReportLevel.Info, "Invoke Action", "Invoking PressBackKey() on item 'MobileApp'.", repo.MobileApp.SelfInfo);
        repo.MobileApp.Self.As<AndroidApp>().PressBackKey();
	}
}

public Boolean Validate_Unassigned_Label_Exist()
{
	bool TitleExists = new bool();
	
	try
	{
		Validate.Options option = new Validate.Options(ReportLevel.Info);
		option.ExceptionOnFail = false;
		TitleExists = Validate.Attribute(repo.MobileApp.RefImplOrderListActivity.Unassigned1Info, "Text", "Unassigned", "", option);
	} catch (Exception e) {
		return false;
	}
	
	return TitleExists;
}
Now onto the next point related to the long timeout. The timeout actually comes from the repository properties. Probably the element you are looking for is the 3rd children inside some folders in repository. Each repository element usually has 30sec search timeout and if it is inside another element it will be added together. So in your case there are 3 30sec timeouts added together.

To overcome this i actually created a seperate grouping in my repository for those specific elements where i need a low search timeout (as the scenario you specified in your post).

So lets say i have a button which i have added to the repository:

Repo
- Firefox (30 sec timeout)
-- SearchBtn (30 sec timeout)

So the timeout in this case will be 1 minute for SearchBtn.

Now i actually create a copy of the Firefox repository grouping and right click on each of the newly created folder elements and select properties. You will see a timeout field on the right of Ranorex Studio and i have set the timeout to 200ms.

Repo
- Timeout_Firefox (100 ms)
-- SearchBtn (100 ms)

- Firefox (30 sec)
-- SearchBtn (30 sec)

Now i just target the timeout repo element in my code and the timeout will be 200ms.

But you have to remember to add some validation for elements to exists where needed because this is quite a small timeout and your page might just not load with this short amount of time.

So the flow would be where needed as such:

Wait for the back button to exists ( repo.Firefox.BackBtnInfo.WaitForExists(10000); )
And then validate the text.