How to swipe horizontally in Appium , As swipe is deprecated in Appium Any replacement for swipe - appium-android

private static void Add_Feed() throws InterruptedException {
TouchActions action = new TouchActions(driver);
action.press(10, 10);
action.move(50, 50);
action.perform();
Thread.sleep(10000);
As swipe is deprecated in Appium, i m using this
But error message displayed as,
java.lang.ClassCastException: io.appium.java_client.android.AndroidDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen

Use this :
new TouchAction(driver).press(startX, startY).waitAction(Duration.ofMillis(duration)).moveTo(endX, endY).release().perform();
Make sure you use the import java.time.Duration; for Duration class

new TouchAction(getDriver())
.press(point(startX, startY))
.waitAction(waitOptions(Duration.ofSeconds(1)))
.moveTo(point(startX, endY)).release().perform();

Related

Unity (Custom Editor) Save Data When Exit Unity

I created a simple Custom Editor that shows how much time I spent on Unity. When the button on it is pressed, it records the start time in a Scriptable Object (It's dirty). When the button is pressed again, it records the end time. If the window is closed before the button is pressed, I use the OnDestroy() method to complete the recording. It works (I also use "ExecuteInEditMode").
Here is the problem: If I close Unity without pressing the button, the OnDestroy() method does not work this time. Is there any way to fix this?
You could add a callback to EditorApplication.quitting
Unity raises this event when the editor application is quitting.
Add an event handler to this event to receive a notification that the application is quitting.
Note that this will not fire if the Editor is forced to quit or if there is a crash. This event is raised when the quitting process cannot be cancelled.
Note btw that you could do it completely automated without a button or a ScriptableObject:
using UnityEngine;
using UnityEditor;
using System.Diagnostics;
public static class LogEditorTime
{
private static bool isLogging;
private static readonly StopWatch sw = new StopWatch ();
static void OnQuit()
{
sw.Stop();
var elapsedTime = sw.Elapsed;
Debug.Log($"Quitting the Editor after {elapsedTime.Hours}h {elapsedTime.Minutes}m {elapsedTime.Seconds}.{elapsedTime.Milliseconds / 10}s");
}
[InitializeOnLoadMethod]
static void OnLoad()
{
if(isLogging) return;
sw.Restart();
EditorApplication.quitting -= OnQuit;
EditorApplication.quitting += OnQuit;
isLogging = true;
}
}

Click on Camera Shutter using UIAutomator

I am writing an Espresso test for my app, and am trying to automate clicking the shutter button after opening of a camera in my app.
I am using Espresso and UIAutomator in the Android Emulator. I managed to dump this UI in UIAutomatorViewer.
I can't figure out why I am unable to click on the shutter button using UIAutomator using this code:
public void clickCameraShutterButton() throws UiObjectNotFoundException
{
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
UiSelector shutterSelector = new UiSelector().resourceId("com.android.camera:id/shutter_button");
UiObject shutterButton = device.findObject(shutterSelector);
shutterButton.click();
}
The camera just sits there, and the shutter button is never clicked. This is the stack trace I'm getting in the Android Studio monitor:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.app.Activity.findViewById(int)' on a null object reference
Any advice would be appreciated.
You can try this code:
device.findObject(new UiSelector().resourceId("com.android.camera:id/shutter_button")).click();
or
device.findObject(new UiSelector().description("Shutter button")).click();
or
device.executeShellCommand("input keyevent 27");
this mean KEYCODE_CAMERA value is 27
or
device.click(x,y);
This worked for me
#Before
public void setUp() {
// Initialize UiDevice instance
final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
mDevice = UiDevice.getInstance(instrumentation);
}
...
/**
* ##Test comment here##
*
* #throws Exception
*/
#Test
public void culebraGeneratedTest_CameraShutter() throws Exception {
mDevice.findObject(By.res("com.android.camera2:id/shutter_button").desc("Shutter").clazz("android.widget.ImageView").text(Pattern.compile("")).pkg("com.android.camera2")).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT);
}
This test finds the shutter and clicks on it.
If you are interested this test was automatically generated using CulebraTester.
Just need to put the UI Automator Viewer "resource-id" value at the place of *
mdevice.findObject(new UiSelector().resourceId("*")).click();

JavaFX: Reacting to Single, Double, and Triple Click

I am trying to configure certain actions in response to number of mouse clicks. It seems to me that the single click and triple click get detected and applied. but the double click does not really work.
I tried to do something like:
if (doubleClick)
else if (tripleClick)
else if (singleClick).
The order of checking did not help either, the action for the double click never gets triggered because that of the single click get triggered first. Any ideas on how to do this?
Assuming you are doing something like
if (mouseEvent.getClickCount()==1)
etc, then it's probably not doing what you think. MouseEvent.getClickCount() just returns the number of clicks that have occurred in a "small" region and in a "small" amount of time. "Small" is (deliberately) not defined.
So a double click is just two clicks. The first returns 1 for getClickCount(), then second returns 2. Similarly, a triple click is three clicks: the first returns 1, the next 2, the third 3. You can test this with a very simple piece of code:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class ClickCountTest extends Application {
#Override
public void start(Stage primaryStage) {
Pane root = new Pane();
root.setOnMouseClicked(event -> System.out.println(event.getClickCount()));
primaryStage.setScene( new Scene(root, 250, 150) );
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
If you click, you'll see the output "1". If you double click, you'll see a "1" followed by a "2".
There's no built-in way to ignore the first click if it's part of a double (or triple) click. The issue, obviously, is that at the time of the first click, there's no way of knowing if another click is going to come without some kind of timing, which gets pretty complicated and would force a delay on responding to any mouse click.
There was some talk a while back about implementing an onClickSequenceFinished type of event, so that instead of listening for mouse click events, you could listen for the click sequence finished event and then query that event to find the number of clicks. In the end, it was decided not to support this as the use case was not considered good UI programming practice.
The reason for that is that it's a pretty bad idea for, say, a double click to exclude the action of a single click. If the user is just too slow with their double click, then they will inadvertently invoke the single click action (twice). So if you are supporting both double click and single click actions, then the actions should be chosen so that it makes sense for the single-click action to be invoked any time the double-click action is invoked. The typical example is a ListView, where double-clicking a list element opens a "details" editor, and single-clicking selects the item. It makes sense for the item being edited to also be selected, so the double-click action implies the single-click action.
Put another way, it's considered a bad design if a double click action is designed to exclude a single click action, and that idiom is not directly supported. You should consider using modifier keys instead of click counts for this kind of distinction.
Update:
If you really want to distinguish events by click count like this (and I really don't recommend it), then you can use something like a PauseTransition to implement the timer. Something like:
import javafx.animation.PauseTransition;
import javafx.application.Application;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.util.Duration;
public class ClickCountTest extends Application {
#Override
public void start(Stage primaryStage) {
// This value may need tuning:
Duration maxTimeBetweenSequentialClicks = Duration.millis(500);
PauseTransition clickTimer = new PauseTransition(maxTimeBetweenSequentialClicks);
final IntegerProperty sequentialClickCount = new SimpleIntegerProperty(0);
clickTimer.setOnFinished(event -> {
int count = sequentialClickCount.get();
if (count == 1) System.out.println("Single click");
if (count == 2) System.out.println("Double click");
if (count == 3) System.out.println("Triple click");
if (count > 3) System.out.println("Multiple click: "+count);
sequentialClickCount.set(0);
});
Pane root = new Pane();
root.setOnMouseClicked(event -> {
sequentialClickCount.set(sequentialClickCount.get()+1);
clickTimer.playFromStart();
});
primaryStage.setScene( new Scene(root, 250, 150) );
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
This is also probably a good use case for Tomas Mikula's ReactFX framework, (also see his blog post).
If you want to detect each of the different click counts, you could use a switch statement.
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
/**
*
* #author jeffreyguenther
*/
public class ListTest extends Application{
#Override
public void start(Stage stage) throws Exception {
Circle c = new Circle();
c.setRadius(100);
c.setCenterX(100);
c.setCenterY(100);
c.setFill(Color.AQUA);
c.setStroke(Color.BLACK);
c.setStrokeWidth(3);
c.setOnMousePressed((e) ->{
switch(e.getClickCount()){
case 1:
System.out.println("One click");
break;
case 2:
System.out.println("Two clicks");
break;
case 3:
System.out.println("Three clicks");
break;
}
});
stage.setScene(new Scene(new Group(c)));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Then as you single, double, and triple click this output is given:
One click
Two clicks
Three clicks
You can use the case statements to determine which counts you want to handle. For example, if you only want to handle the double and triple clicks, you can remove the first case.

How to restrict the minimum size of the window for Eclipse e4

I am making an application based on Eclipse e4 framework. I was wondering how the minimal size of the application window can be controlled. There seems no properties can be defined in e4xmi file for this purpose.
Does anyone know how to do it?
I found a thread in Eclipse Community Forum (http://www.eclipse.org/forums/index.php/t/244875/) saying it can be achieved by creating my own renderer. How can I do that exactly?
Thank you very much :)
Assuming you are using the built-in SWT Renderers, you can also listen for the creation of your E4 MWindow elements and gain access to the underlying SWT Shell. In this example the listener is registered in an AddOn, which you can add to your e4xmi.
import javax.annotation.PostConstruct;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.workbench.UIEvents;
import org.eclipse.swt.widgets.Shell;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
public class MinSizeAddon {
#PostConstruct
public void init(final IEventBroker eventBroker) {
EventHandler handler = new EventHandler() {
#Override
public void handleEvent(Event event) {
if (!UIEvents.isSET(event))
return;
Object objElement = event.getProperty(UIEvents.EventTags.ELEMENT);
if (!(objElement instanceof MWindow))
return;
MWindow windowModel = (MWindow)objElement;
Shell theShell = (Shell)windowModel.getWidget();
if (theShell == null)
return;
theShell.setMinimumSize(400, 300);
}
};
eventBroker.subscribe(UIEvents.UIElement.TOPIC_WIDGET, handler);
}
}
Note, that this will be executed for any MWindow in your application, and there can be more of them (i.e. when an MPart is detached from the MPartStack into a seperate window). If you want to limit the execution to specific MWindows, I recommend to add a tag to the window in the e4xmi and check for this tag before setting the minimum size.
If anyone is still looking to do this in an e4 application and doesn't want to roll their own renderer, you can simply do the following in the post-construct of your part class:
#PostConstruct
public void postConstruct(Composite parent) {
parent.getShell().setMinimumSize(300, 300);
//...
}
The parent Composite passed in by the framework gives you access to the Shell, which lets you set the minimum size. This stops the application from being resized to less than the specified minimum size (in pixels).

implementing jlabel by codes in an automated jFrame in netbeans 6.9

Hi
i'm new with java swing,i try a lot and do a lot of search but in vain.i want to display a jlabel(not by drag n drop but with codes) on an automated jFrame that i have already.well my code for my JLabel is as follows:
private JLabel la=new JLabel("Display label");
codes that i got during my search to dispaly in a jpanel was like follows:
jPanel1.add(jLabel1);
but it does not work.My jPanel1 was built by drag n drop with the name Jpanel1.
i even try this piece of code:
this.add(jLabel1)--
this.getContentPane().add(jLabel1)
but still not working.
Please help me,it must be a simple line of code or i'm missing something somewhere ,please..thank you
This is a simple piece of code obtained from link text
public class HelloWorldFrame extends JFrame {
public static void main(String args[]) {
new HelloWorldFrame();
}
HelloWorldFrame() {
JLabel jlbHelloWorld = new JLabel("Hello World");
add(jlbHelloWorld);
this.setSize(100, 100);
// pack();
setVisible(true);
}
}
What you need to do is to re-set the setVisible property of the parent component to true