自定义的远程关键字库能使用哪些数据类型来和robotframework交互?先引用官网上的一段话
4.2.3   Supported argument and return value types

Because the XML-RPC protocol does not support all possible object types, the values transferred between the Remote library and remote servers must be converted to compatible types. This applies to the keyword arguments the Remote library passes to remote servers and to the return values servers give back to the Remote library.

Both the Remote library and the Python remote server handle Python values according to the following rules. Other remote servers should behave similarly.

Strings, numbers and Boolean values are passed without modifications.
Python None is converted to an empty string.
All lists, tuples, and other iterable objects (except strings and dictionaries) are passed as lists so that their contents are converted recursively.
Dictionaries and other mappings are passed as dicts so that their keys are converted to strings and values converted to supported types recursively.
Strings containing bytes in the ASCII range that cannot be represented in XML (e.g. the null byte) are sent as Binary objects that internally use XML-RPC base64 data type. Received Binary objects are automatically converted to byte strings.
Other types are converted to strings.
Note

Prior to Robot Framework 2.8.3, only lists, tuples, and dictionaries were handled according to the above rules. General iterables and mappings were not supported.

Binary support is new in Robot Framework 2.8.4.

概括起来java能传递的是: 数字类型 boolean String List Array Map。

当java关键字返回的是Map时,该如何书写?

1.远程库方法举例:注意返回类型是Map

