When I run the Appium test for the below code - appium

AndroidDriver driver;
#Test
public void setUp() throws MalformedURLException{
//Set up desired capabilities and pass the Android app-activity and app-package to Appium
DesiredCapabilities capabilities = new DesiredCapabilities();
/*capabilities.setCapability("BROWSER_NAME", "Android");*/
capabilities.setCapability("platformVersion", "5.1");
capabilities.setCapability("deviceName","G4");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("appPackage", "StatusBar"); // This is package name of your app (you can get it from apk info app
capabilities.setCapability("appActivity", "com.android.calculator2/.Calculator t126"); // This is Launcher activity of your app (you can get it from apk info app)
//Create AndroidDriver instance and connect to the Appium server.
//It will launch the Calculator App in Android Device using the configurations specified in Desired Capabilities
driver = new AndroidDriver(new URL("http://10.97.52.83:4723/wd/hub"), capabilities);
}
Getting below error
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: 'java -version' failed. Error: Command failed: 'java' is not recognized as an internal or external command,
operable program or batch file.
) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 242 milliseconds
Build info: version: '2.45.0', revision: '32a636c', time: '2015-03-05 22:01:35'
System info: host: 'ingglw016025a', ip: '10.97.52.83', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_51'

This error means your appium server is not running. Just try to kill the server and start it again. This should fixed this issue.

Related

Unable to create new Remote session error on launching mobile app multiple time using Appium

I am new to Mobile Automation and trying to set up Framework for the same. To get started i set up the required environment & also able to launch the calculator app using below code. But if i execute the same script multiple times it is throwing below Error . If i uninstall the Appium Setttings and execute than it starts working.
My question is: Do we need to uninstall the Appium settings as part of script everytime or how i can handle this situation to avoid error on executing below code multiple times.
public static void main(String[] args) {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "Galaxy S9");
caps.setCapability("udid", "3448594b4874498"); //Give Device ID of your mobile phone
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "9.0");
caps.setCapability("appPackage", "com.sec.android.app.popupcalculator");
caps.setCapability("appActivity", "com.sec.android.app.popupcalculator.Calculator");
caps.setCapability("noReset", "true");
//Instantiate Appium Driver
try {
AppiumDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);
} catch (MalformedURLException e) {
System.out.println(e.getMessage());
}
}
Error:
Exception in thread "main" 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: Could not find 'aapt.exe' in ["C:\Android_sdk\3_1\android-sdk\platform-tools\aapt.exe","C:\Android_sdk\3_1\android-sdk\emulator\aapt.exe","C:\Android_sdk\3_1\android-sdk\tools\aapt.exe","C:\Android_sdk\3_1\android-sdk\tools\bin\aapt.exe"]. Do you have Android Build Tools installed at 'C:\Android_sdk\3_1\android-sdk'?
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'TLMCCND72485NJ', ip: '26.28.23.66', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'
Driver info: driver.version: AndroidDriver
1st of all try to install appium-doctor and check all the requirements are installed and configured truly:
npm install appium-doctor
The server-side error in appium happens when the appium server could not connect to Node.js
Once you pass the appium doctor check-ups you should not have problem.
Also define the Driver in try-catch block is not good idea. Because you masked the real error and passed it to MalformedURLExceptions. The appium has exception handler itself.

Browser is not opening when running Jenkins as a service

