Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Provide error if locator is not supported by Selenium Server #1632

Closed
mitchhentges opened this issue Dec 12, 2014 · 5 comments
Closed

Provide error if locator is not supported by Selenium Server #1632

mitchhentges opened this issue Dec 12, 2014 · 5 comments

Comments

@mitchhentges
Copy link

See the issue posted on the Selendroid issue tracker.

I'm running my tests for a hybrid app on an Android tablet. After properly configuring the server's capabilities, I kept running into a StaleElementReferenceException. It turns out that this is because by.model doesn't work with Selendroid.

An error should be provided if a locator is not supported.

To reproduce:

  1. Have a hybrid Android app that uses Angular
  2. Set up configuration
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
    browserName: 'ANDROID',
    targetPlatform: {androidVersion}, //like 'ANDROID19'
    aut: {applicationId}
},

onPrepare: function() {
    var wd = require('wd'),
        protractor = require('protractor'),
        wdBridge = require('wd-bridge')(protractor, wd);
    wdBridge.initFromProtractor(exports.config);
    wdBrowser.context('WEBVIEW');
},
  1. As part of the test, locate an element by.model(...) and then attempt to do sendKeys(...).
@sjelin
Copy link
Contributor

sjelin commented Dec 12, 2014

How are you running protractor with selendroid?

@mitchhentges
Copy link
Author

Oh, that's a fun story, but I'll skip the details :)

  1. Download selendroid and rename it to selendroid.jar for easier typing
  2. Build one of your hybrid apps to make a beautiful little .apk, call it 'app.apk'
  3. Set up your config (see above), where {applicationId} is your application Id (like com.boop.dunks:1234)
  4. Run selendroid. My command-line setup: java -jar selendroid.jar -app app.apk -forceReinstall
    • If you need more verbosity, do: java -jar selendroid.jar -app app.apk -forceReinstall -verbose -logLevel VERBOSE
  5. Run protractor. In my case, node ./node_modules/protractor/bin/protractor config/spec-e2e.js
  6. You remembered to plug in your device, right? ;)

Two things to keep in mind:

  • Selendroid doesn't like by.model. I fixed this with:
//Allows by.model with Webdriver
by.model = function(model) {
    return by.css('[ng-model="' + model + '"]');
};
  • Android opens up the keyboard every time you type. It's like your device wants your tests to fail due to soft keyboards getting in the way. Fortunately:
//Takes care of the Android keyboard when doing "sendKeys"
var nativeSendKeys = protractor.WebElement.prototype.sendKeys;
protractor.WebElement.prototype.sendKeys = function(value) {
    var result = nativeSendKeys.call(this, value);
    browser.actions().sendKeys('\uE100').perform();
    return result;
};

Don't yell at me for overriding your library functions, I like not having to refactor tests. :)

@juliemr
Copy link
Member

juliemr commented Dec 13, 2014

I'm not sure there's a general way to address this issue. by.model is using the webdriver protocol execute script behind the scenes, which is (I believe) supported to selendroid, it's just something about the implementation is failing?

We don't test on selendroid at the moment - I think the larger issue here is that Protractor needs to set up some of our test cases with some mobile strategy (figuring out what's at the forefront now - I believe that appium is only using selendroid for older versions (android 2.3-), so I'm not sure if it will feature in our final decision, but this is still pending.

@mitchhentges
Copy link
Author

Update:
by.model works out of the box with Appium.

If you're considering completely dropping support for Selendroid and focusing on Appium, I would personally recommend against that. In my experience, Selendroid is faster (which is critical on our painfully-slow-running device E2E tests) and Appium has more "hidden" bugs. When testing my app, I've noticed that Appium will fail on clicking certain buttons (the click won't actually go through, but no error is reported) while Selendroid performs the action perfectly.

I understand that supporting two different frameworks for device testing (Appium due to iOS support, Selendroid due to above - hopefully) is far more difficult, but the benefits are far better for us Protractor end users

@juliemr
Copy link
Member

juliemr commented Jan 6, 2015

I think I'm going to close this issue since the original premise isn't something we need to address. However, deciding on better mobile support is definitely on our todos. We've started to clarify the docs, and better support will be coming soon.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants