Difference in manual execution of running app in background and runAppInBackground() using appium - appium

While executing runAppInBackground() for Android application through Appium the app gets restarted but when executed the same manually couldn't be able to reproduce the same. I Would like to deep dive into implementation of a runAppInBackground() method to reproduce the same issue in a manual way.

You need to look behind the code of runAppInBackground
From java client side (your test code) perspective, it is a single call to Appium server:
POST "/session/:sessionId/appium/app/background"
If you continue looking into where its implemented on server side, you finish with appium-android-driver function.
In short what it does:
Get current activity and package
Press physical Home button
Wait for time you provided as argument (seconds)
Bring up back in focus based on different conditions; from the code you can understand what activity is being started
Basically its a sequence of adb shell commands, that you can run from terminal.
My guess is that step 4 you did manually may differ from what Appium is doing: different activities/arguments for activity been called

Related

"Cached element do not exists in DOM" when run Appium with Robot Framework

I'm working on automated test using Appium with Robot framework on Android device. I create schedule run on Jenkins. My test flow is entering some data in page A and submit, then switch to page B to check the result and switch to page A to enter a new data. I repeat this loop for around 10+ time. Everything works fine in around 4-5 rounds but after that there show up an error :
StaleElementReferenceException: Message: Cached element 'By.xpath:
//android.widget.TextView[#text='Limit']' do not exists in DOM anymore
The TextView is in the page A. I monitored the robot and saw that the TextView was shown up but the robot did not see it. I tried restart the device but the problem is not solved. I search through the internet and found some who facing the same issue but they use different programming language like Java or Python. I have no idea what I have to do next.
Development Tools :
Appium version: 1.21.0
Robot Framework version: 4.1.2 (Python 3.10.0 on win32)
First I do not use Robot Framework, but the code should be similar according to this https://robocorp.com/docs/languages-and-frameworks/robot-framework/try-except-finally-exception-catching-and-handling.
Second, I'm not sure if this is the best way to get around this. I think there is something you can do with the expected conditions class to get around this in a "cleaner way" but I'm not quite familiar with it enough to show/tell you. Instead what I've done is something like this...
from selenium.common.exceptions import StaleElementReferenceException
while some_limiting_factor:
try:
# logic for submitting page A, assertions for page B
except StaleElementReferenceException:
element = driver.find_element('By.xpath: //android.widget.TextView[#text='Limit']' )
As much as I want to cache elements in appium, it seems that the service itself does NOT want you to, at least not in my experience. Getting a fresh element(s) every time seems to ensure a "slow but steady" test. Hopefully someone can show me the deep appium secrets one day.

Appium works very slow on screen having dynamic mobile elements

I am working on automating an Android app. We have a screen that has a table wherein the cell values keep on changing in seconds. I have observed that it takes more than a minute for AndroidDriver to execute a single action.
I have read on some other forums about this and got to know that this is how the UiAutomator2 works and it has nothing to do with Appium. UiAutomator2 waits for elements to come to a static state and then performs the actions.
Since the dynamic elements on the screen are unavoidable, is there any workaround for this to make Appium scripts execute with good speed? Let me know what you all think of this. I will really appreciate your comments on this. Thanks.
Yes, that is right. It has nothing to do with Appium itself, but with UiAutomator. UiAutomator takes accessibility snapshots only when the application is in idle mode and the framework itself is not optimized for cases when there are constant changes in the page view. As a workaround, try to play around with waitForIdleTimeout such as setting it to zero or try with setting the disableWindowAnimation to true in the desired capabilities.
You could also try with running the following commands:
adb shell settings put global window_animation_scale 0
adb shell settings put global transition_animation_scale 0
adb shell settings put global animator_duration_scale 0
As a last resort, you could ask for the developers to provide you with a special build that has the animations removed in the source code.
I had the same issue, my specific problem was that the mobile app had a timer in the UI, that was changing its value every second.
Looks like the driver was waiting for the DOM to become idle, so it was SUPER slow because of that.
This simple command fixed the issue for me:
# Python code
driver.update_settings({"waitForIdleTimeout": 0})
Additional references:
https://appium.io/docs/en/commands/session/settings/update-settings/
https://github.com/appium/appium/issues/14155

Run python kivy application in "kiosk mode"

I've created a simple python application running in raspbian using kivy. The application runs already nicely in full screen mode. however I would like to be sure it cannot be interrupted with ctrl-c or any other command using the keyboard, and the application must never lose focus if something happens in the OS (for example some kind of dialog opens - I'm not sure if this actually can happen). I'd appreciate things that should be taken care of.
My app doesn't need to be bullet-proof, but it should endure a "casual user".
You can catch Ctrl+c or other signals with the signal module.
import signal
def signal_handler(signal, frame):
pass
signal.signal(signal.SIGINT, signal_handler)
This code prevent the user to exit by sending the SIGINT signal, corresponding to ctrl + c.
Other signals: https://unix.stackexchange.com/questions/317492/list-of-kill-signals

UIAutomation bringing iOS app to a consistent state

I writing JavaScript test for my iOS app. I am hoping of using Apples Profiler and UIAutomation.
1) I was wondering how can I reset the app every time I run the test. I would like to reset my app to a consistent state every time before I run a new test. Have separated my tests into few groups. Every test of the first group should start on the first screen containing a tableView and filters for sorting elements in that table should be set to a consistent state. Second group of tests should start on the Settings screen and some options/switches should be pressed in particular order for me to test the UI.
2) Also first time the app starts there is a tutorial. How can I make the app think it is freshly installed and test the tutorial feature.
Thanks for the answers
How can I make the app think it is freshly installed ?
As the iOS applications are sandboxed, the only way is to delete and re-install the app every time.
In the Illuminator framework that I wrote (which extends UIAutomation), we provide an automation bridge that allows us to send "reset" commands to the app, putting it into a known state before each test is run. This makes the testing very repeatable, even if some tests fail.
Additionally, the command line scripts can recover the test run even if the app crashes.

How to profile an ASP.NET web service on a remote server by EQATEC profiler?

I am thinking the modified dlls will create a log file some where in the remote system so I can open it later after load test but all I found was a log file in $(SystemRoot)\Temp\EQATECProfilerLogs saying nothing other than app started. Do I need to install EQATEC profiler on the remote server?
Thanks
This scenario is adressed in this EQATEC forum thread:
A profiled app needs to be told when we want it to produce its profiling report. For plain apps this is simple and has therefore been automated: when Main exits. But your web-service has no similar "exit point" - it just keeps on running until you kill it.
Therefore you have to explicitly/manually tell the profiled web-service to take a snapshot. The easiest way is to simply run the profiler on the same machine as the web-service is running on: when the web-service is starting up it will automatically connect to the profiler and you can then run your tests and control/dump timing info at will using the "take snapshot" and "clear counters"-buttons.
Alternatively, you can make a reference to the supplied runtime-module from within your code and make explicit calls to the API (TakeSnapshot etc) precisely where you want in your code. The runtime-modules reside in C:\Program Files\EQATEC\EQATECProfiler\RuntimeDLL.

Resources