I am running my selenium tests in IE in a Windows VM with the help of Jenkins. When running java -jar jenkins.war, my suite is working fine..
But when Jenkins is running as a service, browser is not opening and always it is failing.
I have opened the service properties and given Allow service to interact with desktop.
The alternate way I am running java -jar jenkins.war as a start up.. But this is starting jenkins when I login VM but if some circumstances due to windows patch update if machine gets restarted this is not working until I login the VM which is not i want.
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73), userDataDir=C:\Windows\TEMP\scoped_dir6052_18573}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=70.0.3538.102, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=false, acceptInsecureCerts=false, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=}]
Session ID: e6ef32b1e294ce9644a5078d9b8bf8c4
Failed ***********
Started InternetExplorerDriver server (32-bit)
2.51.0.0
Listening on port 45007
Only local connections are allowed
org.openqa.selenium.UnhandledAlertException: Modal dialog present:
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:18:15'
System info: host: 'xx-xx-xx', ip: 'xx.xx.xxx.xxx', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_191'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{browserAttachTimeout=0, enablePersistentHover=true, ie.forceCreateProcessApi=false, pageLoadStrategy=normal, ie.usePerProcessProxy=false, ignoreZoomSetting=false, handlesAlerts=true, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:45007/, takesScreenshot=true, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=dismiss}]
Session ID: dbbe2316-a3b3-4e39-82e3-04dae698ec73
Nov 16, 2018 6:17:43 PM org.openqa.selenium.support.ui.ExpectedConditions findElement
WARNING: WebDriverException thrown by findElement(By.id: txtUserName)
org.openqa.selenium.UnhandledAlertException: Modal dialog present:
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:18:15'
System info: host: 'xxx-xx-xx', ip: 'xx.xx.xxx.xxx', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_191'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Error log states that your test failed because of:
org.openqa.selenium.UnhandledAlertException: Modal dialog present
It happens when some alert appeared and was not properly handled by your test. To fix it you need to add a logic to handle alert before you call a method to look for an element findElement(By.id("txtUserName")). The code might look like this:
try {
Alert alert = driver.switchTo().alert();
System.out.println("Alert appeared. Text= " + alert.getText());
alert.accept();
} catch (NoAlertPresentException ignored) {
//if alert is not present for some reason we don't want to fail and can continue a test
}
or you can wrap to a findElement call with a try catch, then close the alert, and try your logic again:
WebElement el;
try {
el = findElement(By.id("txtUserName"));
} catch (UnhandledAlertException f) {
try {
Alert alert = driver.switchTo().alert();
System.out.println("Alert appeared. Text= " + alert.getText());
alert.accept();
el = findElement(By.id("txtUserName"));
} catch (NoAlertPresentException ignored) {
//if alert is not present for some reason we don't want to fail and can continue a test
}
}

getting error "INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling

Using code for opening Amazon application through Appium. But getting error INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling". How can i solve it. I'm using Appium version 1.4.16.1 & Android 7.0 moto G4 plus as device.
package amazonApp;
import io.appium.java_client.android.AndroidDriver;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class App {
private static AndroidDriver driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException {
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "/App/Amazon/");
File app = new File(appDir, "amazon-india-online-shopping-12-2-0-300.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "ZY2239N792");
capabilities.setCapability("platformVersion", "7.0");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "in.amazon.mShop.android.shopping");
capabilities.setCapability("appActivity", "com.amazon.mShop.home.HomeActivity");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.findElementByName("Skip sign in").click();
System.out.println("hii");
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
Thread.sleep(10000);
driver.quit();
}
}
I'm getting error:-
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Command failed:
C:\Windows\system32\cmd.exe /s /c "C:\Users\nik\AppData\Local\Android\sdk\platform-tools\adb.exe -s ZY2239N792 install
"C:\Program Files (x86)\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk""
Failed to install C:\Program Files (x86)\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk:
Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]
) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 31.43 seconds
Build info: version: '2.45.0', revision: '32a636c', time: '2015-03-05 22:01:35'
System info: host: 'nik-nik', ip: '192.168.84.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_131'
Driver info: io.appium.java_client.android.AndroidDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:180)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:126)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:153)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:109)
at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:39)
at amazonApp.App.main(App.java:31)
You should first remove Amazon app from device or you should change your desired capabilities to use the app installed on device already.

Getting "Permission to start activity denied" error in logs on running appium test on real device

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Permission to start activity denied.) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 5.41 seconds
Build info: version: 'unknown', revision: '2aa21c1', time: '2016-08-02 14:59:43 -0700'
System info: host: 'rude', ip: '192.168.1.8', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_101'
Driver info: io.appium.java_client.android.AndroidDriver
Stop the appium server and restart again.
This problem will occur when the launcher activity which you set in appium is not the default launch activity. So I suggest you to change the Launcher activity from the dropdown to other activity which is default activity. Try this.
check with developer for default launcher activity
I set ("autoGrantPermissions","true"). Removed appActivity capability and set appWaitActivity and the issue got resolved.
A new session could not be created. (Original error: Permission to start activity denied.)
above error comes when your appium is not started or sometimes Appium stops working with no reason with error code 500. So restart appium and run your test.
Some time already developed Application has maintain security.
for opening Application from splash screen to next Activity refer below code,
File appDir = new File ("src");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Device");
cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "25");
cap.setCapability("appPackage","com.demo" );
cap.setCapability("appActivity","com.demo.ui.splash.SplashActivity");
cap.setCapability("noReset", "true");
AndroidDriver<AndroidElement> driver = new AndroidDriver<> (new URL("http://117.0.0.1:1723/wd/hub"),cap);
Make sure to set cap.setCapability("noReset", "true");
for launching next activity after Splash activity.

