how can I perform Swipe Left/right appium 8 - testing

I'm new in using appium for mobile automation, Hope I found a solution for my question, i m trying to perform Swipe Left/right appium 8 using w3c actions.
Any suggestion ? Or video, it can help !
This example for up/down swipe, but I need to swipe left and right
package mdw.sample.android;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.PointerInput;
import org.openqa.selenium.interactions.Sequence;
import org.testng.annotations.Test;
import java.time.Duration;
import java.util.Arrays;
public class Swipe extends TestBase {
UiAutomator2Options options = null;
public AndroidDriver driver=null;
#Test
public void swipe_test(WebElement ele1,WebElement el2) {
try{
int centerX = ele1.getRect().x +ele1.getRect().width/2;
double startY = ele1.getRect().x +ele1.getRect().height/2;
double endY = el2.getRect().x +el2.getRect().height/2;
System.out.println("SWIPE FROM x,y: ("+centerX+","+startY+")");
System.out.println("SWIPE TO x,y: ("+centerX+","+endY+")");
PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH,"finger");
Sequence seqSwipe = new Sequence(finger,1);
seqSwipe.addAction(
finger.createPointerMove(Duration.ofSeconds(0),PointerInput.Origin.viewport(),centerX,(int) startY));
seqSwipe.addAction(finger.createPointerDown(0));
seqSwipe.addAction(
finger.createPointerMove(Duration.ofMillis(500),PointerInput.Origin.viewport(),centerX,(int) endY));
seqSwipe.addAction(finger.createPointerUp(0));
driver.perform(Arrays.asList(seqSwipe));
}catch(Exception oEX){
oEX.printStackTrace();
}
}
}

Related

How can I implement the Android Car API for Andorid Studio to read out my EVs percentage?

I'm currently trying to display the percentage of my Ev Via Android Auto. I can't manage to get CarInfo carInfo = getCarContext().getCarService(CarHardwareManager.class).getCarInfo(); to run. I used this in my automotive build.gradle useLibrary 'android.car' and tried importing many things but that didn't help obviously.
This is my first file:
package com.example.aatest4;
import android.car.Car;
import android.car.CarInfoManager;
import android.content.Intent;
import androidx.annotation.NonNull;
import androidx.car.app.CarAppMetadataHolderService;
import androidx.car.app.CarAppService;
import androidx.car.app.CarContext;
import androidx.car.app.Screen;
import androidx.car.app.Session;
import androidx.car.app.hardware.CarHardwareManager;
import androidx.car.app.hardware.info.CarInfo;
import androidx.car.app.validation.HostValidator;
//import android.content.ServiceConnection;
public class HelloWorldService extends CarAppService {
#NonNull
#Override
public HostValidator createHostValidator() {
return HostValidator.ALLOW_ALL_HOSTS_VALIDATOR;
}
public Session onCreateSession() {
return new Session() {
#NonNull
#Override
public Screen onCreateScreen(#NonNull Intent intent) {
CarInfo carInfo = getCarContext().getCarService(CarHardwareManager.class).getCarInfo();
return new HelloWorldScreen(getCarContext());
}
};
}
}
and this my second:
package com.example.aatest4;
//import android.car.Car;
//import android.car.CarInfoManager;
import androidx.annotation.NonNull;
import androidx.car.app.CarContext;
import androidx.car.app.Screen;
import androidx.car.app.model.Pane;
import androidx.car.app.model.PaneTemplate;
import androidx.car.app.model.Row;
import androidx.car.app.model.Template;
public class HelloWorldScreen extends Screen {
//public HelloWorldScreen() {
public HelloWorldScreen(CarContext carContext) {
super(carContext);
}
#NonNull
#Override
public Template onGetTemplate() {
String akku = String.valueOf(50);
Row row = new Row.Builder().setTitle(akku + "% ").addText(akku + "%").build();
return new PaneTemplate.Builder(new Pane.Builder().addRow(row).build()) .setTitle("Akkuanzeige").build();
//Todo: Center?
}
}

Dynamically updating Polyline points in tornadofx