package keywords.leading.testcases;import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import org.robotframework.javalib.annotation.ArgumentNames;
import org.robotframework.javalib.annotation.RobotKeyword;
import org.robotframework.javalib.annotation.RobotKeywords;@RobotKeywords
public class FjTest {@RobotKeyword("Example:\n" + "|test Map | key | value | \n")@ArgumentNames({ "key", "val" })public Map<String, String> testMap(String key, String val) throws Exception {System.out.println("key=" + key + ";val=" + val);Map<String, String> map = new HashMap<String, String>();map.put("邓肯微笑遭驱逐!NBA史上10大怪异技犯吹罚",“http://baidu.com.cn");map.put(key, val);return map;}
}

2.robot framework用例书写举例:

1.rf若要实现对Map的遍历取值等操作,还需要引入一个内建库Collections;它提供了字典(Dictionary)操作相关的关键字,python中的字典数据结构对应于java的Map

2.使用${}变量接受Map;使用Collections库的方法操作Map

*** Settings ***
Library           Remote    http://127.0.0.1:8270/    WITH NAME    MyRemoteLibrary
Library           Collections*** Test Cases ***
ReturnMap${dct}    Test Map    hello    world@{keys}=    Get Dictionary Keys    ${dct}: FOR    ${key}    IN    @{keys}\    log    key=${key}\    ${v}=    Get From Dictionary    ${dct}    ${key}\    log    value=${v}

3.输出结果:

Starting test: Fjtest.RemoteLib.ReturnMap
20160120 17:09:04.534 :  INFO : key=hello;val=world
20160120 17:09:04.534 :  INFO : ${dct} = {'hello': 'world', u'\u9093\u80af\u5fae\u7b11\u906d\u9a71\u9010\uff01NBA\u53f2\u4e0a10\u5927\u602a\u5f02\u6280\u72af\u5439\u7f5a': 'http://baid.com...
20160120 17:09:04.536 :  INFO : @{keys} = [ hello | 邓肯微笑遭驱逐!NBA史上10大怪异技犯吹罚 ]
20160120 17:09:04.538 :  INFO : key=hello
20160120 17:09:04.539 :  INFO : ${v} = world
20160120 17:09:04.540 :  INFO : value=world
20160120 17:09:04.541 :  INFO : key=邓肯微笑遭驱逐!NBA史上10大怪异技犯吹罚
20160120 17:09:04.542 :  INFO : ${v} = http://baidu.com.cn
20160120 17:09:04.543 :  INFO : value=http://baidu.com.cn

Ending test:   Fjtest.RemoteLib.ReturnMap

===================

若关键字返回的Map的值是个对象怎么办?

例如下面例子:

@RobotKeyword("Example:\n" + "|test Map | 123 | 456 | \n")@ArgumentNames({ "key", "val" })public Map<String, PlayResource> testMap(String key, String val)throws Exception {System.out.println("key=" + key + ";val=" + val);Map<String, PlayResource> map = new HashMap<String, PlayResource>();PlayResource res = new PlayResource("电视剧","排行","赵又廷,姚晨,凤小岳,李晨,唐嫣,冯瓅,李光洁,王庆祥,吴军,王德顺 da lian huan!!!~","http://baidu.com""1234", null, false);map.put("p1", res);return map;}
class PlayResource {private String channelName;// 所属频道名称private String navName;// 所属标签名称private String name;// 资源名称private String playGetUrl;// 获取播放资源urlprivate String pid;private String vid;private boolean ok;// 是否能播public PlayResource() {super();// TODO Auto-generated constructor stub}public PlayResource(String channelName, String navName, String name,String playGetUrl, String pid, String vid, boolean ok) {super();this.channelName = channelName;this.navName = navName;this.name = name;this.playGetUrl = playGetUrl;this.pid = pid;this.vid = vid;this.ok = ok;}public String getPid() {return pid;}public void setPid(String pid) {this.pid = pid;}public String getVid() {return vid;}public void setVid(String vid) {this.vid = vid;}public String getName() {return name;}public void setName(String name) {this.name = name;}public boolean isOk() {return ok;}public void setOk(boolean ok) {this.ok = ok;}public String getChannelName() {return channelName;}public void setChannelName(String channelName) {this.channelName = channelName;}public String getNavName() {return navName;}public void setNavName(String navName) {this.navName = navName;}public String getPlayGetUrl() {return playGetUrl;}public void setPlayGetUrl(String playGetUrl) {this.playGetUrl = playGetUrl;}@Overridepublic String toString() {return "PlayResource [channelName=" + channelName + ", navName="+ navName + ", name=" + name + ", playGetUrl=" + playGetUrl+ ", pid=" + pid + ", vid=" + vid + ", ok=" + ok + "]";}
}

robot接收类型除了以上列出的类型外,其他均以java对象toString方法输出字符串形式!

输出如下:

Starting test: Fjtest.RemoteLib.ReturnMap
20160120 19:26:57.324 :  INFO : ${dct} = {'p1': u'PlayResource [channelName=\u7535\u89c6\u5267, navName=\u6392\u884c, name=\u8d75\u53c8\u5ef7,\u59da\u6668,\u51e4\u5c0f\u5cb3,\u674e\u6668,\u5510\u5ae3,\u51af\u74c5,\u674e\u5149\u6d01,\u738b\...
20160120 19:26:57.325 :  INFO : @{keys} = [ p1 ]
20160120 19:26:57.326 :  INFO : key=p1
20160120 19:26:57.329 :  INFO : ${v} = PlayResource [channelName=电视剧, navName=排行, name=赵又廷,姚晨,凤小岳,李晨,唐嫣,冯瓅,李光洁,王庆祥,吴军,王德顺 da lian huan!!!~, playGetUrl=http://baidu...
20160120 19:26:57.335 :  INFO : value=PlayResource [channelName=电视剧, navName=排行, name=赵又廷,姚晨,凤小岳,李晨,唐嫣,冯瓅,李光洁,王庆祥,吴军,王德顺 da lian huan!!!~, playGetUrl=http://baidu.com, pid=1234, vid=null, ok=false]
Ending test:   Fjtest.RemoteLib.ReturnMap

RobotFramework-自定义远程java关键字库能否返回Map类型相关推荐

  1. mybatis 字段名自动转小写_mybatis 返回Map类型key改为小写的操作

    默认情况下,当resultType="java.util.Map"时,返回的key值都是大写的. 现在想key改成自己想要的,只需为查询出来的字段增加个别名即可. 如: selec ...

  2. java tolist_java – Collectors.toList()返回什么类型的List?

    So, what concrete type (subclass) of List is being used here? Are there any guarantees? 如果你看一下Collec ...

  3. MyBatis查询返回Map类型数据

    1.Mapper中SQL: <select id="getBaseMap" resultType="java.util.HashMap"> sele ...

  4. ajax和map返回数据类型,ajax请求后台返回map类型并如何展示

    前台jsp或者ftl文件接收返回结果: 注意:value值用单引号,因为后台返回的结果是json字符串 前台js接收返回结果: success: function(data){ var result ...

  5. map mybatis 的字段返回0_mybatis返回map类型数据空值字段不显示(三种解决方法)

    mybatis的配置 mybatis-config.xml 2,springBoot配置   application.properties 添加 #mybatis resultType equal m ...

  6. MyBatis查询结果resultType返回值类型详细介绍

    一.返回一般数据类型 比如要根据 id 属性获得数据库中的某个字段值. mapper 接口: // 根据 id 获得数据库中的 username 字段的值String getEmpNameById(I ...

  7. MyBatis中resultType返回值类型介绍

    一.返回一般数据类型 比如要根据 id 属性获得数据库中的某个字段值. mapper 接口: // 根据 id 获得数据库中的 username 字段的值 String getEmpNameById( ...

  8. Jav详细介绍的Mapper对应的Mybatis xml查询结果resultType返回值类型

    一.返回一般数据类型 此实列总代用的是string类型 列:比如我们要根据 id 属性获得数据库中的某个字段值. mapper 接口: // 根据 id 获得数据库中的 username 字段的值   ...

  9. mysql resulttype_常见的MyBatis中查询结果resultType返回值类型

    一.返回一般数据类型 比如要根据 id 属性获得数据库中的某个字段值. mapper (dao)接口: // 根据 id 获得数据库中的 username 字段的值 String getStuName ...

最新文章

  1. 初学者python用什么开发软件-对于自学python的初学者来说,应该使用什么编辑工具?...
  2. Android Handler消息传递机制
  3. UBUNTU下彻底删除MYSQL
  4. 数据科学与大数据排名思考题_排名前5位的数据科学课程
  5. linux中波浪线是根目录吗,linux 波浪线 ~ 使用方法
  6. Mybatis延迟加载机制
  7. 蔡崇信与马云的 20 年
  8. 华为 台积电 高通申请_台积电/高通纷纷力挺华为!全面放下姿态:将不再断供华为芯片产品...
  9. Qt制作学生管理系统软件
  10. 计算机用户名不显示,Windows10中设置不显示最后用户名的方法
  11. veu创建项目,自定义配置
  12. python拟合线性函数_Python线性拟合实现函数与用法示例
  13. 商标注册流程,山东商标注册去哪好
  14. Linux小知识:查看当前最耗费CPU的线程(Arthas工具)
  15. java初级程序员考试_Java初级程序员必须要知道的10个基础面试题
  16. jQuery文档处理--包裹
  17. (译)网站加速最佳实践——雅虎35条
  18. 史上最牛女秘书 邮件内容
  19. 基于STM32的智能数据采集系统
  20. CHM文档打开空白的解决

热门文章

  1. 女性向游戏难复制下一个“恋与”,从日本游戏能取到什么经?
  2. mongodb4.0学习总结二(read concern)
  3. 恶习为什么难戒?因为你在HALT状态
  4. MMORPG游戏设计
  5. 蓝牙麦克风 android,带蓝牙麦克风的Android语音识别器
  6. Linux从头开始学--学习笔记9知识点补充-ubuntu,centos;在linux上创建c程序;linux基础命令,shell命令,vi命令,man帮助手册
  7. vue页面路由跳转重复报错的问题
  8. mingw32-make.exe缺少的方法
  9. VisualStdio2013旗舰版激活码-注册码.
  10. 网约车新政陆续出台,共享经济遇阻为哪般?