I have scenario in my project where I need to perform zoom in action Android Mobile web using Appium automation. I have used the following method.
try {
Dimension size = driver.manage().window().getSize();
int x0 = (int) (size.getWidth()*0.5);
int y0 = (int) (size.getHeight()*0.5);
System.out.println(x0+" "+y0);
driver.zoom(100, 500);
reportStep("The Application is zoomed.", "PASS");
} catch (Exception e) {
e.printStackTrace();
reportStep("The Application could not be zoomed.", "FAIL");
}
But this method working fine in Mobile apps and not working in Mobile web.
Are there any specific method or alternate work around to handle the Mobile web zoom?
I am using Appium Java-client version 5.0.4 and Selenium version 3.6.0.
Zoom and Pinch methods are not available in the latest version.
There are not many examples out there without zoom method, but using MultiTouchAction class in conjunction with TouchAction class should work as shown here. Note that using moveTo with WebElement and offset x,y coordinates instead of absolute is advised in that thread.
driver = new AndroidDriver(new URL(nodeURL), capability);
TouchAction touchAction = new TouchAction(driver);
MultiTouchAction multiTouchAction = new MultiTouchAction(driver);
WebElement search = (WebElement) driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().resourceId(\"com.google.android.apps.maps:id/search_omnibox_container\")"));
touchAction .tap(search).perform();
int leftX = search.getLocation().getX();
int rightX = search.getSize().getWidth() + leftX;
int upperY = search.getLocation().getY();
int lowerY = search.getSize().getHeight() + upperY;
a1 = touchAction.press(search,x1,y1).waitAction(2000).moveTo(search,x3,y1).release();
a2 = touchAction.press(search,x2,y1).waitAction(2000).moveTo(search,x4,y1).release();
multiTouchAction.add(a1).add(a2).perform();
Also, look here for appium MultiTouch and here for passing offset x,y co-ordinates to moveTo
Related
I designed a xamarin forms app working practically only on android to implement renderer and other more specific objects, now I have to bring the iOS part to par, the problem arises with the renderers since I have to "translate" the code from android to iOS.
I share below a renderes that I have no idea how to translate a few lines, if you can translate it you would do me a big favor, thanks.
public void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
{
bottomView.ItemIconTintList = default;
int[][] states = new int[][]
{
new int[]{-Attribute.StateChecked}, // unchecked
new int[]{Attribute.StateChecked}, // checked
};
int[] colors = new int[]{
Xamarin.Forms.Color.FromHex("#0D5EB4").ToAndroid(),
Xamarin.Forms.Color.FromHex("#0D5EB4").ToAndroid(),
};
ColorStateList navigationViewColorStateList = new ColorStateList(states, colors);
//bottomView.ItemIconTintList = navigationViewColorStateList;
bottomView.ItemTextColor = navigationViewColorStateList;
This is my class for Android
I was searching for the "right", or the "latest" way to create Tap/Swipe/Drag etc. events using the latest (at this point) Appium Java-client 6.1.0.
I saw different documentations in the Appium site (Tap using TouchActions, Touch using TouchAction), and there is no reference as which should i use (and which is going to be deprecated?).
new TouchAction(driver)
.tap(tapOptions()
.withElement(element(myElement)))
.perform();
new TouchActions(driver)
.singleTap(myElement)
.perform();
It seems that TouchActions is a part of the Selenium project and TouchAction is a part of the Appium, but it does not mean that the Appium is the correct way.
p.s I am using at the moment Chrome/Safari browsers for Android/iOS the testing, but that does not mean that i don't need native apps support for the code.
Thank you for your time
The latest approach to using TouchAction class is to use AndroidTouchAction class instead of TouchAction class as the same is now made generic. That's why you see #SuppressWarnings("rawtypes") being used in the last answer.
This is how you will tap on an element in 6.1.0
For Android:
AndroidTouchAction touch = new AndroidTouchAction (driver);
touch.tap (TapOptions.tapOptions ()
.withElement (ElementOption.element (e)))
.perform ();
For iOS:
IOSTouchAction touch = new IOSTouchAction (driver);
touch.tap (TapOptions.tapOptions ()
.withElement (ElementOption.element (e)))
.perform ();
You want to use TouchAction (Appium).
Below is a section of my code. The first is the general scroll function which takes coordinates as parameters. You generally would not call that function directly, it was meant to be called by other functions, like the scrollDown function I've included below it, that calculates the coordinates and calls the general scroll function.
Hope this helps.
/**
* This method scrolls based upon the passed parameters
* #author Bill Hileman
* #param int startx - the starting x position
* #param int starty - the starting y position
* #param int endx - the ending x position
* #param int endy - the ending y position
*/
#SuppressWarnings("rawtypes")
public void scroll(int startx, int starty, int endx, int endy) {
TouchAction touchAction = new TouchAction(driver);
touchAction.longPress(PointOption.point(startx, starty))
.moveTo(PointOption.point(endx, endy))
.release()
.perform();
}
/**
* This method does a swipe upwards
* #author Bill Hileman
*/
public void scrollDown() {
//The viewing size of the device
Dimension size = driver.manage().window().getSize();
//Starting y location set to 80% of the height (near bottom)
int starty = (int) (size.height * 0.80);
//Ending y location set to 20% of the height (near top)
int endy = (int) (size.height * 0.20);
//x position set to mid-screen horizontally
int startx = (int) size.width / 2;
scroll(startx, starty, startx, endy);
}
I tried below code to move the iOS seek bar. Please help me out to resolve it or am I doing anything wrong here?
Note: I am not getting an error when I run this code but it's not moving seekbar at all.
WebElement seekBar = getDriver().findElement(By.xpath(<elementXpath>));
int startX = seekBar.getLocation().getX();
int endX = seekBar.getSize().getWidth();
int yAxis = seekBar.getLocation().getY();
int end50X = (int) (startX + ((seekBar.getSize().getWidth()) * 0.51));
TouchAction action = new TouchAction(getDriver());
action.press(startX, yAxis).moveTo(end50X, yAxis).release().perform();
I am trying to open the Control Center using appium and the following code:
int halfWidth = driver.manage().window().getSize().width / 2;
int screenHeight = driver.manage().window().getSize().height;
driver.swipe(halfWidth, screenHeight-5, halfWidth, screenHeight-300, 500); // driver is instance of IOSDriver
Instead of opening control centre the app simply draws on the screen upwards from the bottom (using coordinates input). Anyone know how to open Control Center using appium and swipe (or any other way)?
Thanks, Charlie
We can do this. I tried in Appium 1.4.13 and I am able to change settings.
I used below code to change the settings in my iPadAir2.
int height = driver.findElementByClassName("UIAWindow").getSize().getHeight();
int width = driver.findElementByClassName("UIAWindow").getSize().getWidth();
driver.swipe(width-100, height, width-100, height-200, 500);
driver.findElementByAccessibilityId("Wi-Fi").click();
Appium 1.6.5, You can use swipe method, bellow my Python code:
window_size = self.driver.get_window_size() # this returns dictionary
el = self.driver.find_element(*self.configuration.CommonScreen.WEB_VIEW)
action = TouchAction(self.driver)
start_x = window_size["width"] * 0.5
start_y = window_size["height"]
end_x = window_size["width"] * 0.5
end_y = window_size["height"] * 0.5
action.press(el, start_x, start_y).wait(100).move_to(el, end_x, end_y).release().perform()
I am able to toggle the Wifi OFF or turn Airplane mode ON using Appium 1.6.4-beta for iOS
Swipe up from the bottom of the screen
Click continue link
Click the Wifi or Airplane button
Swipe down from middle of screen
But this doesn't appear to be doing anything in the simulator. I have to actually turn off my computers internet connection to disable the internet on the simulator.
#iOSFindBy(xpath = "//XCUIElementTypeSwitch[#name='Wi-Fi']")
private MobileElement WIFI_MODE_BUTTON;
public void disableWifi() {
openToolBarMenu();
//if wifi is on/true then turn it off
if (WIFI_MODE_BUTTON.getAttribute("value") == "true" ) {
Autoscope.tap(WIFI_MODE_BUTTON);
}
closeToolBarMenu();
}
#iOSFindBy(xpath = "//XCUIElementTypeButton[#name='Continue']")
private MobileElement CONTINUE_BUTTON; //continue button on control center
public void openToolBarMenu() {
Autoscope.scrollFromBottomOfScreen();
if (Autoscope.isElementDisplayed(CONTINUE_BUTTON)) {
Autoscope.tap(CONTINUE_BUTTON);
}
}
static public void scrollFromBottomOfScreen() {
TouchAction touchAction = new TouchAction(autoscopeDriver);
int xStartPoint = Math.round(pixelWidth() / 2);
int yStartPoint = pixelHeight();
int yEndPoint = 0 - yStartPoint;
touchAction.press(xStartPoint, yStartPoint).moveTo(0, yEndPoint).release().perform();
}
This code will help in bringing up the Control center, while you are in your app, you can perform all the operations which are available in the Control Center
new TouchAction(DriverConfig.getInstance().getDriver()).press(point(250, 735)).waitAction(waitOptions(Duration.ofSeconds(3))).moveTo(point(250, -460)).release()
.perform();
C#: iOS 13.x
//Opening control center
var size = Driver.Manage().Window.Size;
var height = size.Height;
var width = size.Width;
var touchAction = new TouchAction(Driver);
touchAction.Press(width - 100, height).Wait(1000).MoveTo(width - 100, height - 200).Release().Perform();
//Clicking the WiFi button
Driver.FindElementByAccessibilityId("wifi-button").Click();
//Checking if WiFi enabled or not
var myElement = Driver.FindElementByAccessibilityId("wifi-button");
var result = myElement.GetAttribute("label");
if(!result.Contains("Wi-Fi, Not Connected") && !result.Equals("Wi-Fi"))
{
// WiFi connected
}
else
{
// WiFi Not connected
}
The idea is to simulate the swipe action you use to open Control Center on the corresponding iOS device. My device is iPhone 11 so it is swipe from the top right(to the right of the notch) down. My code is to swipe from position(x,y) (80% width, 0) to (80% width, 50% height)
Dimension size = getScreenSize();
int x = (size.getWidth() / 5) * 4;
int startY = 0;
int endY = size.getHeight() / 2;
new TouchAction(driver).press(PointOption.point(x, startY))
.waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1)))
.moveTo(PointOption.point(x, endY))
.release().perform();
Ok so after a fair amount of investigation it seems to me that this is not possible. If you really need this functionality then I think a tool like eggplant might be appropriate.
I want to implement Xamarin forms image zoom property. I did search the internet for quite some time but I didn't find any relevant documentation, can anyone provide me some information on how to implement it in Xamarin Forms?
Currently there is no zoom property for image. You have to use custom renderer to acheive that.
Try using ScaleTo, Itz similar to zoom but not exactly zoom functionality.. Hope it helps...
var img = new Image {
Source = "foo.png",
Scale = .9
};
var stepper = new Stepper {
Minimum = .1,
Maximum = 1,
Increment = .1,
Value = .9,
};
stepper.ValueChanged += async (object sender, ValueChangedEventArgs e) => {
img.ScaleTo(e.NewValue);
};
I had the same need to implement zoom, click, ... on images on Xamarin Forms.
On the forum i find a plugin that define custom renderers for the 3 platforms that can allow you to get coordinates of click on image and then to implement the zoom you want to do.
Here the website of the plugin : http://www.mrgestures.com/
It costs 10euros for every application you develop. Depending on what you need to implement and how many times you will need it it's not expensive at all.
The issue comes with scale property that its scaled to the center of x and y ,
I've implemented this extension no need for extra renderer.
public static Task<bool> ScaleTo(this VisualElement view, double scale, double anchorX, double anchorY, uint length = 250, Easing easing = null)
{
var tcs = new TaskCompletionSource<bool>();
if (easing == null)
{
easing = Easing.Linear;
}
new Animation(
(v) =>
{
view.Scale = scale;
view.AnchorX = anchorX;
view.AnchorY = anchorY;
}, 0, length
).Commit(view, nameof(view), 16, length, easing, finished: (f, a) => tcs.SetResult(a));
return tcs.Task;
}
You can implement pinch to zoom by using a pinch gesture recognizer.
Here is the documentation on pinch to zoom
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/gestures/pinch
At the same time if you want to add pan, you can combine the above code with
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/gestures/pan
Then you would have a pretty good full screen image viewer in Xamarin.Forms
You can use this library, just install on your .netstandard project and that's it!
You can then use Rg.Plugin.Popup and add the image dynamically by providing the link
xmlns:pinch="clr-namespace:Xamarin.Forms.PinchZoomImage;assembly=Xamarin.Forms.PinchZoomImage"
<pinch:PinchZoom.Content>
<Image Source="xxamarin.jpg" />
</pinch:PinchZoom.Content>