Refresh android app from script

Hi everyone,
Does anyone know how to refresh app from code.
We can do it using Appium UI just click “Refresh” button, appium sent the following command:
{“cmd”:“action”,“action”:“source”,“params”:{}}
I noticed that sometime, when UI of application changes, I’ve got incorrect, old data, and, it seems, it’s needed to do something like refresh.
Did anyone faced with it?

Hi @SergeVKom,

There is a resetApp() command available, which might help you with android/ios driver.

Thanks,
Sujata

thank you for answer!
resetApp() close application and open it again, but I want just refresh element hierarchy, because appium does not see new elements in UI after not big changes (for instance a little panel appears)

Hi @SergeVKom

It sounds like you want the view to refresh instead of the App. I haven’t had this problem during testing (using Appium 1.3.5), but perhaps if you can explain the events that occur and what should be happening but isn’t in more detail, we can help you out.

–Will

If you invoke the get source method that might help. That’s what the Appium.app does under the hood when you press the refresh button.

1 Like

Hi @bootstraponline
This is exactly what I want, but I don’t know HOW to invoke the get source method from java code. Do you try it?

driver.runAppInBackground(1)
we use very sometimes when met with same issue that some elements appeared dynamically not visible.

In ruby I do get_source, try maybe:

driver.getPageSource()

driver.getPageSource() is correct for Java.

1 Like

@Telmo_Cardoso, @bootstraponline Thanks guys!
Works perfect. Don’t know why I didn’t see it earlier…

I’ve noticed with ruby that if I call the ‘page’ method it’ll refresh the location of different elements. The problem is that it outputs the page elements to the console which clutters test results. Is there a ‘quieter’ way of doing this?

Hi all, in case you haven’t figured out like me one day ago, the solution is simple. Use the swipe method. Here is an example that worked for me in a nexus 5:

driver.swipe(411,290,411,900,2000);

Thanks :slightly_smiling:

I applied the above solution on Google Pixel, but it fails the problem I am facing is that when the android screen load completely after the service request complete we are not getting the element from the screen, for that reason we tried to refresh the screen, spent my complete day, but fails, pleas help.

Can you help e to get the same code in python.
Currently am sending the app to background, But it has some adverse effect on testing.

Thanks