我已经尝试了http://appium.io/slate/en/1.5.3/?javascript#ios中列出的问题排查步骤,但没有运气。
我用:
进行测试$ mocha sample.js
这会成功在设备上安装应用程序并打开它,但每次出现此错误时,测试都会在第一步失败:
错误:[elementByName(“Username”)]不是JSON回复
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)
这是我的测试:
//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]")
});
});
我对elementByXPath命令有完全相同的错误,该命令使用Appium Inspector显示的元素的确切路径。在这两种情况下,我使用的命令与在其他设置(也包括iOS和mocha)中工作的其他测试的示例完全相同,这让我相信它不是我对命令的使用,但是设备和Appium之间的通信存在根本错误
以下是Appium Log的摘录,似乎适用于错误:
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"...
我很感激任何人都可以提供的任何帮助,甚至猜测或提示错误“不是JSON响应”的含义,以及为什么会发生这种情况。提前致谢。
答案 0 :(得分:1)
我正在定义驱动程序两次 - 在“之前”块中对其进行注释,并使用XPath命令而不是.elementByName之后,它起作用了。