testautomation - Can´t test game on android screen - java

That i want to do is to "click"/"touch" on a android screen through images because i want to test a game and this game don't have any xpath.
If i cant use image recognition then I at least want to "click" on the screen using coordinates.
But none of these options have worked for me so far.
This far has i come. Now i using Appium Driver.
USING IMAGE RECOGNITION ON DESKTOP:
public void playGame() throws InterruptedException, FindFailed {
Screen screen = new Screen();
String imageLibrary = "src/main/resources/automated-tests/images/";
String skipIntro = imageLibrary + "JackAndTheBeanstalk/skip.PNG";
String skipInfo = imageLibrary + "JackAndTheBeanstalk/continue.PNG";
String bet = imageLibrary + "JackAndTheBeanstalk/increaseStakes.PNG";
String play = imageLibrary + "JackAndTheBeanstalk/play.PNG";
Thread.sleep(10000);
if (screen.exists(new Pattern(skipIntro).similar((float) 0.8)) != null) {
System.out.println("Start playing Jack and the beanstalk");
Thread.sleep(10000);
screen.click(new Pattern(skipIntro).similar((float) 0.8));
screen.click(new Pattern(skipIntro).similar((float) 0.8));
screen.click(new Pattern(skipInfo).similar((float) 0.8));
screen.click(new Pattern(bet).similar((float) 0.8));
screen.click(new Pattern(play).similar((float)0.8));
}
}
This image recognition is working fine on desktop. My goal is to do this but on android! But the click method don´t work on android, only desktop. I have heard that you can use tap, performTouchAction and press instead but i don´t know how to use them.
USING PRESS ON ANDROID:
TouchAction action = new TouchAction(driver);
action.press(10, 0).moveTo(22,33).release().perform();
The problem here is that i don´t know how to get the RIGHT coordinates for android.
Have anyone tried to test automate mobile games/or something similar on android or used image recognition on android or used coordinates on android? Or have you used a different tactic to test automate on android or an other device?
Thanks in advance!

Its unclear what library you are using for image recognition (what do you import to use Screen class?).
But its obvious, that only Appium is not enough to test it.
You can research for Appium + Sikuli API or Appium+OpenCV prototypes.
Several links so far:
Appium+Sikuli
Appium+OpenCV+Akaze

Related

VLCJ - Visualizer has no output

