0

My use case varies for this, but in general i'm trying to collect a bunch of elements and then apply _.map() to each. The problem is that this series of .getAttribute() calls can cause a test that works locally to fail against a remote server like sauce/android.

One example: collecting all <div class='article'><a href='articles/{id}'> on a page and then getting the hrefs. it might look something like this, and this approach will work until i test on a mobile (android) sauce environment. then I get a timeout.

Is it possible this is an issue related to my android environment capabilities? To piling up so many requests? I've tried scaling my test down from using 75 articles to only 45 and i've upped the timeout to 60s and still the mobile test fails. locally with chromedriver is fine, chrome desktop + sauce is fine.

Not my actual test but an approximation of the code i'm talking about:

/// ... return this.remote
.findAllByTagName('div.article a')
    .then(function (articles) {
      var promises = articles.map(function(article) {
        return article.getAttribute('href');
      });
      Promise.all(promises)
      .then(function (hrefs) {
        uniques = _.uniq(hrefs);
        assert(hrefs.length === uniques.length);
      });
    });
erikdstock
  • 1,117
  • 9
  • 16
  • What error are you getting? – jason0x43 Apr 15 '16 at 19:33
  • You should probably try with a more common JavaScript client. This one looks dubious just by its title: "Leadfoot drives browsers insanely fast" – Florent B. Apr 15 '16 at 19:49
  • @jason0x43 - the error i'm getting is just ` Timeout reached on android 4.4 on Linux - infinite scroll works 3 times` This seemed to be the most recent android build sauce offered in their configurator and it is running on an android emulator. i suppose another option would be to avoid the android emulator and simply use chrome/safari with mobile dimensions/capabilities? – erikdstock Apr 16 '16 at 13:51

1 Answers1

1

Since you're seeing a timeout error, I'd suggest continuing to increase the test timeout until the test passes. The mobile testing environments on Sauce are both slower to initialize and slower to operate than the desktop environments, so it's quite possible that a test with many requests is simply very slow.

One way to speed things up would be to use an execute block to gather the references, like:

.then(function (articles) {
    return this.parent.execute(function (articles) {
        return articles.map(function (node) {
            return node.getAttribute('href');
        });
    }, [ articles ]);
})

In the above snippet, the articles element array is passed as an argument to the execute block. The remote WebDriver will deserialize the element references into actual DOM elements that can be operated on in the execute code. This is significantly more efficient than using individual getAttribute requests for each element since only a single request will be made to the remote browser.

jason0x43
  • 3,363
  • 1
  • 16
  • 15
  • Thanks! This perfectly explains everything. – erikdstock Apr 16 '16 at 16:32
  • This actually doesn't work using `execute` in the mobile [selendroid] environment. Specifically I'm getting the Selendroid Exception "Object [object HTMLAnchorElement] has no method 'map'". Works fine locally with chromedriver and remotely with chrome browser. – erikdstock Apr 18 '16 at 18:52
  • Odd. It sounds like the `articles` argument is ending up as a single element on selendroid. So the exact same test code behaves differently on Selendroid vs chromedriver? – jason0x43 Apr 18 '16 at 23:47
  • yep. in the end i switched to running the tests in chromedriver with mobile device mode, which works much more quickly & predictably with much faster capabilities detection. Let me know if i can help with anything else relating to this. – erikdstock Apr 19 '16 at 01:52