I'm hitting this error:
java.lang.SecurityException: adb clearing user data is forbidden.'; Code: '1'
while running the below mentioned code on appium server in android 8.1.0 (oreo) but the same code is running fine in android 5.1 (lollipop). USB debugging is already on in mobile. Anyone having any idea why I'm hitting this error?`
package appium;
#BeforeTest
public void setcapbilities() throws Exception
{
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("deviceName","Vipul");
cap.setCapability(CapabilityType.VERSION,"8.1");
cap.setCapability("platformName","Android");
cap.setCapability("appPackage","com.android.calculator2");
cap.setCapability("appActivity","com.android.calculator2.Calculator");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),cap);
driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
}
#Test
public void firstt()
{
driver.findElement(By.xpath("//android.widget.Button")).click();
driver.findElement(By.xpath("7")).click();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}
#AfterTest
public void kill()
{
driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
driver.quit();
}
There few pointers which you can try to solve the issue you're facing.
First, use latest stable Appium server and Java client available.
Second, use AndroidDriver <MobileElement> instead of RemoteWebDriver. Since, AndroidDriver extends RemoteWebDriver via AppiumDriver, it must have overiden the quit method functionality.
Third, you don't need to call implicit wait everywhere. You must call it once in your set up method.
Forth, update your Android SDK and tools to latest.
It is not neccessary that if a something works in andorid v5 , then it should also work on android v8
Reason
To make the devices more secure , latest android versions are imposing restrictions on some already working APIs.
e.g. You can enable airplane mode using Appium API in mobile devices till Android V6, from Android V7 onwards this API has been blocked.
Solution
looking at your code, it seems ,the session should get created successfully , the only thing u need to take care is how to make your test successfull. May be you need to change your Xpath as per the UI for Android V8.
did you try checking this Xpath in APPIUM Desktop ?
https://automationlab0000.wordpress.com/2018/12/31/appium-desktop-for-locating-elements/
Related
I would like to set my Android app as device owner on a device running Android Things.
(I know that Android Things is getting shut down, but still I would need to make it work)
I tried the usual command: adb shell dpm set-device-owner <package>/<component>
This command works well on a standard Android device, but on Android Things I get the following response:
java.lang.RuntimeException: Can't set package ComponentInfo{<package>/<component>} as device owner.
at com.android.commands.dpm.Dpm.runSetDeviceOwner(Dpm.java:149)
at com.android.commands.dpm.Dpm.onRun(Dpm.java:96)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:54)
at com.android.commands.dpm.Dpm.main(Dpm.java:41)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:285)
I tried running the command as root (after adb shell & su), but still get the same error.
I also tried to create manually device_owner.xml, device_policies.xml,... files in /system/data, as mentionned in topics related to AOSP, but it has no effect.
Is it somehow possible to set device owner on an Android Things device?
Android Things are already deprecated now, you can use smartphone OS or Android. That is based on this quote:
Android Things is a now-deprecated Android-based embedded operating system platform by Google, announced at Google I/O 2015, and launched in 2018. In 2019, Android Things dropped support for low-power hardware and refocused on smartphone-class devices.
Owner in android can be used to set in this document explanation, sample code :
val provisioningActivity = getActivity()
// You'll need the package name for the DPC app.
val myDPCPackageName = "com.example.myDPCApp"
// Set up the provisioning intent
val provisioningIntent = Intent("android.app.action.PROVISION_MANAGED_PROFILE")
provisioningIntent.putExtra(myDPCPackageName,
provisioningActivity.applicationContext.packageName)
if (provisioningIntent.resolveActivity(provisioningActivity.packageManager) == null) {
// No handler for intent! Can't provision this device.
// Show an error message and cancel.
} else {
// REQUEST_PROVISION_MANAGED_PROFILE is defined
// to be a suitable request code
startActivityForResult(provisioningIntent,
REQUEST_PROVISION_MANAGED_PROFILE)
provisioningActivity.finish()
}
We are attempting to run our tests for our Mobile app on BrowserStack through our Bitbucket pipeline, using Appium version 6.0.0 with the AndroidDriver, which inherits from RemoteWebDriver. We are currently passing the URL to BS with our capabilities (AndroidDriver(AppiumDriverLocalService service, org.openqa.selenium.Capabilities desiredCapabilities)), however the test suite always loses connection to the BrowserStack Hub about half way through.
I wanted to try to add a Factory in the Android Driver to increase the HTTP Timeout and see if that would help my case (AndroidDriver(AppiumDriverLocalService service, org.openqa.selenium.remote.http.HttpClient.Factory httpClientFactory, org.openqa.selenium.Capabilities desiredCapabilities)). The code as is runs fine when running from my local machine to BS but as soon as we run from Bitbucket or even Jenkins, then the network issues start to occur.
Does anyone have an example on how I would be able to achieve this?
Tried this one?
WebDriverWait wait = new WebDriverWait(driver, timeLimitInSeconds);
element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“desired xpath”)));
Else you can explicitly wait for several seconds using thread.sleep()
I am a beginner in automation testing. I am trying to write common test project for my android and ios app. Both the apps on ios and android have almost same UI and flow. I want to know how can I instantiate Appium driver for based on the platform.
As of now, I am thinking to have a boolean variable isAndroid which I would have to manually change in the code before running the tests.Based on isAndroid I instantiate AppiumDriver to AndroidDriver or IOSDriver and elements will be located as per #AndroidFindby or #IOSFindBy
When I start Appium from the terminal, I mention the parameter platformName, is there a way to fetch that information in my code so that I do not have to manually change isAndroid variable and exactly same test code runs on both platforms.
Are you able to try one platform, catch the exception and then try the other?
try:
driver = webdriver.Remote('http://localhost:4723/wd/hub', ios_caps)
run_iOS_tests(driver)
except selenium.common.exceptions.WebDriverException:
driver = webdriver.Remote('http://localhost:4723/wd/hub', android_caps)
run_android_tests(driver)
Otherwise you'll need to use some external method to see what devices are connected (android, ios).
I've used hierarachyviewer earlier, but on android emulator. It works absolutely fine when I use it on the emulator. However it does not work with Samsung Galaxy TAB 7.0, with Android 2.3.4.
This is the log, that I get
11:04:22 E/hierarchyviewer: Unable to get view server version from device 303599
64881B00EC
11:04:22 E/hierarchyviewer: Unable to get view server protocol version from devi
ce 30359964881B00EC
11:04:24 E/hierarchyviewer: Unable to debug device 30359964881B00EC
11:05:05 E/hierarchyviewer: Unable to get view server version from device 303599
64881B00EC
11:05:05 E/hierarchyviewer: Unable to get view server protocol version from devi
ce 30359964881B00EC
11:05:07 E/hierarchyviewer: Unable to debug device 30359964881B00EC
11:09:38 E/hierarchyviewer: Unable to get view server version from device 303599
64881B00EC
11:09:38 E/hierarchyviewer: Unable to get view server protocol version from devi
ce 30359964881B00EC
11:09:40 E/hierarchyviewer: Unable to debug device 30359964881B00EC
I'm also not using hierarchyviewer in the debug mode, just running the application.
Thanks.
I found a workaround: https://github.com/romainguy/ViewServer
ViewServer is a simple class you can use in your Android application to use the HierarchyViewer inspection tool...
Verify that you need this library(newer versions of Android don't)
If you do need this library then follow these directions:
Include the ViewServer library(easy directions found here)
Your application must require the INTERNET permission
The recommended way to use this API is to register activities when they are created, and to unregister them when they get destroyed:
public class MyActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set content view, etc.
ViewServer.get(this).addWindow(this);
}
public void onDestroy() {
super.onDestroy();
ViewServer.get(this).removeWindow(this);
}
public void onResume() {
super.onResume();
ViewServer.get(this).setFocusedWindow(this);
}
}
Please refer to the documentation in ViewServer.java for more info...
Use the monitor-tool instead (android-sdk/tools/monitor).
Connect to your device. Close Eclipse first if you can't connect.
Press the "Dump view hierarchy for UI automator" button in the devices-tab. Its the one next to the screen-capture button.
Works since API Level 16 (Android 4.1).
You can only use HierarachyViewer on the emulator and special developer phones bought from google.
http://groups.google.com/group/android-developers/browse_thread/thread/b0b0af7a316ca768
Quote from above link
HierarchyViewer does not work on user builds (i.e. with devices
available in stores.) This is for security reasons. If HiearchyViewer
was able to work on user builds, any application on your desktop (or
even on the phone in some cases) could potentially get access to
private information (like logins and passwords.)
I'm solved question in max os
this ANDROID_HVPROTO solution is documented here:
http://developer.android.com/tools/performance/hierarchy-viewer/setup.html
then try to close Android Studio
run adb kill-server, adb start-server
and launch monitor work to me!
the answer is :
https://github.com/romainguy/ViewServer/issues/14#issuecomment-75354479
#ozodrukh's answer is usefull.
Almost no general-production phones will allow the HierarchyViewer to access them. Usually developer phones and emulators are the only ones with those features.
Similar issue i was having on 4.1 Android phone.Use ViewServer in your code.
Before checking in Hierarchy viewer,Just restart adb server once by doing.
the official documentation:Optimizing Your UI said so:
To preserve security, Hierarchy Viewer can only connect to devices running a developer version of the Android system.
Profile your layout with Hierarchy Viewer:
Set the environment variable
ANDROID_HVPROTO=ddm
So from [andrid-sdk]/tools folder run this in Command Line:
set ANDROID_HVPROTO=ddm
hierarchyviewer
Or put set ANDROID_HVPROTO=ddm in the hierarchyviewer.bat.
I want to create an android activity for setting up an SSH Session with a remote device (through Wifi) and executing some linux commands on the remote device. Anyone got a quick, short example for connecting, authenticating and sending remote commands using Trilead libraries in Android ? Connectbot source (the only place to find the source for the unmaintained library) is quite vast and time consuming to go through if one is just trying to do a quick SSH Connection/ Command execution. I had found the sshJ library earlier, which had nicely documented examples and tips but unfortunately Android lacks some Java.Util classes required for sshJ.
I am looking for something in Trilead like (this is from the sshJ example I found earlier) :
final SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();
ssh.connect("localhost");
try {
ssh.authPublickey(System.getProperty("user.name"));
final Session session = ssh.startSession();
try {
final Command cmd = session.exec("ping -c 1 google.com");
System.out.print(cmd.getOutputAsString());
System.out.println("\n** exit status: " + cmd.getExitStatus());
} finally {
session.close();
}
} finally {
ssh.disconnect();
}
If you are okay with restricting your app to Android 2.3+ (Gingerbread), then you can use sshj. You will have to create the SSHClient object with this
Config.