Appium Unknown server-side error occurred - did not start application - automation

I am trying to test a mobile app in appium but its throwing the following error
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command.
Original error: Cannot start the 'com.example.abc' application.
Original error: 'com.example.abc.ui.splash.SplashActivity' or 'com.example.abc.ui.splash.SplashActivity' never started.
Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting
(WARNING: The server did not provide any stacktrace information)
Follwing are my capabilities setup
#Before
public void setUp() {
File f = new File( "src" );
//App Name
File fs = new File( f, "app-sandbox-debug.apk" );
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability( "deviceName", "Samsung SM-A305F/DS Android 10, API 29" );
capabilities.setCapability( "platformName", "Android" );
capabilities.setCapability( CapabilityType.BROWSER_NAME, "Android" );
capabilities.setCapability("normalizeTagNames","true");
capabilities.setCapability( MobileCapabilityType.APP, fs.getAbsolutePath() );
try {
driver = new AndroidDriver<MobileElement>( new URL( "http://127.0.0.1:4723/wd/hub" ), capabilities );
driver.manage().timeouts().implicitlyWait( 1000, TimeUnit.SECONDS );
System.out.println("Application running");
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
I am unable to find the error cause nor unable to find what's missing at my end.

You can use adb shell dumpsys window windows command to see the launch activity
Launch the app on the device
connect the device to PC/Laptop with adb enabled
In terminal enter the following command adb shell "dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'"
Use the correct activity which can be launched properly

Related

Appium [MAC] [iOS] Bad pp error

I have an error when trying to launch iOS app by desktop Appium server, i managed to run the test on android device successfully, but failed to do the same for the iOS.
The error is:
>
Bad app: >/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/app>ium-ios-driver/build/SafariLauncher/SafariLauncher.app. App paths need to be >absolute, or relative to the appium server install dir, or a URL to compressed >file, or a special app name.
My code is:
// Set desired capabilities.
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "iOS");
// REAL DEVICE
//capabilities.setCapability("deviceName", "iPhone 6s");
capabilities.setCapability("deviceName", "Testing iPhone6s");
capabilities.setCapability("platformVersion", "11.0.1");
capabilities.setCapability("browserName", "Safari");
capabilities.setCapability("orientation", "PORTRAIT");
capabilities.setCapability("udid", "XXXX");
String apkpath="/Users/testing/Desktop/Mohandisi.ipa";
// capabilities.setCapability(MobileCapabilityType.APP, apkpath);
File app=new File(apkpath);
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
// Open the app.
driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
I don't know why appium days that the application is bad although i added the full path!
iOS Settings in Appium Server Screen shot

Connection refused thrown when instantiating a new chrome driver

I have a selenium project with cucumber on my local Jenkins server.
DesiredCapabilities capability = DesiredCapabilities.chrome();
try {
baseUtil.driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
} catch (MalformedURLException e) {
e.printStackTrace();
}
This is how i instantiate my driver. I have the chrome plugin on jenkins as well.
When i try to build, i get this error:
org.openqa.selenium.remote.UnreachableBrowserException: Could not
start a new session. Possible causes are invalid address of the remote
server or browser start-up failure.
....
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to
localhost:4444 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1]
failed: Connection refused
Any idea what am i doing wrong?
If you are running locally try switching to chromedriver
DesiredCapabilities capability = DesiredCapabilities.chrome();
try {
baseUtil.driver = new ChromeDriver(capability));
} catch (MalformedURLException e) { e.printStackTrace(); }
the URL in your previous call was set to point to the hub which you aren't using.
you might need to point it at the local driver location such as:
System.setProperty("webdriver.chrome.driver", "<pathtoyourchromedriver>/chromedriver.exe");

Browsers are not launching from command prompt. Same testng File is working while running through eclipse

