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; } }
*** 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.输出结果:
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;// 获取播放资源url private 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; } @Override public 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