Best WinAppDriver code snippet using Input.MultiTouchScenarios.Pinch
MultiTouchScenarios.cs
Source:MultiTouchScenarios.cs
...72 /// Multiple fingers touch the screen and move closer together.73 /// Manipulation gesture.74 /// </summary>75 [TestMethod, TestCategory("MultiTouch")]76 public void Pinch()77 {78 var touchable = AppSession.FindElementByAccessibilityId("Touchable");79 var coords = touchable.Coordinates.LocationInViewport;80 var startSize = new Size(touchable.Size.Width, touchable.Size.Height);81 var x = coords.X + startSize.Width / 2;82 var y = coords.Y + startSize.Height / 2;83 // The Pinch method assumes a 100px difference between the start/end points.84 // Add half (50) to offset the touch to the center of the element.85 AppSession.Pinch(x, y + 50);86 // AppSession.Pinch(touchable); Not supported yet87 Assert.IsTrue(startSize.Height > touchable.Size.Height);88 Assert.IsTrue(startSize.Width > touchable.Size.Width);89 }90 /// <summary>91 /// Multiple fingers touch the screen and move farther apart.92 /// Manipulation gesture.93 /// AKA Zoom94 /// </summary>95 [TestMethod, TestCategory("MultiTouch")]96 public void Stretch()97 {98 var touchable = AppSession.FindElementByAccessibilityId("Touchable");99 var coords = touchable.Coordinates.LocationInViewport;100 var startSize = new Size(touchable.Size.Width, touchable.Size.Height);...
Pinch
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using OpenQA.Selenium.Appium;7using OpenQA.Selenium.Appium.Android;8using OpenQA.Selenium.Appium.MultiTouch;9using OpenQA.Selenium.Remote;10using OpenQA.Selenium;11{12 {13 static void Main(string[] args)14 {15 DesiredCapabilities capabilities = new DesiredCapabilities();16 capabilities.SetCapability("deviceName", "Nexus 6 API 24");17 capabilities.SetCapability("platformVersion", "7.0");18 capabilities.SetCapability("platformName", "Android");19 capabilities.SetCapability("appPackage", "com.android.calculator2");20 capabilities.SetCapability("appActivity", "com.android.calculator2.Calculator");
Pinch
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Windows.UI.Xaml.Controls;7using Windows.UI.Xaml.Input;8using Windows.UI.Xaml;9using Windows.UI.Xaml.Media;10using Windows.UI;11using Windows.UI.Xaml.Shapes;12using Windows.UI.Xaml.Media.Animation;13using Windows.Foundation;14using Windows.UI.Input;15using Windows.UI.Core;16using Windows.UI.Xaml.Media.Imaging;17using Windows.UI.Xaml.Data;18{19 {20 private Dictionary<uint, Ellipse> _ellipseDictionary = new Dictionary<uint, Ellipse>();21 private Dictionary<uint, TextBlock> _textBlockDictionary = new Dictionary<uint, TextBlock>();22 private Dictionary<uint, Line> _lineDictionary = new Dictionary<uint, Line>();23 private Dictionary<uint, Point> _startPointDictionary = new Dictionary<uint, Point>();24 private Dictionary<uint, Point> _currentPointDictionary = new Dictionary<uint, Point>();25 private Dictionary<uint, double> _startDistanceDictionary = new Dictionary<uint, double>();26 private Dictionary<uint, double> _currentDistanceDictionary = new Dictionary<uint, double>();27 private Dictionary<uint, double> _scaleDictionary = new Dictionary<uint, double>();28 private Dictionary<uint, double> _rotationDictionary = new Dictionary<uint, double>();29 private Dictionary<uint, double> _previousScaleDictionary = new Dictionary<uint, double>();30 private Dictionary<uint, double> _previousRotationDictionary = new Dictionary<uint, double>();31 private Dictionary<uint, double> _scaleDeltaDictionary = new Dictionary<uint, double>();32 private Dictionary<uint, double> _rotationDeltaDictionary = new Dictionary<uint, double>();33 private Dictionary<uint, double> _previousContactDistanceDictionary = new Dictionary<uint, double>();34 private Dictionary<uint, double> _contactDistanceDeltaDictionary = new Dictionary<uint, double>();35 private Dictionary<uint, double> _contactDistanceDictionary = new Dictionary<uint, double>();36 private Dictionary<uint, Point> _previousContactPointDictionary = new Dictionary<uint, Point>();37 private Dictionary<uint, Point> _contactPointDeltaDictionary = new Dictionary<uint, Point>();38 private Dictionary<uint, Point> _contactPointDictionary = new Dictionary<uint, Point>();39 private Dictionary<uint, Point> _previousContactPoint2Dictionary = new Dictionary<uint, Point>();40 private Dictionary<uint, Point> _contactPoint2DeltaDictionary = new Dictionary<uint, Point>();
Pinch
Using AI Code Generation
1using UnityEngine;2using System.Collections;3public class Pinch : MonoBehaviour {4 void Start () {5 Input.multiTouchEnabled = true;6 }7 void Update () {8 if (Input.touchCount == 2) {9 Touch touchZero = Input.GetTouch(0);10 Touch touchOne = Input.GetTouch(1);11 Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;12 Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;13 float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;14 float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;15 float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;16 Camera.main.fieldOfView += deltaMagnitudeDiff * 0.5f;17 Camera.main.fieldOfView = Mathf.Clamp(Camera.main.fieldOfView, 0.1f, 179.9f);18 }19 }20}21using UnityEngine;22using System.Collections;23public class Rotate : MonoBehaviour {24 void Start () {25 Input.multiTouchEnabled = true;26 }27 void Update () {28 if (Input.touchCount == 2) {29 Touch touchZero = Input.GetTouch(0);30 Touch touchOne = Input.GetTouch(1);31 Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;32 Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;33 float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;34 float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;35 float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;36 transform.Rotate(Vector3.up * deltaMagnitudeDiff * 0.5f, Space.World);37 }38 }39}40using UnityEngine;41using System.Collections;42public class Zoom : MonoBehaviour {43 void Start () {44 Input.multiTouchEnabled = true;45 }
Pinch
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Xamarin.Forms;7using Xamarin.Forms.Xaml;8using Xamarin.Essentials;9{10 [XamlCompilation(XamlCompilationOptions.Compile)]11 {12 public Pinch()13 {14 InitializeComponent();15 }16 protected override void OnAppearing()17 {18 base.OnAppearing();19 Input.MultiTouchScenarios.Pinch += MultiTouchScenarios_Pinch;20 }21 private void MultiTouchScenarios_Pinch(object sender, PinchGestureUpdatedEventArgs e)22 {23 if (e.Status == GestureStatus.Running)24 {25 var current = e.Scale;26 var original = e.ScaleOrigin;27 ScaleText.Text = $"Scale: {current:F2}";28 OriginText.Text = $"Origin: {original:F2}";29 }30 }31 protected override void OnDisappearing()32 {33 base.OnDisappearing();34 Input.MultiTouchScenarios.Pinch -= MultiTouchScenarios_Pinch;35 }36 }37}
Pinch
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Xamarin.Forms;7{8 {9 Label label;10 public PinchGesturePage()11 {12 {13 FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),14 };15 var pinch = new PinchGestureRecognizer();16 pinch.PinchUpdated += OnPinchUpdated;17 label.GestureRecognizers.Add(pinch);18 {19 Children = { label }20 };21 }22 void OnPinchUpdated(object sender, PinchGestureUpdatedEventArgs e)23 {24 if (e.Status == GestureStatus.Started)25 {26 label.AnchorX = 0;27 label.AnchorY = 0;28 }29 label.Rotation += e.TotalRotation;30 label.Scale += (e.Scale - 1) * label.Scale;31 }32 }33}34using System;35using System.Collections.Generic;36using System.Linq;37using System.Text;38using System.Threading.Tasks;39using Xamarin.Forms;40{41 {42 Label label;43 public PanGesturePage()44 {45 {46 FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),47 };48 var pan = new PanGestureRecognizer();49 pan.PanUpdated += OnPanUpdated;50 label.GestureRecognizers.Add(pan);51 {52 Children = { label }53 };54 }55 void OnPanUpdated(object sender, PanUpdatedEventArgs e)56 {57 switch (e.StatusType)58 {59 ((Label)sender).Text = "Panning started";60 break;61 ((Label)sender).Text = string.Format("Panning at {0}, {1}", e.TotalX, e.TotalY);62 break;
Pinch
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Windows.UI.Xaml;7using Windows.UI.Xaml.Controls;8using Windows.UI.Xaml.Input;9using Windows.UI.Xaml.Media;10using Windows.UI.Xaml.Navigation;11using Windows.UI.Xaml.Shapes;12using Windows.UI;13using Windows.UI.Input;14using Windows.Foundation;15using Windows.Devices.Input;16{17 {18 public Scenario4()19 {20 this.InitializeComponent();21 }22 private void Canvas_PointerPressed(object sender, PointerRoutedEventArgs e)23 {24 Point pointerLocation = e.GetCurrentPoint(MyCanvas).Position;25 Ellipse newEllipse = new Ellipse();26 newEllipse.Width = 100;27 newEllipse.Height = 100;28 newEllipse.Fill = new SolidColorBrush(Colors.Blue);29 newEllipse.PointerPressed += new PointerEventHandler(newEllipse_PointerPressed);30 MyCanvas.Children.Add(newEllipse);31 Canvas.SetLeft(newEllipse, pointerLocation.X - newEllipse.Width / 2);32 Canvas.SetTop(newEllipse, pointerLocation.Y - newEllipse.Height / 2);33 }34 private void newEllipse_PointerPressed(object sender, PointerRoutedEventArgs e)35 {36 Point pointerLocation = e.GetCurrentPoint(MyCanvas).Position;37 Rectangle newRectangle = new Rectangle();38 newRectangle.Width = 100;39 newRectangle.Height = 100;40 newRectangle.Fill = new SolidColorBrush(Colors.Red);41 newRectangle.PointerPressed += new PointerEventHandler(newRectangle_PointerPressed);42 MyCanvas.Children.Add(newRectangle);43 Canvas.SetLeft(newRectangle, pointerLocation.X - newRectangle.Width / 2);44 Canvas.SetTop(newRectangle, pointerLocation.Y - newRectangle.Height / 2);45 }46 private void newRectangle_PointerPressed(object sender, PointerRoutedEventArgs e)47 {48 Point pointerLocation = e.GetCurrentPoint(MyCanvas).Position;49 Line newLine = new Line();50 newLine.X1 = pointerLocation.X;
Pinch
Using AI Code Generation
1using UnityEngine;2using System.Collections;3{4 void Update()5 {6 if (Input.touchCount == 2)7 {8 Touch touchZero = Input.GetTouch(0);9 Touch touchOne = Input.GetTouch(1);10 Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;11 Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;12 float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;13 float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;14 float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;15 if (camera.isOrthoGraphic)16 {17 camera.orthographicSize += deltaMagnitudeDiff * orthoZoomSpeed;18 camera.orthographicSize = Mathf.Max(camera.orthographicSize, 0.1f);19 }20 {21 camera.fieldOfView += deltaMagnitudeDiff * perspectiveZoomSpeed;22 camera.fieldOfView = Mathf.Clamp(camera.fieldOfView, 0.1f, 179.9f);23 }24 }25 }26}27using UnityEngine;28using System.Collections;29{
Pinch
Using AI Code Generation
1using UnityEngine;2using System.Collections;3public class Pinch : MonoBehaviour {4 private Vector3 touchStart;5 private Vector3 touchEnd;6 private Vector3 touchDelta;7 private float zoomOutMin = 1;8 private float zoomOutMax = 10;9 void Update() {10 {11 Touch touchZero = Input.GetTouch(0);12 Touch touchOne = Input.GetTouch(1);13 Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;14 Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;15 float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;16 float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;17 float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;18 Camera.main.fieldOfView += deltaMagnitudeDiff * 0.5f;19 Camera.main.fieldOfView = Mathf.Clamp(Camera.main.fieldOfView, zoomOutMin, zoomOutMax);20 }21 }22}23using UnityEngine;24using System.Collections;25public class Drag : MonoBehaviour {26 private Vector3 screenPoint;27 private Vector3 offset;28 void OnMouseDown() {29 screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);30 offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));31 }32 void OnMouseDrag() {33 Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);34 Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;35 transform.position = curPosition;36 }37}38using UnityEngine;39using System.Collections;40public class Rotate : MonoBehaviour {41 private Vector3 screenPoint;42 private Vector3 offset;43 void OnMouseDown() {44 screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);45 offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));46 }47 void OnMouseDrag() {48 Vector3 curScreenPoint = new Vector3(Input
Pinch
Using AI Code Generation
1using System;2using Microsoft.Xna.Framework;3using Microsoft.Xna.Framework.Graphics;4using Microsoft.Xna.Framework.Input;5using Microsoft.Xna.Framework.Input.Touch;6{7 {8 GraphicsDeviceManager graphics;9 SpriteBatch spriteBatch;10 SpriteFont font;11 string message;12 Texture2D texture;13 Vector2 position;14 float scale;15 public Game1()16 {17 graphics = new GraphicsDeviceManager(this);18 Content.RootDirectory = "Content";19 graphics.IsFullScreen = true;20 TouchPanel.EnabledGestures = GestureType.Pinch;21 }22 protected override void Initialize()23 {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!