how to run appium tests in selendroid mode (API<17)>

I want to run automation test on real devices, earlier i did this on emulators (API>17) but the same test i was trying to run on Appium in selendroid mode it failed.
Below is the capabilities i configured for appium to run in selendroid mode.
Appium Version : 1.0
Selendroid Version: 0.10
I run appium on port no : 6001 and bootstrap port : 4001, And selendroid server run on default port : 8080
private static String url = "http://localhost:"
+ System.getProperty("appium_port") + "/wd/hub";
private AppiumDriver driver;
private static DesiredCapabilities capabilities;
capabilities = new DesiredCapabilities();
File app = new File("en-android.apk");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Selendroid");
capabilities.setCapability(CapabilityType.PLATFORM, "ANDROID");
capabilities.setCapability("device", "Selendroid");
capabilities.setCapability("platformVersion", "4.1.2");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("app-activity",
"testapp.android.gui.WelcomeActivity");
capabilities.setCapability("app-package",
"testapp.android");
driver = new AppiumDriver(new URL(url), capabilities);
Below is Applium server logs.
Appium Log:
error: Android devices must be of API level 17 or higher. Please change your device to Selendroid or upgrade Android on your device.
info: Stopping logcat capture
debug: Logcat terminated with code null, signal SIGTERM
info: Sent shutdown command, waiting for UiAutomator to stop...
warn: UiAutomator did not shut down fast enough, calling it gone
info: Cleaning up android objects
info: Cleaning up appium session
error: Failed to start an Appium session, err was: Error: Android devices must be of API level 17 or higher. Please change your device to Selendroid or upgrade Android on your device.
info: Error: Android devices must be of API level 17 or higher. Please change your device to Selendroid or upgrade Android on your device.
at /home/priyankpshah/.linuxbrew/lib/node_modules/appium/lib/devices/android/android.js:263:17
at /home/priyankpshah/.linuxbrew/lib/node_modules/appium/lib/devices/android/adb.js:630:7
at /home/priyankpshah/.linuxbrew/lib/node_modules/appium/lib/devices/android/adb.js:154:5
at ChildProcess.exithandler (child_process.js:635:7)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Socket.<anonymous> (child_process.js:956:11)
at Socket.EventEmitter.emit (events.js:95:17)
at Pipe.close (net.js:465:12)
info: Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Android devices must be of API level 17 or higher. Please change your device to Selendroid or upgrade Android on your device.)","origValue":"Android devices must be of API level 17 or higher. Please change your device to Selendroid or upgrade Android on your device."},"sessionId":null}
POST /wd/hub/session 500 7269ms - 400b
Tests run: 4, Failures: 1, Errors: 0, Skipped: 3, Time elapsed: 8.198 sec <<< FAILURE! - in TestSuite
setUp(com.ishisystems.enigma.EnigmaLaunchTest) Time elapsed: 8.084 sec <<< FAILURE!
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Android devices must be of API level 17 or higher. Please change your device to Selendroid or upgrade Android on your device.) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 7.41 seconds
Build info: version: '2.41.0', revision: '3192d8a6c4449dc285928ba024779344f5423c58', time: '2014-03-27 11:29:39'
System info: host: 'ishiahm-lt113', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-24-generic', java.version: '1.7.0_55'
Driver info: io.appium.java_client.AppiumDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:76)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:126)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:153)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:41)
at TestUtility.automationInit(TestUtility.java:41)
at LaunchTest.setUp(LaunchTest.java:33)
Please let me know is there any specific changes need to be made to run appium tests on selendroid mode on real devices.
Thanks,
Priyank P Shah
If you are using Appium 1.0 use capability 'automationName' instead of device.
E.G.
capabilities.setCapability("automationName", "Selendroid");
instead of
capabilities.setCapability("device", "Selendroid");
For appium versions less than 1.0 beta , you can continue with 'device' capability.

Resources