I am new to Appium. I did set the configurations and tried to test samsung galaxy tab of android kitkat 4.4.2. The device is not getting identified by the appium. The device is getting identified by the android but not appium.Please do help me to resolve the issue.
I am giving the coding here
#BeforeTest
public void setUp() throws Exception {
/*
* File classpathRoot = new File(System.getProperty("user.dir")); File
* appDir = new File(classpathRoot, "../../../apps/ApiDemos/bin"); File
* app = new File(appDir, "ApiDemos-debug.apk");
*/
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("automationName","Selendroid");
capabilities.setCapability(CapabilityType.VERSION, "4.4.2");
capabilities.setCapability("deviceName", "4d0001f745b350e1");
capabilities.setCapability("platformName","Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME,"chrome");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),
capabilities);
}
#AfterTest
public void tearDown(){
driver.quit();
}
#Test
public void apiDemo() {
driver.get("http://www.facebook.com");
}
and when I am running this,Appium is showing as 0 connected devices.
But the same configured Appium is working fine with emulator of 4.3.
check your cable connection
Are you able to see your device on adb devices directly ?
if your not able see on adb devices , den please enable usb debugging and tap on yes on the prompt that will authorize your device.
check drivers for your device and install
check connecting with debugging other in other mode instead of mtp mode
Related
I am using appium (v1.10.0) for automating iOS native app on macOS(10.13.6) using Xcode 10.1 on a real device (iPhone 6s) of platform version 12.1.3. When I start appium server and start session, the app will open in the device. Once I run the code in eclipse to send the Username to login page of the app, mobile keyboard is not getting opened and hence sendkeys() is not working.
Tried getKeyboard() before sendkeys(). Still the error exists. Below is the code which I tried.
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("device", "iPhone");
cap.setCapability("deviceName", "iPhone 6s");
cap.setCapability("platformVersion", "12.1.3");
cap.setCapability("platformName", "iOS");
cap.setCapability("app","/Users/TP/Desktop/SampleApp.ipa" );
cap.setCapability("udid", "xxxxxxxxxxxxxxxxxxx");
cap.setCapability("automationName", "XCUITest");
cap.setCapability("xcodeOrgId", "xxxxxxxx");
cap.setCapability("xcodeSigningId", "xxxxxxxx");
driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
driver.findElement(By.xpath("//XCUIElementTypeApplication[#name=\"TBI\"]")).click();
driver.getKeyboard().sendKeys("abc");
Mobile keyboard is not getting opened and hence throwing the following error.
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command.
Original error: Error Domain=com.facebook.WebDriverAgent Code=1 "Only actions of 'pointer' type are supported. 'key' is given instead for action with id 'keyboard'" UserInfo={NSLocalizedDescription=Only actions of 'pointer' type are supported. 'key' is given instead for action with id 'keyboard'}
you don't need to use getKeyboard() you can directly send the value to the fields
Send Keys sends a sequence of key strokes to an element.
Can you replace the following two lines
driver.findElement(By.xpath("//XCUIElementTypeApplication[#name=\"TBI\"]")).click();
driver.getKeyboard().sendKeys("abc");
with
MobileElement mobileElement = driver.findElement(By.xpath("//XCUIElementTypeApplication[#name=\"TBI\"]"));
mobileElement.sendKeys("abc");
Try this. Worked for me:
IWebElement currentElement = driver.SwitchTo().ActiveElement();
currentElement.SendKeys("any text");
I am doing some automation with Appium on a iOS mobile app.
I need to:
open the app
do some tasks
open safari
I looked around how to do it but I've been reading that it's impossible due to a limitation in apple's framework, it doesn't allow you to sent commands to more than one app per session.
Does anyone know a way around this? Or if what I read is just not 100% true.
it doesn't allow you to sent commands to more than one app per session
Thats true, but you can run 2 sessions in a single test:
create instance of appium driver with app-based capabilities
do what you need in the app
quit driver
create instance of appium driver with browser-based capabilities
do what you need in the safari
quit driver
In a quick way it may look like:
#Test
public void testBothAppAndSafari() throws MalformedURLException {
URL appiumServerUrl = new URL("<your appium server host>");
DesiredCapabilities appCaps = new DesiredCapabilities();
// put required native app capabilities in appCaps
DesiredCapabilities safariCaps = new DesiredCapabilities();
// put required safari capabilities in safariCaps
IOSDriver driver = new IOSDriver(appiumServerUrl, appCaps);
driver.findElement(<locator for element in native app>).click();
// do whatever you want with mobile app
driver.quit();
driver = new IOSDriver(appiumServerUrl, safariCaps);
driver.findElement(<locator for element in web>).click();
// do whatever you want in safari
driver.quit();
}
You can use following approach,
Created two setup one for app and other for safari.
First launch application and perform task
clear first session
Created again new Appium object for safari ( call second setup )
Perform browser activity
Close safari appium session
You also can follow my approach without quit driver.
Go terminate application. (I've used javascript to run terminateApp cause native method not work for me.)
Find Safari on Home screen and then click on it
Use drive.get to open website as you expected.
In there you can change to WEBVIEW_*** to inspect web element.
Back to native context by NATIVE_APP keyword
Sample code:
System.out.println("Run application");
Map<String, Object> params = new HashMap<>();
params.put("bundleId", "com.example");
boolean terminalApp = (boolean) driver.executeScript("mobile: terminateApp", params);
System.out.println("terminateApp: " + terminateApp);
driver.findElementById("Safari").click();
Set<String> contextNames = appDriver.getContextHandles();
// Change context to WEBVIEW_***
appDriver.context(String.valueOf(contextNames.toArray()[1]));
driver.get("https://www.google.com.vn");
Thread.sleep(20000);
// Do something.
// ...
// If you want to communicate with NATIVE context just change to NATIVE_APP.
appDriver.context("NATIVE_APP");
you can activate system apps via driver.activateApp(BUNDLE_ID);
there is no need to kill the app driver and start browser driver to access browser, just switch between apps.
safari
driver.activateApp("com.apple.mobilesafari");
Here is how I resolved the issue:
driver2.activateApp("com.apple.mobilesafari");
Thread.sleep(5000);
boolean openSafariTab =
driver2.findElements(By.xpath("//XCUIElementTypeButton[#name=\"AddTabButton\"]")).size() > 0;
if (openSafariTab) {
driver2.findElement(By.xpath("//XCUIElementTypeButton[#name=\"AddTabButton\"]")).click();
} else { }
Thread.sleep(3000);
driver2.findElement(By.xpath("//XCUIElementTypeTextField[#name=\"TabBarItemTitle\"]")).click();
Thread.sleep(3000);
driver2.findElement(By.xpath("//XCUIElementTypeOther[#name=\"CapsuleViewController" +
"\"]/XCUIElementTypeOther[3]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]")).sendKeys("https://www.golfbpm.com");
Thread.sleep(3000);
driver2.findElement(By.xpath("//XCUIElementTypeButton[#name=\"Go\"]")).click();
In my initial proof of concept for testing a React Native mobile app using Appium, I noticed that when I load the APK to start my test, I am presented with an Android prompt to "Permit drawing over other apps" as I am creating my AndroidDriver driver. If I move the slider manually, then click the back button, all is good -- the app loads fully, and my test proceeds. However, I don't see how to do this with automation using my Appium script because it looks like the driver instantiation will not complete until the slider is moved.
Most people don't see this in Appium testing as it appears to be specific to React Native in dev mode, as seen here...
Here's my code where I've put in conditional code to click the slider, but I never get there because it waits at the "driver = ..." line:
AndroidDriver driver = null;
#Before
public void setUp() throws Exception {
// < defining capabilities (emulator6p) up here...>
// initialize driver object
try {
driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), emulator6p);
} catch (MalformedURLException e) {
System.out.println(e.getMessage());
}
}
#Test
public void test1() throws Exception {
By BY_slider_permitDrawing = By.id("android:id/switchWidget");
boolean present = (driver.findElements(BY_slider_permitDrawing).size() == 1);
if (present) {
driver.findElement(BY_slider_permitDrawing).click();
driver.navigate().back();
}
WebElement button_begin = driver.findElementByAccessibilityId("button-lets-begin");
button_begin.click();
}
I definitely hear plenty of people say that Appium is a viable solution for React Native testing, and really need to get over this hump.
Thanks in advance for any suggestions!
jph
p.s. In case it wasn't really clear, the test does NOT hang at the "driver = " line if I am not loading the APK from scratch, but I will need to do that for CI testing in the future.
Setting right capabilities helped me to run Appium tests in Debug mode on Android:
{
...
"appWaitPackage": "com.android.settings, com.yourPackage",
"appWaitActivity": "com.android.settings.Settings$AppDrawOverlaySettingsActivity, com.yourPackage.MainActivity",
}
Replace yourPackage with your real package name used in Android app. Some docs here: https://appium.io/docs/en/writing-running-appium/caps/#android-only
I have one application by using which i will block the foreground application. It means when i am clicking any icon in the home screen it should not start. And my application is running in the background and will start when phone will start booting up. So i checked the Auto-run on start up. This is working fine in the simulator but not working in the device after running the cod file. I am running in Blackberry Storm. Here i am putting my code:
public class BlockApplication extends Application
{
int mForegroundProcessId = -1;
public BlockApplication() {
Timer timer = new Timer();
timer.schedule(mCheckForeground, 1000, 1);
}
public static void main(String[] args) {
BlockApplication app = new BlockApplication();
app.enterEventDispatcher();
}
TimerTask mCheckForeground = new TimerTask() {
public void run() {
int id = getForegroungProcessID();
ApplicationManager appMan = ApplicationManager.getApplicationManager();
appMan.requestForegroundForConsole();
KeyEvent inject = new KeyEvent(KeyEvent.KEY_DOWN, Characters.ESCAPE, 0);
inject.post();
};
};
private int getForegroungProcessID()
{
return ApplicationManager.getApplicationManager().getForegroundProcessId();
}
}
Can any one help? What is the problem?
Just an idea - have you setup permissions for your app?
For instance, your app uses KeyEvent injection - something that is potentially dangerous and thus requires an explicit permission from user. In device Options (on my Storm 9530 simulator it is in the 'Options' -> 'Security Options' -> 'Application Permissions' -> select your app -> 'Edit Permissions' menu item) the permissoin for KeyEvent injection is named as "Input Simulation". It is also possible to set up permissions for the app using programmatic way (check ApplicationPermissionsManager class for this, also you can review ApplicationPermissionsDemo project that is included with the JDE).
Note that it is impossible to simulate permission framework on simulator (simulator acts as if all permissions are always set to "Allow"), so to test permissions you need real device.
I'm working on a BlackBerry application that uses a MapView.
At the moment, I'm only showing the MapView, nothing more.
This is a snippet from the code I use for it:
public class MapScreen extends MainScreen {
private MapField map;
public MapScreen() {
super(MainScreen.NO_VERTICAL_SCROLL);
map = new MapField();
map.moveTo(new Coordinates(50.847573,4.713135, 0));
add(map);
//...
}
//...
}
I'm using net.rim.device.api.lbs.MapField because I have to be compatible with OS 5.0
On the simulator, everything's fine and it's working.
But the moment I deploy it on the device, I see a white screen...
The device has an internet connection, but only over Wi-Fi. First I was thinking that that was the problem, but according to "Blackberry services that are available over Wi-Fi connections", it shouldn't be a problem.
So, does anybody know why it's not working on the device, and how I can solve this?
Thanks
You say "the device has an internet connection, but only over Wi-Fi" which makes me beleive you don't have the real device provisioned with a BlackBerry data plan. You need that plan in order to access any BlackBerry services, even over Wi-Fi.
To check for an appropriate connection you can use:
if (CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_BIS_B) {
// Connection will support BlackBerry services
} else if (CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_MDS) {
// Connection will support BlackBerry services if BES allows the connection to BIS servers.
}
A better way of checking for this is to check the ServiceBook entries for LBSConfig or variants thereof.
That allows devices that are no longer on a plan, but were once configured by one with LBS, to function properly.
private static final boolean have_lbs() {
ServiceBook sb = ServiceBook.getSB();
ServiceRecord[] records = sb.getRecords();
int count = records.length;
for (int ii = 0; ii < count; ++ii) {
if (records[ii].getCid().toUpperCase().startsWith("LBS"))
return true;
}
return false;
}