Search code examples
iosseleniumappiumnightwatch.jsxcuitest

Nightwatch.js - Cannot perform touchAction or scroll with Appium (iOS Simulator), looking for solutions


I am running some tests via Nightwatch and Appium, and I have been unable to successfully implement a scroll action using the iOS Simulator. My tests are set up to be able to run on a Chrome, Safari, or Firefox browser, or an iOS Simulator using Safari. The application is built using React, and I am using Javascript. Everything runs smoothly until I have to scroll to a particular element on the screen.

When using the web browsers, all I need to do is send a .click() method on a specific element, and that automatically brings the element into view, but on the iOS Simulator that does not appear to be the case.

This is what I have set up for iOS in my nightwatch.conf.js file. So far any methods that I have seen from my searching online have come up short. The Appium docs have several methods listed, but none of them have been executable, or have failed silently. Does anyone have a possible solution or suggestion about how to properly execute a scroll using this set up? Thanks, and much appreciated

    "ios": {
      "selenium_start_process": false,
      "selenium_port": 4723,
      "selenium_host": "localhost",
      "silent": true,
      "automationName": "XCUITest",
      "desiredCapabilities": {
        "browserName": "safari",
        "platformName": "iOS",
        "platformVersion": "12.2",
        "deviceName": "iPad Pro (9.7 -inch)"
      }
    },

Here is an example of what I have tried to implement (The goal is to move to the button element and click it once it's into view - it's a dropdown)

       browser
            .assert.elementPresent('div[data-mr="quiz-dont-know"]')
            .click('div[data-mr="quiz-dont-know"]')
            .assert.elementPresent('div[data-mr="grey-info"]')
            browser.pause(2000)
            browser.element('css selector', 'div[data-"mr=grey-info"]', function(button) {
                console.log("THIS ELEMENT IS " + button.value.ELEMENT);
                browser.moveTo(button.value.ELEMENT, 10, 10)
                browser.elementIdClick(button.value.ELEMENT);
            })
            .pause(2000)
            .assert.elementPresent('div[data-mr="grey-info-options"]')

Solution

  • I think you want to use ".scrollIntoView()"

    buttons.value.forEach((button, index) => {
        browser.elementIdText(button.ELEMENT, result => {
            if(result.value === 'None') {
                console.log("THIS ELEMENT IS " + button.ELEMENT);
                browser.execute(function(button) {
                    //var elmnt =button // based on user comment
                      var elmnt = document.querySelector([data-mr="grey-info"]') 
                    elmnt.scrollIntoView();
                });
                browser.elementIdClick(button.ELEMENT);
            }
        });
    });