I am trying to run my testng test cases from command prompt. I can see browser's instance are created in task manager but it is not launching with given URL. I debugged the code and found it is failing on new ChromeDriver() below line but there is no exception.
On command line, I can see below message :
Starting ChromeDriver 2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a) on port 7108
Only local connections are allowed.
Browser instance will create in task manager but it will not launch and will not go to next line.
This issue is coming from all browsers on same line.
same code worked well in Eclipse.
Using Selenium 2.53.0 and testng 6.9.13 versions
Try this solution:
ChromeDriverService service = null;
try
{
service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File(chromeDriver))
.usingAnyFreePort()
.build();
service.start();
}catch(IOException io){}
if(service.isRunning())
{
DesiredCapabilities cap = DesiredCapabilities.chrome();
try{
driver = new RemoteWebDriver(service.getUrl(), cap);
}catch (SessionNotCreatedException e)
{
}
}

Appium TouchAction/ MultiTouchAction don't work when testing Mobile Web

I'm trying to set up an automated test for a mobile website using Appium 1.2.4, Java-client 2.0.0, Selenium 2.42.2 and a real device (Samsung Galaxy Tab-3).
The problem is that, whenever I'm trying to use Touch Actions (e.g. driver.swipe() or driver.pinch()) I'm getting a Not Yet Implemented … error.
I've tried to improvise by switching the driver context to NATIVE_APP before executing the TouchAction and yet it still didn't work (I get a different error: An unknown server-side error occurred while processing the command).
Would appreciate your kind advice.
Configuration:
Selenium 2.42.2 Java-client 2.0.0 Appium 1.2.4
Device:Galaxy Tab3
OS: Android 4.4.2
Browser: Chrome 38
Thanks and Best Regards,
Daniel.
DesiredCapabilities capability = new DesiredCapabilities();
capability.setCapability("device","ANDROID");
capability.setCapability("app", getValidBrowserName(browser));
capability.setCapability("newCommandTimeout",150);
capability.setCapability("platformName", "Android");
capability.setCapability("deviceName", "GalaxyTab3");
capability.setCapability("platformVersion", "4.4.2");
RemoteWebDriver driver = null;
Platform currentPlatform = desiredCapabilities.getPlatform();
boolean isMobilePlatform = currentPlatform.equals(Platform.ANDROID) || currentPlatform.equals(Platform.MAC);
URL hubURL = new URL(hubHost + "/wd/hub");
try {
driver = isMobilePlatform ? new AndroidDriver(hubURL, desiredCapabilities) : new RemoteWebDriver(hubURL, desiredCapabilities);
driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(scriptTimeout, TimeUnit.SECONDS);
driver.setFileDetector(new LocalFileDetector());
}
catch (Exception e) {
throw new Exception("Failed to create Selenium WebDriver instance on hub: "
+ hubURL.toString() + " with capabilities: "
+ desiredCapabilities.toString() + "\n"
+ e.getMessage());
}
WebElement buttonTest = driver.findElement(By.id("configBtn"));
int buttonX = buttonTest.getLocation().getX();
int buttonY = buttonTest.getLocation().getY();
((AppiumDriver)driver).swipe(buttonX, buttonY, buttonX + 70, buttonY + 70, 1000);

Appium error using real android device

I am getting error in the appium. It is working fine in the emulator but not in the device. Please refer the code and error log below. Could anyone let me know the reason for the error.
//Code///////////////////////////////////////
public void setUp() throws Exception{
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "/app");
File app = new File(appDir, "app.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("browserName", "");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("deviceName", "SCH-I535");
capabilities.setCapability("appPackage", "com.app");
capabilities.setCapability("appActivity", "com.justwink.homepage.HomePageActivity");
capabilities.setCapability("appWaitActivity", "com.app.homepage.HomePageActivity");
try {
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
} catch (Exception e) {
e.printStackTrace();
}
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
}
I fixed it by changing the appActivity name.
Orginally I used hierarchy viewer to find the activity name.
When I used the command
aapt dump badging sample.apk it showed the original activity name.
You may first need to ignore the below code first
*File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "/app");
File app = new File(appDir, "justwink-usa-2.3.2.218221.69.apk");*
match your setup code with this one
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName","sony xperia Z");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("appPackage", "com.android.calculator2");
capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
There is other way you can get the current activity by running following adb command
adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'