Appium : New session could not be created - appium

I just started exploring Appium, I am trying to launch Amazon app in my nexus 9 and i am getting following error:
"A new session could not be created. (Original error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity"
My app is already installed in nexus devie and i also tried by checking/un-checking "Full reset"/"No reset" options
Here's my code:
File app = new File("D:\\Seleniumdownloads\\apk\\com.amazon.mShop.android.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "Nexus 9");
capabilities.setCapability("platformVersion", "5.1.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.amazon.mShop.android");
capabilities.setCapability("appActivity", "com.amazon.mShop.android.HomeActivity");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
Thread.sleep(10000);
driver.quit();
Please help where i am going wrong..
Thanks in advance.

the problem lies in this line for sure:
capabilities.setCapability("appActivity","com.amazon.mShop.android.HomeActivity");
By looking at some tutorial, I think that the activity should be com.amazon.mShop.home.HomeActivity. Check if it works.
You can download small free APK Info app to see what are the app activities. Sometimes activity that is launched first does not have "Main" or "Home" word in name. For example, recently I tested app that has ".MainActivity", but the activity that was started first was ".LoginActivity" and that was the one that was used by Appium to start the app.
Good luck!

When ever u get New session could not be created error just restart the eclipse once and try again.

Related

How to launch already installed app from iPhone using appium

I am writing an automation script using Java + TestNG + Appium.
In a test scenario, I am trying to launch already installed application on iphone. (Box in this case). Box contains some MS office file which I need to access.
I am not very sure how can I achieve this.
I tried multiple options such as extracting .app file from iTunes and deploying using Appium, but no success.
Can someone please guide me, if this is possible. If yes, how?
Automate a preinstalled app with following scenario.
1.This will only work for applications that are signed with a DEVELOPMENT cert.
2.This will NOT work for applications that are signed with a DISTRIBUTION cert
3.If you have created the app with a developer provisioning profile, and built yourself. Or downloaded it using testFlight, and is signed with a development provisioning profile
4.This is because Apple's Instruments will not allow you to interact with those applications which is live. (Even if you knew the bundleId)
if your app is in development mode please follow these things
1.The bundleId of the app that was installed on the device. Use that as the app capability.
Follow the Appium Real Devices guide (substitute any .ipa/.app reference with the bundleId)
In addition to your regular desiredCapabilities (ex. platformName, platformVersion, deviceName).. these should be your desiredCapabilities:
For preinstalled apps
desiredCaps['app'] = 'yourbindleID'
Device's unique identifier
desiredCaps['udid'] = '1824y983h2849gh2498'
this works for me
HashmMap<String, Object> args = new HashMap<String,Object>();
args.put("bundleId","*YOUR_APP_BUNDLEID*");
driver.executeScript("mobile: launchApp", args);
Refer below code snippet:
cap.setCapability(IOSMobileCapabilityType.APP_NAME, "{appName}");
This capability is the MOST important capability to open the app automatically if the app is already installed on mobile device.
public static IOSDriver<IOSElement> capabilities() throws IOException {
//Configure absolute path of the .ipa file
FileInputStream fis = new FileInputStream(System.getProperty("user.dir")+"//automation.properties");
System.out.println(fis);
Properties prop = new Properties();
prop.load(fis);
File f = new File("src/test/resources");
File fs = new File(f, (String)prop.get("iOSAppName"));
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.PLATFORM_NAME, (String)prop.get("iOSPlatformName"));
cap.setCapability(MobileCapabilityType.UDID, (String)prop.get("iDeviceUDID"));
cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone");
driveriOS = new IOSDriver<IOSElement>(new URL("http://127.0.0.1:4725/wd/hub"), cap);
//Check app is already installed if NOT install app to device automatically
if(driveriOS.isAppInstalled("com.test.app")==false)
{
cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
}
//cap.setCapability(MobileCapabilityType.BROWSER_NAME, (String)prop.get("iOSBrowserType"));
cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, (String)prop.get("iOSPlatformVersion"));
cap.setCapability(IOSMobileCapabilityType.APP_NAME, "{appName}"); //Provide your app name here
cap.setCapability(IOSMobileCapabilityType.BUNDLE_ID, (String)prop.get("updateWDABundleId"));
cap.setCapability("xcodeSigningId", "iPhone Developer");
cap.setCapability("xcodeOrgId", (String)prop.get("xcodeOrgId"));
driveriOS = new IOSDriver<IOSElement>(new URL("http://127.0.0.1:4725/wd/hub"), cap);
driveriOS.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
stepRecorder(Status.INFO, "iOS Driver initiated");
return driveriOS;
}