I am trying to get VLCJ to do a visualizer for the mp3 files its playing from a HTTP stream. Video shows up when I stream one. But when audio plays, nothing happens.
This is my code on the cliente side
EmbeddedMediaPlayerComponent empc = new EmbeddedMediaPlayerComponent();
String[] op = {"audio-visual=visual", "effect-list=spectrum", "effect-width=800", "effect-height=80"};
empc.mediaPlayer().media().play("http://127.0.0.1:" + port, op);
There's a lot more code, but nothing directly related to VLCJ.
I can post the server code if you think it's necessary, but I think it's not needed since the media reaches the client perfectly.
So, audio and video work fine, but the visualizer simply doesn't show up.
Any help would be appreciated.
First, check if you have the visualisation plugins installed on your OS distribution.
I am using Linux Mint and those plugins are NOT installed by default when you install VLC.
Do this:
sudo apt install vlc-plugin-visualization
Second, it seems you have to set the visualisation options on the MediaPlayerFactory rather than passing them when you invoke play() on the media player.
For example:
String[] options = new String[] {"--audio-visual=visual", "--effect-list=scope,vuMeter,spectrometer,spectrum"};
factory = new MediaPlayerFactory(options);
mediaPlayer = factory.mediaPlayers().newEmbeddedMediaPlayer();
This example configures the factory before creating a media player from it, you can use any of the media player factory creation methods.
The visualisations scale with the size of the window, I could not get the width and height parameters to do anything.
This is fine for audio.
If you play video, then the video will go the video surface embedded in your application and VLC will open up a new separate window to show the visualisations (probably you don't want that).

appium : webview : selenium : How to automate touchend event on a div?

I want to automate a hybrid app using appium.
My app uses touchend events instead of click events for div
How do I automate this touchend events in appium?
For simple click I can find an element and then perform click by simply doing WebElement.click();
How to fire an event for touchend?
I have spend the last few days looking into this same issue. Eventually what I have found is that the Appium touch actions only work on the NATIVE context. However when you are testing/automating a web application you are in WEBVIEW context. So you have to switch to NATIVE, perform the touch actions, then switch back.
Ok, so that doesn't sound to bad. But they can't let it be that simple. So you can not use your Selenium WebElement as an argument in the Touch Actions. You will either have to re-find it using the NATIVE context, or use the elements location and dimensions to calculate a touch position and use that. However, the X and Y coordinates in the NATIVE context are different than those in the WEBVIEW context. So if you need them to be exact, then you have to translate them.
Well, at least that is where I am now. Perhaps someone else can provide some more or better details.
Here is some sample code for a tap which ignores the pixel translation issue. I have only tested this with iOS, but it should work with Android as well.
private void tapElement(AppiumDriver appiumDriver, WebElement element) {
// Locate center of element
Point location = element.getLocation();
Dimension size = element.getSize();
int tapX = location.getX() + (size.getWidth() / 2);
int tapY = location.getY() + (size.getHeight() / 2);
// Execute tap
String originalContext = appiumDriver.getContext();
appiumDriver.context("NATIVE_APP");
TouchAction action = new TouchAction(appiumDriver);
action.tap(tapX, tapY).perform();
appiumDriver.context(originalContext);
}
Have you looked through documentation?
https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/touch-actions.md

Sharing animated GIF to Twitter makes it static (iOS)

So I'm using LibGDX and RoboVM to convert my Android project to an iOS app. I'm trying to share an animated GIF that the user has just created and saved to their device, here's what I have so far:
public void shareGif(String path)
{
NSData data = new NSData(Gdx.files.absolute(path).readBytes());
NSArray<NSData> nsObjectsToShare = new NSArray<NSData>(data);
ArrayList<String> excludedActivities = new ArrayList<String>();
excludedActivities.add(UIActivityType.Print());
excludedActivities.add(UIActivityType.AddToReadingList());
excludedActivities.add(UIActivityType.PostToVimeo());
excludedActivities.add(UIActivityType.PostToTencentWeibo());
UIActivityViewController share = new UIActivityViewController(nsObjectsToShare, null);
share.setExcludedActivityTypes(excludedActivities);
((IOSApplication)Gdx.app).getUIViewController().presentViewController(share, true, null);
}
Now, this does work. It successfully opens the share window and sends an animated GIF via Mail and Message. Twitter, however, only seems to share a static image (it appears to actually be a JPG when I examine it on my Twitter timeline).
Anyone have any ideas how I can get Twitter to share the ANIMATED version of the GIF? I know I'm not using Objective-C like with typical iOS apps but I'm hoping you can still make out what's going on in the above code.
Was apparently fixed in iOS 8. Just updated my device and it works now. Cool.

Capturing Android screenshot with appium

I currently have something working to capture screenshots on iOS for appium tests using java and junit. Before a test finishes it runs this code to get the last visible thing on the screen before killing the connection
#After
public void tearDown() throws Exception {
if (platform.equals(iOS)) {
captureScreenshot(testName.getMethodName());
}
driver.quit();
}
#SuppressWarnings("Augmenter")
public void captureScreenshot(String testName) {
String imagesLocation = "target/surefire-reports/screenshot/" + platform + "/";
new File(imagesLocation).mkdirs(); // Insure directory is there
String filename = imagesLocation + testName + ".jpg";
try {
Thread.sleep(500);
WebDriver augmentedDriver = new Augmenter().augment(driver);
File scrFile = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(filename), true);
} catch (Exception e) {
System.out.println("Error capturing screen shot of " + testName + " test failure.");
// remove old pic to prevent wrong assumptions
File f = new File(filename);
f.delete(); // don't really care if this doesn't succeed, but would like it to.
}
}
This sorta works for android but lately it has completely killed the running test but this might have to do with the device it is trying to get the snapshot of. Before it would save the file but the image would come up blank or broken.
Anyone know how to get image/screen capturing working on android using appium? Perhaps something with UIAutomator?
You can use this method:
public void screenshot(String path_screenshot) throws IOException{
File srcFile=driver.getScreenshotAs(OutputType.FILE);
String filename=UUID.randomUUID().toString();
File targetFile=new File(path_screenshot + filename +".jpg");
FileUtils.copyFile(srcFile,targetFile);
}
It works fine for me.
I happened to find this via Google search with nearly the same problem - Appium screenshots in the Android emulator come up blank. I'm using both the 'native' method much like you describe above - and - the method within the ATU framework.
WebElement appArea = wd.findElementByXPath("//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]");
ATUReports.add("Main Screen Area Screenshot", LogAs.INFO, new CaptureScreen(appArea));
and both come back blank/transparent. The marginally good news is that the dimension of that blank/transparent image is exactly the size I want to capture - avoiding the status bar where date diffs would cause error on image comparison. That said, it's not much use without actual viewable pixels (for eventual matching of object area grabs to validated baseline images).
I tried setting context to "NATIVE_APP" and nothing seems to help. I am - in a word - vexed. If you've made any progress with this I'd love to read/hear how you got it working. Maybe the next step is to go to the Appium Google Group.
EDIT: I found the core issue in my case - using HAXM acceleration causes the blank screen shots. Note this also affects test run on physical devices if the base device profile set in the test's capabilities is defined with "Host GPU" selected.

How to make a J2ME application run in Background?

I have a written a J2ME application which uses Bluetooth and search a file within the peer mobile and download it. I would like to make my application run in background , whenever I get a call , or message and later resume after few seconds , Has anybody worked on this please share your experience . Is there any way to run a Midlet in background ?
to set a j2me app to the background use the following in your midlet class:
Display.getDisplay (this).setCurrent (null);
to get the screen back use the following:
Display.getDisplay (this).setCurrent (myCanvas);
Where myCanvas is your canvas instantiation
R
p.s. You can still use a thread or timer to do things in the background while your midlet is hidden.
p.s.2: this does not work on all models. (Works on Nokia s60, SonyEricsson, but not on Nokia s40, Samsung and some others.
A device's ability to run an application in the background depends on its ability to multitask. Therefore, more expensive, PDA-type devices are more likely to support background execution than lower-cost devices.
For in background :-
private Display display = Display.getDisplay(this);
private Displayable previousDisplayable;
public void toBack() {
previousDisplayable = display.getCurrent();
display.setCurrent(null);
}
And to come in Fore ground :-
public void toFront() {
display.setCurrent(previousDisplayable);
}
But be aware that it not supports every device.(Works on Nokia s60, SonyEricsson, but not on Nokia s40, Samsung and some others).

Categories