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
Related
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.
Is there a way to use Chromium switches after starting it up, or must they be enabled on start up? For example, can switches be passed to the renderer processes, or just to the main process?
I want to turn on paint flashing in Chromium (actually in my Electron app which runs on top of Chromium).
Devtools has a checkbox that turns this on, but I want to be able to turn this on without devtools, and after the app has started.
I know there's a show-paint-rects flag I can use:
chrome.exe --show-paint-rects
In my Electron app, I would need to use app.commandLine.appendSwitch:
app.commandLine.appendSwitch("show-paint-rects");
I also found a ui-show-paint-rects flag that lives in something called the "compositor," but that may be irrelevant for me.
Both of these work, but since Chromium uses a multi-process architecture, I'm hoping that there's a way I can specify that switch, or otherwise, turn on a feature in one process and not have to specify it at startup.
Is there a way to do this in Chromium? (Would be ideal to do this in Electron, but I'm not counting on it)
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
We are trying to migrate from UIAutomation to XCUITests and did use the captureScreenWithName() API to programmatically generate screen shots.
What is the replacement in the XCUITests ?
(I know that automatically screenshots are taken in case of error, but we have a special test which runs forever in a loop and evaluates QA click,tap commands via network similar to the appium-xcuitest-driver https://github.com/appium/appium-xcuitest-driver)
Do I need to rip out private headers (XCAXClient_iOS.h) like the appium guys did in order to get a screenshot API?
Edit
I used the actual code line for the accepted solution from
https://github.com/fastlane/fastlane/blob/master/snapshot/lib/assets/SnapshotHelper.swift and its just this for IOS
XCUIDevice.sharedDevice().orientation = .Unknown
or in objC
[XCUIDevice sharedDevice].orientation =UIInterfaceOrientationUnknown;
I use a process on the host to lookup in the "Logs/Test/Attachments" directory all Screenshot_*.png files before the call , and find the new shot then after the call as the new file added in this directory.
Gestures (taps, swipes, scrolls...) cause screenshots, and screenshots are also often taken while locating elements or during assessing expectations.
Fastlane's snapshot tool uses a rotation to an unknown orientation to trigger a screenshot event (which has no effect on the app): https://github.com/fastlane/fastlane/tree/master/snapshot - you can use this if you want to be in control of some screenshots.
Is it possible to stop Firefox from popping up when cucumber hits a #javascript tag? After a while it gets frustrating to always get disrupted while running tests.
It would be nice if webdriver was to start Firefox minimized or not focus on it.
There's no API in WebDriver to do this, and it's not really advisable since Firefox won't trigger certain events (like focus, blur) when the window is in the background. I usually work around this by using a virtual machine (e.g. in VirtualBox) or a separate X display.
You can add lines below to Info.plist of Firefox.app. After that it will start without grabbing focus.
<key>LSBackgroundOnly</key>
<string>1</string>