How to set desired capabilities for launching ios app on real device with appium ( c#)

Hi I am automating the native ios application on ios . I already automated android native app but for launching the appium server on mac from c# code running on windows I need to know how to setup the Desired capabilities for ios platform.
Please find the below peace of code for c# language:
DesiredCapabilities capabilities = new DesiredCapabilities();
TestCapabilities testCapabilities = new TestCapabilities();
testCapabilities.App = "";
testCapabilities.AutoWebView = true;
testCapabilities.AutomationName = "";
testCapabilities.BrowserName = String.Empty; // Leave empty otherwise you test on browsers
testCapabilities.DeviceName = "Needed if testing on IOS on a specific device. This will be the UDID";
testCapabilities.Platform = TestCapabilities.DevicePlatform.IOS; // Or Android
testCapabilities.PlatformVersion = String.Empty; // Not really needed
testCapabilities.AssignAppiumCapabilities(ref capabilities);
driver = new AppiumDriver(testServerAddress, capabilities, INIT_TIMEOUT_SEC);
driver.Manage().Timeouts().ImplicitlyWait(IMPLICIT_TIMEOUT_SEC);
To run Appium test on iOS simulator/real device, Mac hardware is needed and to run test on real device, team id from apple developer account is also needed. More details here.
Connect the iPhone to MacOS via cable or connect both iPhone and Mac computer to same wireless network (WiFi).
C# code for initialising appium iOS driver to run test on real device:
//Initialise driver options
AppiumOptions capabilities = new AppiumOptions();
//Declare capabilities
capabilities.AddAdditionalCapability(MobileCapabilityType.PlatformName, "iOS");
capabilities.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, "13.2"); //put real device iOS version
capabilities.AddAdditionalCapability(MobileCapabilityType.DeviceName, "iPhone X"; //put real device name
capabilities.AddAdditionalCapability(MobileCapabilityType.AutomationName, "XCUITest");
if (appInstalled)
{
//if app is installed and don't want to re-install, use below capability
capabilities.AddAdditionalCapability(IOSMobileCapabilityType.BundleId, "<app-bundle-id>");
}
else
{
//(re)installs app
capabilities.AddAdditionalCapability(IOSMobileCapabilityType.AppName, "<name-of-test-app>");
capabilities.AddAdditionalCapability(MobileCapabilityType.App, "<absolute-path-to-test-app.app>");
}
capabilities.AddAdditionalCapability(MobileCapabilityType.Udid, "<real-device-Udid>");
capabilities.AddAdditionalCapability("xcodeOrgId", "<team-id>");
capabilities.AddAdditionalCapability("xcodeSigningId","iPhone Developer");
//Initialise iOS driver
var driver = new IOSDriver<IMobileElement<AppiumWebElement>>(capabilities);

driver.get() is not working for Android Native browser in Bluestack

Following is the desired capability i am using
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Browser");
capabilities.setCapability("automationName","Appium");
capabilities.setCapability("platformName", "Android");
//capabilities.setCapability("avd","firstavd");
capabilities.setCapability("deviceName", "Android Emulator");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
When i execute the following code - with the above desired cap
driver.navigate().to(url);
driver.findElementByLinkText("Start").click();
It works absolutely fine in other avd. The browser is launched and the url is loaded. But in bluestacks I am getting the following exception:
org.openqa.selenium.NoSuchWindowException: A request to switch to a different window could not be satisfied because the window could not be found.
Appium server: info: [debug] Responding to client with error: {"status":23,"value":{"message":"A request to switch to a different window could not be satisfied because the window could not be found.","origValue":"no such window: window was already closed\n (Session info: webview=)\n (Driver info: chromedriver=2.10.267521,platform=Windows NT 6.1 SP1 x86_64)"},"sessionId":"ba7131af61cad9451da99dd750d61fa8"}
What is wrong. I am not trying to switch any window. Where am i going wrong?
Not sure where exactly the problem is. But look at this http://appium.io/slate/en/v1.3.4/?java#about-appium. Linktext and partiallinktext is not supported by appium.

iOS app gets reset on creation of new appium session

I am performing following steps
Set capabilities and launch ABC app. By providing app path
capabilities.setCapability("app", "/Users/changdeojadhav/Library/Developer/Xcode/DerivedData/ABC/Build/Products/Debug-iphonesimulator/ABC.app");
capabilities.setCapability("bundleId","com.abc.ABC-Demo");
Perform some actions
quit driver by driver.quit()
Set capabilities for Xyz app. And launch XYZ app
Perform some steps
quit driver by driver.quit()
relaunch ABC app as mentioned in step #1.
Expected is "App ABC should retain it's state" but ABC gets reset.
I have launched appium with --no-reset parameter.
Any idea about what I am missing here
Thanks
As far as I can tell, there is currently no solution to reopening the application after going to the home screen without clearing the app from cache.
In past versions of iOS/Appium, the solution was to do:
from appium import webdriver
driver = webdriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps)
driver.close_app()
app = driver.find_element_by_xpath('//UIAApplication/UIAWindow/UIAScrollView/UIAButton[#name="sampleApp"]')
app.click()
However this currently crashes Appium
I will update this question when I log a github issue for it.
The Appium help page says that it only supports multiple app testing in a single test session for Android without Selendroid:
iOS: Support for automating multiple apps in one session: No
Android:Support for automating multiple apps in one session: Yes (but not when using the Selendroid backend)
http://appium.io/slate/en/master/?ruby#toc_27
I'm guessing that is why you are having this issue, and it's most likely an Instruments/XCode issue.
I was able to relaunch the same app without it resetting its state with Appium 1.3.1 running with Xcode 6.1 on a Mac Mini running Mavericks. I did not try launching another app in between launches. I'm driving the automation from C#.
protected AppiumDriver GetAppiumDriver(bool forRestart = false)
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability("appium-version", "1.0");
capabilities.SetCapability("platformName", "iOS");
capabilities.SetCapability("platformVersion", "7.1");
capabilities.SetCapability("deviceName", "iPhone Simulator");
capabilities.SetCapability("app", _appPath);
capabilities.SetCapability("locationServicesEnabled", true);
if (forRestart)
{
capabilities.SetCapability("noReset", true);
}
AppiumDriver driver = new AppiumDriver(_serverUrl), capabilities, new TimeSpan(0, 5, 0));
return driver;
}
public void iOSMobileAppBasicUITest()
{
// Initially Launch the app with the noReset capability at its default value of false to ensure a clean starting point.
_driver = GetAppiumDriver(false);
//Shut down the app.
_driver.Quit();
// Launch the app again, this time with the noReset capability set to true.
_driver = GetAppiumDriver(true);
// Use _driver to do whatever UI automation is desired.
// Optional: Send the app to the background so that iOS does state preservation.
_driver.BackgroundApp(3);
// Close the app.
_driver.CloseApp();
// Alternative: _driver.Quit();
// Launch the app.
_driver.LaunchApp();
// Alternative: _driver = GetAppiumDriver(true);
...
As I known, Appium by default runs in fast reset mode, and it tries to clear app's data when the session ends (as a result of the invocation of quit() in this case). If your want to keep app's data, the option --no-reset should work for you.

Blackberry:web view not work in eclipse simulateor

i have tried this web view code on my blackberry eclipse simulator. but it does not work. what is the reason for that? Is my code wrong or Doesn't it support the running in the simulator ? please someone help me.
public MyScreen()
{ BrowserFieldConfig myBrowserFieldConfig = new BrowserFieldConfig();
myBrowserFieldConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER);
BrowserField browserField = new BrowserField(myBrowserFieldConfig);
add(browserField);
browserField.requestContent("http://www.blackberry.com");
}
}
Right click the project and click Run As then click Run Configuration. Open the Simulator tab then check Launch mobile data System connection Service (MDS-CS). After that, a bat program will run with your simulator, and solve your problem.

Resources