How to tap on a specific point on Xcode simulator
up vote
1
down vote
favorite
I work with swift's UI testing, and I need to be able to tap a specific point on my app. I followed the answers from How to tap on a specific point using Xcode UITests, which worked great for testing on iPad. However, when doing the same on the simulator nothing happens. No errors, the program simply acts like I'm pressing something, but not anything in particular, and the program can't continue executing since the right info isn't there.
Is this possibly a local problem? If not, what can I do to tap at specific coordinates on the simulator?
ios swift xcode xctest xcode-ui-testing
add a comment |
up vote
1
down vote
favorite
I work with swift's UI testing, and I need to be able to tap a specific point on my app. I followed the answers from How to tap on a specific point using Xcode UITests, which worked great for testing on iPad. However, when doing the same on the simulator nothing happens. No errors, the program simply acts like I'm pressing something, but not anything in particular, and the program can't continue executing since the right info isn't there.
Is this possibly a local problem? If not, what can I do to tap at specific coordinates on the simulator?
ios swift xcode xctest xcode-ui-testing
3
(1) I believe the short answer is - you can't. It's a simulator! To "tap" you "click". How do you tap on a specific point on a real device? Short answer? You don't. You record the specific point that was tapped. Same with the simulator. Anything otherwise is illogical. (2) That said, what exactly are you trying to do? Test something? As it is, your question is somewhat vague. If all you wish to do is test some code where a specific point is "tapped" - which is all you've said - then "hard-code" it!
– dfd
Nov 7 at 9:54
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I work with swift's UI testing, and I need to be able to tap a specific point on my app. I followed the answers from How to tap on a specific point using Xcode UITests, which worked great for testing on iPad. However, when doing the same on the simulator nothing happens. No errors, the program simply acts like I'm pressing something, but not anything in particular, and the program can't continue executing since the right info isn't there.
Is this possibly a local problem? If not, what can I do to tap at specific coordinates on the simulator?
ios swift xcode xctest xcode-ui-testing
I work with swift's UI testing, and I need to be able to tap a specific point on my app. I followed the answers from How to tap on a specific point using Xcode UITests, which worked great for testing on iPad. However, when doing the same on the simulator nothing happens. No errors, the program simply acts like I'm pressing something, but not anything in particular, and the program can't continue executing since the right info isn't there.
Is this possibly a local problem? If not, what can I do to tap at specific coordinates on the simulator?
ios swift xcode xctest xcode-ui-testing
ios swift xcode xctest xcode-ui-testing
asked Nov 7 at 9:45
Parakit
61
61
3
(1) I believe the short answer is - you can't. It's a simulator! To "tap" you "click". How do you tap on a specific point on a real device? Short answer? You don't. You record the specific point that was tapped. Same with the simulator. Anything otherwise is illogical. (2) That said, what exactly are you trying to do? Test something? As it is, your question is somewhat vague. If all you wish to do is test some code where a specific point is "tapped" - which is all you've said - then "hard-code" it!
– dfd
Nov 7 at 9:54
add a comment |
3
(1) I believe the short answer is - you can't. It's a simulator! To "tap" you "click". How do you tap on a specific point on a real device? Short answer? You don't. You record the specific point that was tapped. Same with the simulator. Anything otherwise is illogical. (2) That said, what exactly are you trying to do? Test something? As it is, your question is somewhat vague. If all you wish to do is test some code where a specific point is "tapped" - which is all you've said - then "hard-code" it!
– dfd
Nov 7 at 9:54
3
3
(1) I believe the short answer is - you can't. It's a simulator! To "tap" you "click". How do you tap on a specific point on a real device? Short answer? You don't. You record the specific point that was tapped. Same with the simulator. Anything otherwise is illogical. (2) That said, what exactly are you trying to do? Test something? As it is, your question is somewhat vague. If all you wish to do is test some code where a specific point is "tapped" - which is all you've said - then "hard-code" it!
– dfd
Nov 7 at 9:54
(1) I believe the short answer is - you can't. It's a simulator! To "tap" you "click". How do you tap on a specific point on a real device? Short answer? You don't. You record the specific point that was tapped. Same with the simulator. Anything otherwise is illogical. (2) That said, what exactly are you trying to do? Test something? As it is, your question is somewhat vague. If all you wish to do is test some code where a specific point is "tapped" - which is all you've said - then "hard-code" it!
– dfd
Nov 7 at 9:54
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Well, you cannot just tap a screen. You have to tap on something.
Easiest thing to do would be tapping using elements in app and method coordinate(withNormalizedOffset:)
from Apple.
Create a method, thats gonna have input parameters element (you want to tap on) and offset (the point, you want to tap on). Something like this:
func tap(on element: XCUIElement, xOffset: Double, yOffset: Double) {
let coordinate = element.coordinate(withNormalizedOffset: CGVector(dx: xOffset, dy: yOffset))
if element.waitForExistence(5) {
coordinate.tap()
}
}
You can then tap on any element within the tested app by calling this method and giving it the element.
F.e.:
You want to tap on some point in app itself with 0.8
and 0.5
offset:
tap(on: XCUIApplication(), xOffset: 0.8, yOffset: 0.5)
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Well, you cannot just tap a screen. You have to tap on something.
Easiest thing to do would be tapping using elements in app and method coordinate(withNormalizedOffset:)
from Apple.
Create a method, thats gonna have input parameters element (you want to tap on) and offset (the point, you want to tap on). Something like this:
func tap(on element: XCUIElement, xOffset: Double, yOffset: Double) {
let coordinate = element.coordinate(withNormalizedOffset: CGVector(dx: xOffset, dy: yOffset))
if element.waitForExistence(5) {
coordinate.tap()
}
}
You can then tap on any element within the tested app by calling this method and giving it the element.
F.e.:
You want to tap on some point in app itself with 0.8
and 0.5
offset:
tap(on: XCUIApplication(), xOffset: 0.8, yOffset: 0.5)
add a comment |
up vote
0
down vote
Well, you cannot just tap a screen. You have to tap on something.
Easiest thing to do would be tapping using elements in app and method coordinate(withNormalizedOffset:)
from Apple.
Create a method, thats gonna have input parameters element (you want to tap on) and offset (the point, you want to tap on). Something like this:
func tap(on element: XCUIElement, xOffset: Double, yOffset: Double) {
let coordinate = element.coordinate(withNormalizedOffset: CGVector(dx: xOffset, dy: yOffset))
if element.waitForExistence(5) {
coordinate.tap()
}
}
You can then tap on any element within the tested app by calling this method and giving it the element.
F.e.:
You want to tap on some point in app itself with 0.8
and 0.5
offset:
tap(on: XCUIApplication(), xOffset: 0.8, yOffset: 0.5)
add a comment |
up vote
0
down vote
up vote
0
down vote
Well, you cannot just tap a screen. You have to tap on something.
Easiest thing to do would be tapping using elements in app and method coordinate(withNormalizedOffset:)
from Apple.
Create a method, thats gonna have input parameters element (you want to tap on) and offset (the point, you want to tap on). Something like this:
func tap(on element: XCUIElement, xOffset: Double, yOffset: Double) {
let coordinate = element.coordinate(withNormalizedOffset: CGVector(dx: xOffset, dy: yOffset))
if element.waitForExistence(5) {
coordinate.tap()
}
}
You can then tap on any element within the tested app by calling this method and giving it the element.
F.e.:
You want to tap on some point in app itself with 0.8
and 0.5
offset:
tap(on: XCUIApplication(), xOffset: 0.8, yOffset: 0.5)
Well, you cannot just tap a screen. You have to tap on something.
Easiest thing to do would be tapping using elements in app and method coordinate(withNormalizedOffset:)
from Apple.
Create a method, thats gonna have input parameters element (you want to tap on) and offset (the point, you want to tap on). Something like this:
func tap(on element: XCUIElement, xOffset: Double, yOffset: Double) {
let coordinate = element.coordinate(withNormalizedOffset: CGVector(dx: xOffset, dy: yOffset))
if element.waitForExistence(5) {
coordinate.tap()
}
}
You can then tap on any element within the tested app by calling this method and giving it the element.
F.e.:
You want to tap on some point in app itself with 0.8
and 0.5
offset:
tap(on: XCUIApplication(), xOffset: 0.8, yOffset: 0.5)
answered Nov 7 at 11:28
Václav
546
546
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53186926%2fhow-to-tap-on-a-specific-point-on-xcode-simulator%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
(1) I believe the short answer is - you can't. It's a simulator! To "tap" you "click". How do you tap on a specific point on a real device? Short answer? You don't. You record the specific point that was tapped. Same with the simulator. Anything otherwise is illogical. (2) That said, what exactly are you trying to do? Test something? As it is, your question is somewhat vague. If all you wish to do is test some code where a specific point is "tapped" - which is all you've said - then "hard-code" it!
– dfd
Nov 7 at 9:54