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

312 Views Asked by At

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

1

There are 1 best solutions below

0
Mohammad Monfared On

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.