我这边是使用 ruby 来调用 java 的代码,用的是 rjb 的 gem,实例化和运行都可以,但参考官方的示例 ip 和 port 的参数无法修改,提交显示仍然是http://localhost:3456wd.java 里面的初始化 ip 和端口就可以,是否该处的 java 代码有 bug?。直接修改写死
java 代码示例:
public class SampleTest {

MacacaClient driver = new MacacaClient();

@Before
public void setUp() throws Exception {
Logger logger = Logger.getLogger(getClass());
JSONObject porps = new JSONObject();
porps.put("autoAcceptAlerts", true);
porps.put("browserName", "electron");
porps.put("platformName", "desktop");
porps.put("version", "");
porps.put("javascriptEnabled", true);
porps.put("platform", "ANY");
JSONObject desiredCapabilities = new JSONObject();
desiredCapabilities.put("desiredCapabilities", porps);
//desiredCapabilities.put("host", "127.0.0.1"); // custom remote host
//desiredCapabilities.put("port", 3456); // custom remote port
driver.initDriver(desiredCapabilities).setWindowSize(1280, 800).get("https://www.baidu.com");
}

ruby 代码引用:
def self.setup(hash)
if @driver.nil?
switch(hash[:deviceid])
end
params = @@device_hash[ hash[:deviceid] ]
params.each do |k,v|
ATT.keyword_logger.info( "参数 : #{k} ---> #{v.to_s}" )
end
class_json = Rjb::import('com.alibaba.fastjson.JSONObject')
porps = class_json.new
porps.put("autoAcceptAlerts",params[:autoacceptalerts])
porps.put("platformName",params[:platformname])
porps.put("platformVersion",params[:platformversion])
porps.put("deviceName",params[:devicename])
porps.put("javascriptEnable",params[:javascriptenable])
porps.put("udid",params[:udid])
porps.put("reuse",params[:reuse])
porps.put("bundleId",hash[:bundleid])
porps.put("package",hash[:package])
porps.put("activity",hash[:activity])
porps.put("browserName",hash[:browsername])
porps.put("app",hash[:app])
desiredCapabilities = class_json.new
desiredCapabilities.put("desiredCapabilities",porps)
desiredCapabilities.put("host", params[:host]) #custom
desiredCapabilities.put("port", params[:port]) #custom
ATT.keyword_logger.debug( @driver)
@driver.initDriver(desiredCapabilities)
end

交互日志提示为 localhost:

org.apache.http.conn.HttpHostConnectException: Connection to http://localhost:34
56 refused


↙↙↙阅读原文可查看相关链接,并与作者交流