This question is a bit simplistic, but i couldn't figure it out for myself... What I'm trying to do is using a JavaFX Timeline to update my Polyline points. What I've got until now is as follows:
class MainView : View("Hello TornadoFX") {
var myLine: Polyline by singleAssign()
val myTimeline = timeline {
cycleCount = INDEFINITE
}
override val root = hbox {
myLine = polyline(0.0, 0.0, 100.0, 100.0)
myTimeline.apply {
keyFrames += KeyFrame((1/10.0).seconds, {
myLine.points.forEachIndexed { i, d ->
myLine.points[i] = d + 1
}
println(myLine.points)
})
play()
}
}
}
Although the point list does update the values, as shown when printing them, the change is not reflected in the ui.
Thank you very much for your help!
I have not worked with TornadoFX earlier, so I gave a try with the normal JavaFX. Looks like the the UI is updating when the points are updated. May be the issue is something related to your implementation with TornadoFX.
Please check below the working example.
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Polyline;
import javafx.stage.Stage;
import javafx.util.Duration;
public class PolyLinePointsUpdateDemo extends Application {
#Override
public void start(Stage primaryStage) throws Exception {
Pane root = new Pane();
Scene scene = new Scene(root, 600,600);
primaryStage.setScene(scene);
primaryStage.setTitle("PolyLine Points Update");
primaryStage.show();
Polyline line = new Polyline(0.0, 0.0, 100.0, 100.0);
root.getChildren().add(line);
Timeline timeline = new Timeline();
timeline.getKeyFrames().add(new KeyFrame(Duration.millis(250), e->{
for (int i = 0; i < line.getPoints().size(); i++) {
double d = line.getPoints().get(i);
line.getPoints().set(i, d+1);
}
System.out.println(line.getPoints());
}));
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
}
public static void main(String... a){
Application.launch(a);
}
}
Figured out that the issue was simply using an hbox as the parent layout, instead of a pane, which handles the chidren positioning with absolute coordinates.

how to get ride of deprecated API error in Android Studio

I am working on android studio project for the first time and I am using Broadcast Receiver. Whenever I run my application I get an error that my Broadcast File uses or overrides a deprecated Api. Although my project runs fine but I need to know why I am getting this and how to get rid of this error.My broadcast file is as follows:
package com.example.user.offlinemobilefinder;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
public class AlarmActivity extends AppCompatActivity {
MediaPlayer myMediaPlayer = null;
Button btnStop;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alarm);
Intent intent= getIntent();
final String contact=intent.getStringExtra("contact");
btnStop=findViewById(R.id.stopButton);
myMediaPlayer = MediaPlayer.create(this, R.raw.loudalarm);
final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
audioManager.setStreamVolume(AudioManager.STREAM_ALARM, maxVolume,AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
myMediaPlayer.start();
btnStop.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
myMediaPlayer.stop();
SmsManager smsManager = SmsManager. getDefault();
smsManager.sendTextMessage(contact, null, "Alarm Stoped", null, null);
}
});
}
}
Thanks in advance for help.
AndroidStudio should tell you which method is deprecated. You can then go to the documentation for that method on developer.android.com and there should be a note telling you what to use instead.

Serenity BDD doesn't take screenshots with appium

