How to move the focus to another app in appium - java

I'm writing test automation for an app. The app launches the phone dialer with a specific phone number when clicking a button. I want to return the phone number to my code and return it to the app.
I'm using appium 1.21 and java.
I've tried to use this code:
androidDriver.activateApp("com.android.phone");
System.out.println(androidDriver.findElement(MobileBy.id("digis")).getText());
androidDriver.activateApp("com.app.test"); //return to the app from dial
but i'm getting an error :
Encountered internal error running command: Error: Cannot activate
'com.android.phone'. Original error: Error executing adbExec. Original
error: 'Command '/Users/idoa/Library/Android/sdk/platform-tools/adb -P
5037 -s ce051605bd453d2502 shell monkey -p com.android.phone -c
android.intent.category.LAUNCHER 1' exited with code 252'; Stderr:
'args: [-p, com.android.phone, -c, android.intent.category.LAUNCHER,
1]
How can I do it?

Key presses on appium are done by
driver.press_keycode(code)
All required codes can be found here
187 - KEYCODE_APP_SWITCH
Try this, not sure whether it solves

Related

Appium fails to launch on Android emulator with multiple activities

I'm using
Appium v1.22.2
IntelliJ community
Gradle with dependencies
implementation 'io.appium:java-client:7.6.0'
testImplementation 'junit:junit:4.13.1'
implementation 'org.assertj:assertj-core:3.22.0'
Can you please help me to start an application via Appium on Android Emulator with multiple activities?
I couldn't get ahold of the concept of App_Wait_Activity and was trying to find the best suitable activity. While looking at Appium logs, it says that appium found the best match which is presentation.onboarding.OnboardActivity. When I choose this activity the application launches and quits, and there are errors. (See the error log below)
I also checked AndroidManifest.xml on Android Studio and there are multiple activities coming from top to bottom as:
android:name=".presentation.splash.StartActivity"
android:name=".presentation.onboarding.OnboardActivity"
android:name=".presentation.splash.SplashActivity"
android:name=".MainActivity"
android:name=".presentation.custom_view.widgets.WidgetsActivity"
The error log with chosen App_activity as .presentation.onboarding.OnboardActivity.
https://res.cloudinary.com/newslettergs/image/upload/v1657776487/Screen_Shot_2022-07-14_at_11.25.13_diutcy.png
org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: Cannot start the 'app_package_name' application. Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting. Original error: Error executing adbExec. Original error: 'Command '/Users/baizhan/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell am start -W -n app_package_name/app_package_name.presentation.onboarding.OnboardActivity -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000' exited with code 255'; Command output: Security exception: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=app_package_name/.presentation.onboarding.OnboardActivity } from null (pid=10838, uid=2000) not exported from uid 10151
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=app_package_name/.presentation.onboarding.OnboardActivity } from null (pid=10838, uid=2000) not exported from uid 10151
at com.android.server.wm.ActivityStackSupervisor.checkStartAnyActivityPermission(ActivityStackSupervisor.java:1043)
at com.android.server.wm.ActivityStarter.startActivity(ActivityStarter.java:760)
at com.android.server.wm.ActivityStarter.startActivity(ActivityStarter.java:583)
at com.android.server.wm.ActivityStarter.startActivityMayWait(ActivityStarter.java:1288)
at com.android.server.wm.ActivityStarter.execute(ActivityStarter.java:514)
at com.android.server.wm.ActivityTaskManagerService.startActivityAndWait(ActivityTaskManagerService.java:1231)
at com.android.server.am.ActivityManagerService.startActivityAndWait(ActivityManagerService.java:3512)
at com.android.server.am.ActivityManagerShellCommand.runStartActivity(ActivityManagerShellCommand.java:513)
at com.android.server.am.ActivityManagerShellCommand.onCommand(ActivityManagerShellCommand.java:172)
at android.os.ShellCommand.exec(ShellCommand.java:104)
at com.android.server.am.ActivityManagerService.onShellCommand(ActivityManagerService.java:9774)
at android.os.Binder.shellCommand(Binder.java:881)
at android.os.Binder.onTransact(Binder.java:765)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:4498)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2741)
at android.os.Binder.execTransactInternal(Binder.java:1021)
at android.os.Binder.execTransact(Binder.java:994)
I am not able to see automationName in your capabilities. You can follow this guide.
You can also follow this to setup your appActivity or appWaitActivity

Original error: io.appium.uiautomator2.common.exceptions.UiAutomator2Exception

