Appium::TouchAction.new.tap doesn't work correctly - ios

And(/^I click OK button in popup$/) do
#Appium::TouchAction.new.tap(x:0.64, y:0.57, count: 1).perform
Appium::TouchAction.new.tap(x: 270, y: 506,count: 1).perform
end
And(/^I click Allow button in popup$/) do
#Appium::TouchAction.new.tap(x:0.64, y:0.57, count: 1).perform
Appium::TouchAction.new.tap(x: 270, y: 506,count: 1).perform
end
Given the next code, I work with Appium 1.9.1, Ruby 2.3.7 and Cucumber to automate iOS app, if I'm passing relative coordinates (percentage) - then appium doesn't perform any taps, but, if I comment out lines with absolute coordinates and comment lines with relative coordinates - all taps will work. The strangest thing is that if I use relative coordinates in 1st line and absolute coordinates in second line - it will perform first tap, but won't perform second.
My goal is to use relative coordinates everywhere, so tests will be usable on devices with any screen resolution, please advice, if there are any known solutions to use relative coordinates (or if I'm doing smth wrong)

After going through your code snippet, I assume you are dealing with alert pop-up in iOS device.
In iOS, with Appium Java client, I can deal with pop-up using traditional driver.switchTo().alert();.
Here driver refers to IOSDriver.
I'm sure there must be equivalent to this in Ruby as well.
Try using Alert class to accept the alerts instead of tapping on the coordinates.

Related

Swift / React Native How to know split view / slide over app's position relative to the whole screen?

I'm making a react-native based app, and I can partially use Swift code by react-native's NativeModule feature.
My app will be used as Split view / Slide over mode in iPad, and I want to know if my app is in the left-side, right-side, or Slide-over.
I could get width and height, also origin (CGPoint) by this code.
let window = UIApplication.shared.windows.first
// Then getting X, Y like this...
window.frame.origin.x
Now my app has only one webview, made by react-native-webview.
So I guess, since the webview is the whole content of the app, and it fills app 100%, so it always returns app.
I want to know, not in webView's perspective, but in app's perpective, the POSITION relative to the screen.
For example, if my iPad width is 1400, and if my app is on the half right side, x should be 700.
And if it is on left side, it should be 0.
I really struggled this, but couldn't find any solution.
FYI, I drawed a diagram for this question.
As I wrote on the above, I tried UIApplication.shared.windows.first.frame.
But it only show the CGPoint of webview, not app relative to the screen.
There is no API for getting 'X' or 'LEFT' in react-native-dimension too.
onLayout also not helpful.

ARKit - Extend the reach of "hitTest"

I want to perform a hit testing from a point on the screen to a Cube in a 3D world. I've been using hitTest from ARKit. It works when I'm standing close to the cube, but when I start moving backwards, it stops working. I'm assuming this is because it's locked to the camera's zRange.
I've tried to set the clipToZRange option to false, like so:
let hits = self.sceneView.hitTest(loc, options: [SCNHitTestOption.clipToZRange: false])`
but it doesn't seem to have any effect.
Am I not setting the option right, or is this a bug?
I am using the latest Xcode and iOS betas.
Turns out the showFeaturePoints debug option from ARKit interferes with hitTest...

How to scroll the page in Appium + Python

I create tests using Appium+Python to test IOs app.
I want to scroll the page.
Here is the code
def scroll_page(self):
action = TouchAction(self)
action.press(BrowsePageElements.firs_element_to_scroll(self)).
move_to(BrowsePageElements.second_element_to_scroll(self)).perform()
When I'm trying to run this function, I get an error
error screenshot
Could you help me to find out, how to fix this error?
Appium Python has a native scroll function. It works for both Android and iOS.
driver.scroll(origin_el, destination_el, duration=None), where duration is an optional argument. This function scrolls origin_el to the location of destination_el.
Link to scroll source code
The Appium documentation is rather spotty and needs updating. However, the source code is documented well enough to understand and learn the program.
This currently works for me:
...
SCROLL_DUR_MS = 3000
...
window_size = self.driver.get_window_size()
self.scroll_y_top = window_size['height'] * 0.2
self.scroll_y_bottom = window_size['height'] * 0.8
self.scroll_x = window_size['width'] * 0.5
...
def scroll_up(self):
self._y_scroll(self.scroll_y_top, self.scroll_y_bottom)
def scroll_down(self):
self._y_scroll(self.scroll_y_bottom, self.scroll_y_top)
def _y_scroll(self, y_start, y_end):
actions = TouchAction(self.driver)
actions.long_press(None, self.scroll_x, y_start, SCROLL_DUR_MS)
actions.move_to(None, self.scroll_x, y_end)
actions.perform()
It scrolls slowly over 3s because I want it to be controlled, but you could shorten SCROLL_DUR_MS (the duration of the scroll action in milliseconds) if you want something more zoomy. I also went away from using elements as the start and/or end points because I wanted something general that would work with any screen content.
For scroll_y_top and scroll_y_bottom I picked 20% in from the top and bottom of the screen just to make sure I wasn't hitting anything at the borders (like the navigation bar at the top of iOS Preferences or an info bar at the bottom of the app I was working in). I also ran into a "bug" where it wasn't scrolling when I left scroll_x as 0, but it turns out that it wasn't registering the left edge as inside the scrolling area for the app I was working in.
Hope this helps.
In the past when i've run into issues scrolling for one reason or another, I've simply swiped using coordinates to scroll down the page.
self.driver.swipe(100, 700, 100, 150)

Implement Camera in Custom page in Cordova iOS

In Cordova and Meteor.js, is it possible to implement the Camera function into our own custom page, getting it to look similar to the following in iOS:
I don't know about Meteor.js but I can tell you about cordova-plugins.
Yes you can do it by using mbppower/CordovaCameraPreview plugin that allows camera interaction from HTML code. To create your custom camera what you should do is, start camera on your HTML page. You have to draw rectangle for "Camera Preview Box" with required height-width dimensions and starting point(x,y) as parameters in below code snippet.You can also make it Tap enabled and Drag-able.
cordova.plugins.camerapreview.startCamera({x: 100, y: 100, width: 200, height:200}, "front", tapEnabled, dragEnabled, toBack);
Now its on your HTML page only, so you can add Capture button, Browse picture button, Flash or anything you want. It will be like your custom camera only. A big thanks to its author, he has done a great job..
Added more stuff:
you can also use donaldp24/CanvasCameraPlugin Plugin for your application, its supported in both android and iOS. For iOS its working, but in android isn't working properly for me.
UPDATE:10th Oct 2017 It used to work well during that time but, donaldp24/CanvasCamera is no longer maintained and currently fails build with the latest Cordova version.

How to click/tap on content drawn using core graphics in appium for iOS

I am new to Appium and use it for iOS native app automation.
Appium version : 1.2.0
Webdriver : Selenium
Testing framework : JUnit
Programming language : Java
I have an iOS application where the contents are drawn using Core Graphics. I need to click/tap on certain content(word) using Appium with the co-ordinates specified.
My question is, how can I tap on the content drawn using CG?
For example, how can I click on "Start" using Appium using co-ordinates where the origin is x=0, y=102 and size is height=305, width=320.
The content is present within this and must be scrolled for other contents.
I tried with .tap, .press of TouchAction(). The test case passed but it has not clicked.
Please help me solve this.
Thanks in advance.
This is the general gist of what you need to do to tap something. (My attempt at a Java translation of my python code)
WebElement application = driver.findElement(By.xpath("//UIAApplication[1]"))
Action action = TouchAction(driver)
action.tap(application, x, y, 1).perform()
When testing drawing/tapping code, I like to point it at a sample drawing app like this one and that lets me see exactly what's going on.

Resources