My Zoom Code is NOT working

Hi friends,

I am opening Gallery App in my Android Phone and clicking an an Image.
I am actually trying to Zoom IN on the Image with 2 fingers.

Test is getting PASSED. But, Zoom IN Action is NOT happening.

Below is the code:

WebElement ele2=driver.findElement(By.xpath(“(//android.widget.FrameLayout[@resource-id="com.sec.android.gallery3d:id/deco_view_layout"])[1]”));
ele2.click();

	WebElement ele3=driver.findElement(By.xpath("//android.view.ViewGroup[@resource-id=\"com.sec.android.gallery3d:id/top_center_decor_layout\"]"));
	
	Point point=ele3.getLocation();
	Dimension dimension=ele3.getSize();
	
	Point pt2=getCenterOfElement(point, dimension);
	
	PointerInput finger1=new PointerInput(PointerInput.Kind.TOUCH,"finger1");
	PointerInput finger2=new PointerInput(PointerInput.Kind.TOUCH,"finger2");
	
	Sequence sequence1=new Sequence(finger1,1)
			.addAction(finger1.createPointerMove(Duration.ZERO, PointerInput.Origin.viewport(), pt2))
			.addAction(finger1.createPointerDown(PointerInput.MouseButton.LEFT.asArg()))
			.addAction(new Pause(finger1,Duration.ofMillis(200)))
			.addAction(finger1.createPointerMove(Duration.ofMillis(200),PointerInput.Origin.viewport(),pt2.getX()+100,pt2.getY()-100))
			.addAction(finger1.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
	
	Sequence sequence2=new Sequence(finger2,1)
			.addAction(finger2.createPointerMove(Duration.ZERO, PointerInput.Origin.viewport(), pt2))
			.addAction(finger2.createPointerDown(PointerInput.MouseButton.LEFT.asArg()))
			.addAction(new Pause(finger2,Duration.ofMillis(200)))
			.addAction(finger2.createPointerMove(Duration.ofMillis(200), PointerInput.Origin.viewport(), pt2))
			.addAction(finger2.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
	
	driver.perform(Arrays.asList(sequence1,sequence2));
	
	Thread.sleep(3000);

Please help.
Thank you.

Try appium-uiautomator2-driver/docs/android-mobile-gestures.md at master · appium/appium-uiautomator2-driver · GitHub

Thank you so much @mykola-mokhnach

It worked to Zoom IN.
I also tried for Zoom OUT. But failed.

What’s wrong with my above code? When to use it??

For zooming out appium-uiautomator2-driver/docs/android-mobile-gestures.md at master · appium/appium-uiautomator2-driver · GitHub may be used. The original question was only about zooming in though

Yes. Zoom IN worked.
I am trying to Zoom OUT the same Zoomed IN image using the below code:

WebElement ele2=driver.findElement(By.xpath(“(//android.widget.FrameLayout[@resource-id="com.sec.android.gallery3d:id/deco_view_layout"])[1]”));
ele2.click();

WebElement ele3=driver.findElement(By.xpath(“//android.view.ViewGroup[@resource-id="com.sec.android.gallery3d:id/top_center_decor_layout"]”));

((JavascriptExecutor)driver).executeScript(“mobile:pinchOpenGesture”, ImmutableMap.of(“elementId”,((RemoteWebElement)ele3).getId(),“percent”,0.75));
Thread.sleep(3000);
((JavascriptExecutor)driver).executeScript(“mobile:pinchCloseGesture”, ImmutableMap.of(“elementId”,((RemoteWebElement)ele3).getId(),“percent”,1));
Thread.sleep(3000);

Please check.