theintern / intern

A next-generation code testing stack for JavaScript.
https://theintern.io/
Other
4.36k stars 310 forks source link

Android functional support using javascript .touchScroll, .pressFinger .tap etc.. #641

Open lighterletter opened 8 years ago

lighterletter commented 8 years ago

So I've looked up how to do this for some time, I've been trying to run functional tests on the android emulator using javascript.

I've referenced the Leadfoot docs and other sources but I keep running into walls when it comes to interacting with the device and navigating through listviews etc.. I've used differing methods that Intern does't seem to recognize, When I try to use the .touchScroll method, error log reports along the lines of "mobile: scrollTo" not implemented. When I try to use a combination of pressFinger, moveFinger and releaseFinger the program runs but I see no interaction. I tried the swipe, tap and click functions with no luck either. I'm wondering if I'm just not implementing things right but I can't seem to find examples of how to use the methods properly. I like the simplicity of the set up and I got the environment to run fine as the emulator works, brings up the app and the tests either pass of fail, so I think it's about knowing how to write them.

tldr: Is there a conventional way to scroll, swipe, touch/tap, on android using javacript? I've found little on the docs specified for mobile functional tests, and no examples.

Cheers.

dylans commented 8 years ago

@lighterletter could you please provide an example of the approach that is failing, so we can determine if the issue is documentation or a bug?

Tz3entch commented 7 years ago

I faced exactly the same problems. And still looking for a solution. @dylans here is an example from my side.

I tried to perform a swipe:

return this.remote .pressFinger(360, 10) .moveFinger(360, 1000)

And got an error from Appium:

[debug] [MJSONWP] Calling AppiumDriver.touchDown() with args: [360,10,"f36948ef-bec0-45c6-a374-bc7c51e2e0d0"] [debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:touchDown","params":{"elementId":360,"x":10,"y":"f36948ef-bec0-45c6-a374-bc7c51e2e0d0"}} [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:touchDown","params":{"elementId":360,"x":10,"y":"f36948ef-bec0-45c6-a374-bc7c51e2e0d0"}} [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: touchDown [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":13,"value":"Invalid double: "f36948ef-bec0-45c6-a374-bc7c51e2e0d0""}

afunix commented 7 years ago

The same issue here. I've tried touchDown action (Appium/Selenium: tap_and_hold())

Using Appium with WebUI works since MJSONWP passes only x and y:

2017-04-18 19:38:20:086 - [HTTP] --> POST /wd/hub/session/950ae098-d25f-487d-80b5-c297759a2a7a/touch/down {"y":175,"x":0,"sessionId":"950ae098-d25f-487d-80b5-c297759a2a7a"}
2017-04-18 19:38:20:087 - [MJSONWP] Driver proxy active, passing request on via HTTP proxy
2017-04-18 19:38:20:092 - [debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/950ae098-d25f-487d-80b5-c297759a2a7a/touch/down] to [POST http://127.0.0.1:8000/wd/hub/session/96ce73931daca48c4984de3a074d3965/touch/down] with body: {"y":175,"x":0,"sessionId":"950ae098-d25f-487d-80b5-c297759a2a7a"}

Appium with native Android UI fails since MJSONWP maps arguments incorrectly (x is mapped to elementId, y is mapped to x, y is mapped to sessionId):

2017-04-18 21:44:56:656 - [HTTP] --> POST /wd/hub/session/b0c30673-7ee4-40e9-8f99-1caed2141c43/touch/down {"y":946,"x":180,"sessionId":"b0c30673-7ee4-40e9-8f99-1caed2141c43"}
2017-04-18 21:44:56:657 - [debug] [MJSONWP] Calling AppiumDriver.touchDown() with args: [180,946,"b0c30673-7ee4-40e9-8f99-1caed2141c43"]
2017-04-18 21:44:56:660 - [debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:touchDown","params":{"elementId":180,"x":946,"y":"b0c30673-7ee4-40e9-8f99-1caed2141c43"}}
2017-04-18 21:44:56:670 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:touchDown","params":{"elementId":180,"x":946,"y":"b0c30673-7ee4-40e9-8f99-1caed2141c43"}}
2017-04-18 21:44:56:671 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
2017-04-18 21:44:56:672 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: touchDown
2017-04-18 21:44:56:674 - [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":13,"value":"Invalid double: \"b0c30673-7ee4-40e9-8f99-1caed2141c43\""}
florin0x01 commented 7 years ago

@afunix I managed a fix in Appium for re-mapping x,y coords but it does not do anything. My temp fix in Appium is like this : (however note that I hardcoded elementId but I definitely know it is 7 for my case).

./node_modules/appium-android-bootstrap/lib/bootstrap.js line 108

 return await new Promise ((resolve, reject) => {
  let cmd = Object.assign({cmd: type}, extra);
  try {
            if (cmd['params']['y'] !== undefined) {
                    if (!Number.isInteger(cmd['params']['y'])) {
                            console.log("WARN !!! y is not an integer. Try FIX");
                            cmd['params']['y'] = cmd['params']['x'];
                            cmd['params']['x'] = cmd['params']['elementId'];
                            cmd['params']['elementId'] = '7'; //temp
                    }
     }
    }catch(err) {

    }

I have a list with multiple elements, and I am doing :

     browser.driver.touchActions()
                      .tapAndHold(startLocation)
                      .move(newLocation)
                                                //
                       .release(newLocation)
                       .perform();

where startLocation I take it from item1.getLocation() call and :

      var newLocation = {
                                        x: startX,
                                        y: startY + distance ; // distance is +300 or -300
                                    };

It touches on the second element from the list but it does not scroll down (although I see scroll bar showing up). I tried both with distance negative or positive to test if y coords are down or up, but no effect.

I have also asked a colleague of mine and the following works using the Java bindings:

 touchAction.press(startFromX, startFromY).waitAction(duration).
moveTo(endAtX, endAtY).release();       touchAction.perform();

Please tell me what to do to get scroll working with Protractor. Using latest appium 1.6.5-beta, latest protractor.

Using it on native Android app. I have not tested on iOS but probably same problem,