I have a problem with Serenity BDD using the Screenplay Pattern with appium (I'm using Appium 1.3.1), the project do not generate the Screenshots in each Step, the generated report doesn't show the capture of the step, but in my code i don't have any issue or error in the IDE, this is my code and the capture of the Serenity Report:
import net.serenitybdd.junit.runners.SerenityRunner;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.abilities.BrowseTheWeb;
import net.serenitybdd.screenplay.questions.page.TheWebPage;
import net.thucydides.core.annotations.Issue;
import net.thucydides.core.annotations.Managed;
import net.thucydides.core.annotations.Screenshots;
import net.thucydides.core.annotations.Steps;
import net.thucydides.core.annotations.findby.By;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import com.Otherpackage.tasks.OpenTheApplication;
import com.Otherpackage.tasks.Search;
import com.Otherpackage.tasks.escribeNombre;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import static net.serenitybdd.screenplay.GivenWhenThen.*;
import static net.serenitybdd.screenplay.EventualConsequence.eventually;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasItem;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
#RunWith(SerenityRunner.class)
public class SearchByKeywordStory {
Actor anna = Actor.named("Anna");
#Managed
public static AppiumDriver<WebElement> herBrowser;
#Steps
OpenTheApplication openTheApplication;
#Before
public void annaCanBrowseTheWeb() {
anna.can(BrowseTheWeb.with(herBrowser));
}
#Test
public void search_results_should_show_the_search_term_in_the_title() throws
MalformedURLException, InterruptedException {
String packagename = "com.facebook.katana";
String URL="http://127.0.0.1:4723/wd/hub";
String activityname = "com.facebook.katana.LoginActivity";
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Galaxy S5");
capabilities.setCapability("udid", "284596bb");
capabilities.setCapability("platformVersion", "8.0");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", packagename);
capabilities.setCapability("appActivity", activityname);
capabilities.setCapability("noReset", true);
herBrowser= new AndroidDriver<WebElement>(new URL(URL), capabilities);
herBrowser.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
Thread.sleep(4000);
when(anna).attemptsTo(escribeNombre.yacasi());
}
}
this is the other class "escribeNombre" that contain the Step:
package com.Otherpackage.tasks;
import static net.serenitybdd.screenplay.Tasks.instrumented;
import static org.openqa.selenium.Keys.ENTER;
import org.openqa.selenium.WebElement;
import com.accenture.features.search.SearchByKeywordStory;
import com.accenture.ui.SearchBox;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Task;
import net.serenitybdd.screenplay.actions.Click;
import net.serenitybdd.screenplay.actions.Enter;
import net.thucydides.core.annotations.Step;
public class escribeNombre implements Task {
#Step("Abre la App y busca nombre")
public <T extends Actor> void performAs(T actor) {
WebElement num3 =
SearchByKeywordStory.herBrowser.findElementByClassName
("android.widget.EditText"); //Click a la barra de busqueda.
num3.sendKeys("Daniel Correa \n");
}
public static escribeNombre yacasi() {
return instrumented(escribeNombre.class);
}
}
and this is the Serenity Report, doesn't take any screenshot in the steps
https://i.imgur.com/uKkMGeE.png
anyone can help me with this? in the webpage it have little documentation about using it with appium, http://thucydides.info/docs/serenity-staging/#_running_tests_on_appium
if you have and example with serenity with appium would be great help for me
thanks for reading and sorry for my hardcoded code
Can you try setting serenity.take.screenshots=AFTER_EACH_STEP in serenity.properties file.
You can follow this thread about screenshots are not found in the serenity report.
This gives idea about getting screenshots on reports.

ImageButton is visible only after resize - Libgdx

I have a class called "HudBarView" which takes care of the drawing of the HUD Bar at the top of the screen(Pause button, score, etc).
This class extends the Group class(scene2d).
Another class I have is "HUDManager" which takes care of all the HUD work in the game, including HUD Bar.
Now, currently I have only a pause button in my HUD Bar but the problem is - it is visible only after I resize the screen. Very weird problem.
Here is my HudBarView class:
package views.hud.views;
import views.renderers.HUDManager;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import engine.helpers.AssetsManager;
import engine.helpers.Values;
public class HUDBarView extends Group{
private ImageButton pause;
private HUDManager hud_manager;
private Skin skin;
public HUDBarView(HUDManager hud_manager) {
this.hud_manager = hud_manager;
initiate();
}
private void initiate() {
skin = new Skin(AssetsManager.getAsset(Values.BUTTONS_PACK, TextureAtlas.class));
pause = new ImageButton(skin.getDrawable("pause"));
pause.setSize(Values.Pause_Width, Values.Pause_Height);
pause.setPosition(Values.SCREEN_WIDTH - pause.getWidth(), Values.SCREEN_HEIGHT- pause.getHeight());
addActor(pause);
}
}
Here is my HUDManager class:
package views.renderers;
import views.hud.ParticleEffectsActor;
import views.hud.views.HUDBarView;
import aurelienribon.tweenengine.TweenManager;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import engine.helpers.AssetsManager;
import engine.helpers.UIHelper;
import engine.helpers.Values;
public class HUDManager extends Group {
private Stage stage;
private Skin skin;
private Image text;
private HUDBarView hudView;
public HUDManager(Stage stage) {
this.stage = stage;
initiate();
addActor(hudView);
addActor(particles);
}
public void initiate() {
skin = AssetsManager.getAsset(Values.GAME_SKIN_PACK, Skin.class);
hudView = new HUDBarView(this);
particles = new ParticleEffectsActor();
}
public Stage getStage() {
return stage;
}
}
Here are some photos that will help you understand the problem a little bit better:
Before the screen is resized(it doesn't matter how much the screen is resized):
http://i.gyazo.com/5cc675bde2fcbba7492bba69d4a419c6.png
After the screen is resized:
http://i.gyazo.com/d6814f3e15b903d59dab74b83e95292c.png
P.S Here is my render method inside the Game Screen class(I omitted all the irrelevant parts):
public void render(float delta) {
switch(state) {
case RUN:
// if The asset manager is done loading
if(AssetsManager.update() && !doneLoading) {
doneLoading = true;
hudManager = new HUDManager(stage);
stage.addActor(hudManager);
renderer = new GameRenderer(world, camera, batch);
loadingRenderer.dispose();
} else if(doneLoading) {
renderer.render(delta);
stage.draw();
stage.act(delta);
world.update(delta);
manager.update(delta);
}
// Display loading information
else
loadingRenderer.render(AssetsManager.getProgress()*100);
case PAUSE:
break;
}
}
EDIT: After playing a little bit with the code I found out that if I pause and then resume the game it causes the ImageButton to appear on the screen.