axemclion / browser-perf

Performance Metrics for Web Browsers
BSD 2-Clause "Simplified" License
936 stars 61 forks source link

Unable to select elements when running on Android device #68

Closed CMatias closed 8 years ago

CMatias commented 8 years ago

Hey, I'm running browser-perf to test an Ionic application with my Android phone. Here's the file I'm running:

var browserPerf = require('browser-perf');

browserPerf(undefined, function(err, res) {
    if (err) {
        console.log('[Error]', err);
    } else {
        console.log('Result ok!');
    }
}, {
    selenium: "localhost:9515",
    browsers: [{
        "browserName": "android",
        "chromeOptions": {
            "androidActivity": "com.ionicframework.tabs246303.MainActivity",
            "androidPackage": "com.ionicframework.tabs246303"
        },
        "loggingPrefs": {
            "performance": "ALL"
        }
    }],
    log: console.log.bind(console),
    actions: [
    function(browser) {
        return browser.elementsByCssSelector("*")
        .then(function(el) {
            console.log(JSON.stringify(el[0], null, 2));
            //el.click();
        })
        .catch(function(err) {
            console.log(err);
        });
}
]
});

I'm selecting all elements and printing the first one and I'm getting something like this:

{
  "ELEMENT": "0.01390435879110652-1"
}

Is this expected behaviour? I tried a number of different selectors for my application and nothing ever hits.

Any help would be appreciated.

CMatias commented 8 years ago

I've been able to solve my problem. Please close this :)

axemclion commented 8 years ago

@CMatias Thanks. It would also help others if you are able to post how you fixed this.

CMatias commented 8 years ago

@axemclion I was expecting the logging on the console to give some information about the object being selected besides the logging of the element value. When I couldn't navigate in my app I thought I was just doing something wrong. Eventually I tried again and was able to do it.

In my specific case I was trying to select an element of an Ionic application with a specific attribute:

<a icon-on="ion-ios-chatboxes" icon-off="ion-ios-chatboxes-outline">Chats</a>

Eventually after browsing the web driver api (maybe this could be linked somewhere in the wiki? 😄 ) I got around to doing just:

actions: [
      function (browser) {
          return browser.elementByCssSelectorOrNull("a[icon-on='ion-ios-chatboxes']");
        .then(function (el) {
          return el.tap();
        });
]

The only relevant thing besides the selector was using tap instead of click.