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?










share|improve this question


















  • 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















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?










share|improve this question


















  • 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













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?










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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














  • 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












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)






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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

























    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)






    share|improve this answer

























      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)






      share|improve this answer























        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)






        share|improve this answer












        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)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 7 at 11:28









        Václav

        546




        546






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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





















































            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







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()