I've tried the troubleshooting steps listed at http://appium.io/slate/en/1.5.3/?javascript#ios, but with no luck.
I run my test with:
$ mocha sample.js
This successfully installs the app on the device and opens it, but the test fails at the first step every time with this error:
Error: [elementByName("Username")] Not JSON response
at exports.newError (node_modules/wd/lib/utils.js:145:13)
at node_modules/wd/lib/callbacks.js:59:17
at node_modules/wd/lib/webdriver.js:179:5
at Request._callback (node_modules/wd/lib/http-utils.js:88:7)
at Request.self.callback (node_modules/request/request.js:187:22)
at Request.<anonymous> (node_modules/request/request.js:1048:10)
at IncomingMessage.<anonymous> (node_modules/request/request.js:969:12)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
Here is my test:
//example from built.io
"use strict";
require("./helpers/setup");
require('colors');
var wd = require("wd"),
_ = require('underscore'),
Q = require('q'),
serverConfigs = require('./helpers/appium-servers');
var serverConfig = serverConfigs.local;
var driver = wd.promiseChainRemote(serverConfig);
var pry = require('pryjs');
var _p = require('./helpers/promise-utils'); // needed?
var simulator = false
var chai = require("chai");
// var assert = require('assert'); //needed?
var assert = chai.assert;
// var config = require('./helpers/config')
chai.config.includeStack = true;
describe("Node Sample Automation Code", function() {
this.timeout(300000);
var allPassed = true;
before(function() {
var serverConfig = process.env.SAUCE ? serverConfigs.sauce : serverConfigs.local;
var driver = wd.promiseChainRemote(serverConfig);
require("./helpers/logging").configure(driver);
var desired = _.clone(require("./helpers/caps").mycapabilities);
desired.app = require("./helpers/apps").myTestApp;
if (process.env.SAUCE) {
desired.name = 'Automation Code';
desired.tags = ['sample'];
}
return driver.init(desired);
});
after(function() {
return driver
.sleep(3000).quit().finally(function() {
if (process.env.SAUCE) {
return driver.sauceJobStatus(allPassed);
}
});
});
afterEach(function() {
allPassed = allPassed && this.currentTest.state === 'passed';
});
it("Should Login", function() {
return driver
.elementByName('Username').click()
//same field - this doesn't work either
// .elementByXPath("//UIAApplication[1]/UIAWindow[1]/UIATextField[1]")
});
});
I have the exact same error with the elementByXPath command, which uses the exact path to the element revealed by the Appium Inspector. In both cases I am using the commands exactly as in examples of other tests that work in other setups (also iOS and mocha), leading me to believe it's not my usage of the command, but something fundamentally wrong with communication between the device and Appium.
Here's an excerpt of the Appium Log that seems applicable to the error:
2016-12-26 03:47:43:217 - [MJSONWP] Responding to client with driver.getStatus() result: {"build":{"version":"1.5.3"...
2016-12-26 03:47:43:233 - [HTTP] --> POST /wd/hub/session/element {"using":"name","value":"Username"}
2016-12-26 03:47:43:237 - [debug] [HTTP] No route found. Setting content type to 'text/plain'
2016-12-26 03:47:43:239 - [HTTP] <-- POST /wd/hub/session/element 404 5 ms - 65
2016-12-26 03:47:43:242 - [MJSONWP] Responding to client with driver.getStatus() result: {"build":{"version":"1.5.3"...
I'd appreciate any help anyone can provide, even guesses or hints as to what the error "Not JSON response" means, and why that might be occurring. Thanks in advance.
I was defining driver twice - after commenting it out in the "before" block, and using the XPath command instead of .elementByName, it worked.