Android Web Driver - cannot simulate touch actions - android

I've downloaded the android_webdriver_library.jar via the Eclipse ADT SDK Manager under Extras/Google Web Driver and reference it in my eclipse project.
How do I simulate a touch action like tapping a button for example? I cannot find the TouchActions class which according to the documentation (http://selenium.googlecode.com/svn/trunk/docs/api/java/index.html) is supposed to be the factory class for touch actions.

i don't know Java, but I got this working in Python.
What does your code look like? Can you try the Tutorial , as well as the example below and modify it to use touch?
Example from tutorial below:
WebElement toFlick = driver.findElement(By.id("image"));
// 400 pixels left at normal speed
Action flick = getBuilder(driver).flick(toFlick, 0, -400, FlickAction.SPEED_NORMAL)
.build();
flick.perform();
WebElement secondImage = driver.findElement(“secondImage”);
assertTrue(secondImage.isDisplayed());

Related

Unable to drag and drop in Appium Android

I'm using Appium 1.6.5 and Windows 10.
Using the demo app by Appium (ApiDemos-debug.apk), I am trying to drag and drop dots.
View app screen:
This is my current code:
TouchAction actions = new TouchAction(driver);
actions.tap((AndroidElement)driver.findElementByAndroidUIAutomator("text(\"Views\")")).perform();
driver.findElementByAndroidUIAutomator("text(\"Drag and Drop\")").click();
AndroidElement element1 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_1"));
AndroidElement element2 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_2"));
actions.longPress(element1).waitAction(3000).perform().release();
This error prints when test is run:
org.openqa.selenium.NoSuchElementException: An element could not be
located on the page using the given search parameters. (WARNING: The
server did not provide any stacktrace information)
Any combination of longPress() calls results in this error. I can click & tap, that's fine. When it comes to using other TouchAction methods, then errors occur.
Any idea how to resolve this? Need to know if it's my setup that's wrong or TouchAction method has issues.
You need to long press on that element and drag it to other element.Currently, you're only pressing long and performing the action without releasing it.
Try this:
actions.longPress(element1).moveTo(element2).release().perform();

How to take off a PX4 autopilot using mavlink message?

I follow the following link's sample code
http://android.dronekit.io/first_app.html
and when I set API VehicleApi.getApi(this.drone).arm(true);
vehicleState.isFlying() automatically becomes true.
Can anybody tell me what this problem is?
What I need is:
1. take off, land
I read from some website that the dronekit-android does not support the mode changing. If so, how should I send the mavlink message to take off and land?
So far, I can sucessfully send the mavlink message to the PX4 board.
Thanks for replying.
Thank you for replying.
BR
SeanH
If you trace though some of the code in dronekit-android, you can see that isFlying is set here with the code below.
boolean isFlying = systemStatus == MAV_STATE.MAV_STATE_ACTIVE || ...;
MAV_STATE_ACTIVE, defined here states
System is active and might be already airborne. Motors are engaged.
So isFlying doesn't mean it's airborne but just that the motors are turned on. That occurs when you call VehicleApi.getApi(this.drone).arm(true); because you are literally arming the vehicle at that point.
For takeoff, you want to use the ControlApi. ControlApi.getApi(drone).takeOff(desired_altitude, listener) and for land you need to use VehicleApi.getApi(drone).setVehicleMode(VehicleMode.COPTER_LAND, listener)
The sample code you're looking at is very old. I suggest you follow the sample app from github.
I have not tried android-dronekit before and I noticed that the src folder have not been updated for more than two years on github.
I advice you to use python-dronekit because there is a powerful library called pymavlink in python and used in python-dronekit. You can build hyper application if you want but first try to takeoff and land in python.

Taking Screenshots Using Qt C++ on Android

thanks for checking my question out!
I'm currently working on a project using Qt C++, which is designed to be multi-platform. I'm a bit of a newcoming to it, so I've been asked to set up the ability to take screenshots from within the menu structure, and I'm having issues with the Android version of the companion app.
As a quick overview, it's a bit of software that send the content of a host PC's screen to our app, and I've been able to take screenshots on the Windows version just fine, using QScreen and QPixmap, like so:
overlaywindow.cpp
{
QPixmap screenSnapData = screenGrab->currentBackground();
}
screenGrabber.cpp
{
QScreen *screen = QGuiApplication::primaryScreen();
return screen->grabWindow( QApplication::desktop()->winId() );
}
Unfortunately, Android seems to reject QScreen, and with most suggestions from past Google searches suggesting the now-deprecated QPixmap::grab(), I've gotten a little stuck.
What luck I have had is within the code for the menu itself, and QWidget, but that isn't without issue, of course!
QFile doubleCheckFile("/storage/emulated/0/Pictures/Testing/checking.png");
doubleCheckFile.open(QIODevice::ReadWrite);
QPixmap checkingPixmap = QWidget::grab();
checkingPixmap.save(&doubleCheckFile);
doubleCheckFile.close();
This code does take a screenshot, but only of the button strip currently implemented, and not for the whole screen. I've also taken a 'screenshot' of just a white box with the screen's dimensions by using:
QDesktopWidget dw;
QWidget *screen=dw.screen();
QPixmap checkingPixmap = screen->grab();
Would anyone know of whether there was an alternative to using QScreen to take a screenshot in Android, or whether there's a specific way to get it working as compared to Windows? Or would QWidget be the right track? Any help's greatly appreciated!
as i can read in Qt doc : In your screenGrabber.cpp :
QScreen *screen = QGuiApplication::primaryScreen();
return screen->grabWindow( QApplication::desktop()->winId() );
replace with :
QScreen *screen = QGuiApplication::primaryScreen();
return screen->grabWindow( 0 ); // as 0 is the id of main screen
If you want to take a screenshot of your own widget, you can use the method QWidget::render (Qt Doc):
QPixmap pixmap(widget->size());
widget->render(&pixmap);
If you want to take a screenshot of another app/widget than your app, you should use the Android API...

How to create a location input bar in ios/Android?

Looking for some clue to build a location input bar just above keyboard and user can tap location icon to input a location, similar as what Fb/twitter has on their mobile apps when click new post/tweet.
Are there any existing library that support this? Should I create a customized keyboard with this bar?
Many thanks for any clues!
Assuming you are simply looking to create the bar above the keyboard, inputAccessoryView, a property of both UITextFields and UITextViews, is what you are looking for. This allows you to add a UIToolbar to the top of the keyboard similar to what both Twitter and Facebook do.
You can read further in the Apple documentation here.
A simple implementation of this is as follows -
UIToolbar *locationToolbar = [[UIToolbar alloc] init];
locationToolbar.frame = CGRectMake(320, 384, 320, 53);
// Add location button to UIToolbar as desired
self.textField.inputAccessoryView = locationToolbar;
If you are looking to create a map to select the location from, MKMapView would be a good place to start.

HERE Maps on Android freezes browser, breaking ajax requests on iOS

I am using HERE Maps to show a map letting users choose a location of interest. It works fine on desktop, but on mobile devices I am experiencing some problems.
On Android devices, if I create a map using
var map = new nokia.maps.map.Display(document.getElementById("map"), {
// Initial center and zoom level of the map
center: startCoordinate,
zoomLevel: 5,
components: [
new nokia.maps.map.component.Behavior(),
new nokia.maps.map.component.ZoomBar(),
new nokia.maps.map.component.ScaleBar()
]
}
);
the browser freezes after a few seconds. You can test this at karmap.com; try to scroll down to the very bottom to find the map. If I remove the code shown above the browser won't freeze anymore (but I won't get the map, of course).
Another problem occurs, when loading the page on iOS devices; in the form at the bottom you can find an input box named "Place of Birth". After typing 3 letters or more I start an ajax request to find suitable city names. This doesn't work if I use the following code (right under the code snippet to create the map):
map.removeComponent(map.getComponentById("zoom.MouseWheel"));
map.set("baseMapType", map.SATELLITE); // Activates satellite imagery on the display
If I comment that code out, the ajax calls work fine.
For me, that is some strange side effect! Does anyone have a clue what is going on?
Thanks for any help or advice!

Categories

Resources