Getting unknown server-side error while running the script.
The script would terminate while scrolling else it would work fine.
Log error:
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: io.appium.uiautomator2.common.exceptions.UiAutomator2Exception: java.lang.IllegalStateException: UiAutomation not connected!
at io.appium.uiautomator2.utils.UiExpressionParser.invokeMethod(UiExpressionParser.java:251)
at io.appium.uiautomator2.utils.UiScrollableParser.consumeMethodCall(UiScrollableParser.java:124)
at io.appium.uiautomator2.utils.UiScrollableParser.parse(UiScrollableParser.java:60)
at io.appium.uiautomator2.utils.UiAutomatorParser.consumeStatement(UiAutomatorParser.java:93)
at io.appium.uiautomator2.utils.UiAutomatorParser.parse(UiAutomatorParser.java:49)
at io.appium.uiautomator2.utils.LocationHelpers.toSelectors(LocationHelpers.java:95)
at io.appium.uiautomator2.utils.LocationHelpers.toSelector(LocationHelpers.java:88)
at io.appium.uiautomator2.handler.FindElement.findElement(FindElement.java:144)
at io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:75)
at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:37)
at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:250)
at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:241)
at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
* **Element info:
{Using=-android uiautomator, value=new UiScrollable(new UiSelector()).scrollIntoView(new UiSelector().text(" val "));}
Appium Log:
restarting adb before the test run with adb kill-server; adb start-server.
because sometimes the appium server having issue with adb so by restarting you can avoid this problem not every time when this error comes you can again start executing if not solved then please restart adb and then start executing script that will work..
Happy to help...
In case you have any doubts comment down below..

Selendroid "Error forwarding the new session cannot find : Capabilities"

I've got a problem with my selenium config. I'm trying to automate Selenium test on iOS and Android.
The iOS test are running correctly with iOS Driver independently.
The Android test are running correctly independently too.
But when i want to run iOS and Android i've got problems !
For my Android test, i was running this command and everything was fine :
java -jar selendroid-standalone-0.17.0-with-dependencies.jar
But when i want to integrate iOS test, i change the port of this command, following this guide : http://selendroid.io/scale.html
But when I add -port 5555, my Android test fails. With this error :
org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find : Capabilities [{automationName=selendroid, platform=ANDROID, platformName=android, browserName=android, serial=VM-IP}]
I start my config with the following command :
java -cp ios-grid-plugin-0.6.6-SNAPSHOT-4.jar:selenium-server-standalone-2.52.0.jar:selendroid-grid-plugin-0.17.0.jar org.openqa.grid.selenium.GridLauncher -role hub http://192.168.2.33:4444/wd/hub
Am I doing something wrong ?
Thanks for help
Error forwarding the new session cannot find
is the Grid's way of telling you that you are trying to create a new browser session with a capability that the Grid is NOT aware of.
After starting the Selendroid server, did you run the CURL command as documented in this page
curl -H "Content-Type: application/json" -X POST --data #selendroid-nodes-config.json http://localhost:4444/grid/register
Doing this would now force the selendroid server to register itself to the grid running in local host and listening on "4444" and inform the grid that it can service android tests.
Without that, I don't think you can run your Selendroid tests in the Grid mode.

Error emulate android ionic framework

I'm creating an app with ionic, but I can not emulate it in android to see their functions properly.
Here is the error when running the command to emulate
I'm using Ubuntu 4.14 Linux OS
sandim#Inspiron-5448:~/projects/soucgApp$ sudo ionic emulate android
Running command: /home/sandim/projects/soucgApp/hooks/after_prepare/010_add_platform_class.js /home/sandim/projects/soucgApp
add to body class: platform-android
Running command: /home/sandim/projects/soucgApp/platforms/android/cordova/run --emulator
ERROR: Error: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually.
Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.
Error: /home/sandim/projects/soucgApp/platforms/android/cordova/run: Command failed with exit code 2
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:139:23)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1015:16)
at Process.ChildProcess._handle.onexit (child_process.js:1087:5)
does anyone know how to fix this?

Jenkins - could not read Username for 'https://github.com': No such device or address

I'm trying to set up Jenkins / Hudson on my Ubuntu PC. That's not the problem but I set an Android job with the following commands:
export CLEAN=false
export LUNCH=cm_ace-userdebug
export REPO_BRANCH=cm-10.1
export RELEASE_TYPE=CM_NIGHTLY
curl -O https://raw.github.com/CyanogenMod/hudson/master/job.sh
. ./job.sh
The job stops after a few seconds because of the error:
could not read Username for 'https://github.com': No such device or address
How do I fix this error?
Please help!
I suspect that Jenkins is attempting to open "/dev/tty" or something to ask you for a user name and password. That is failing because Jenkins is running as a daemon ... and "/dev/tty" can't be used in that context. The "No such device or address" comes from the failed attempt to open "/dev/tty".
The solution would be to configure the job to use a specific private key for the fetch. Read the curl manual entry and check out the -E option. Alternatively, you could use -u and specify the username and password in the curl command.

Categories

Resources