1. def list_selection_should_be(self, locator, *items):
  2. """Verifies the selection of select list identified by `locator` is exactly `*items`.
  3.  
  4. If you want to test that no option is selected, simply give no `items`.
  5.  
  6. Select list keywords work on both lists and combo boxes. Key attributes for
  7. select lists are `id` and `name`. See `introduction` for details about
  8. locating elements.
  9. """
  10. items_str = items and "option(s) [ %s ]" % " | ".join(items) or "no options"
  11. self._info("Verifying list '%s' has %s selected." % (locator, items_str))
  12. items = list(items)
  13. self.page_should_contain_list(locator)
  14. select, options = self._get_select_list_options_selected(locator)
  15. if not items and len(options) == 0:
  16. return
  17. selected_values = self._get_values_for_options(options)
  18. selected_labels = self._get_labels_for_options(options)
  19. err = "List '%s' should have had selection [ %s ] but it was [ %s ]" \
  20. % (locator, ' | '.join(items), ' | '.join(selected_labels))
  21. for item in items:
  22. if item not in selected_values + selected_labels:
  23. raise AssertionError(err)
  24. for selected_value, selected_label in zip(selected_values, selected_labels):
  25. if selected_value not in items and selected_label not in items:
  26. raise AssertionError(err)

方法名:list_selection_should_be(self, locator, *items)

相似方法:

公共方法 验证指定labels或values的选项应该被选中

接收参数:locator,*items(labels/values)

13行:使用page_should_contain_list(self, locator, message='', loglevel='INFO')方法,验证select list 存在于当前页面

14行:使用_get_select_list_options_selected(self, locator)方法返回Select 元素对象和选中options数组

17行:使用_get_values_for_options(self, options)方法返回选中options的values数组

18行:使用_get_labels_for_options(self, options)返回选中options的labels数组

20、21行: 遍历所传入的items,判断item是否为选中项

24、25行: 遍历当前选中项的value和label,如果不在传入items中存在则报错

使用:

输出结果:

  1. FAIL : List 'id=creOutTime' should have had selection [ 0 | 1 ] but it was [ 无逾期 | 无记录(征信空白) | 贷款或贷记卡当前逾期金额>=300 ]

Selenium2Library系列 keywords 之 _SelectElementKeywords 之 list_selection_should_be(self, locator, *items)的更多相关文章

  1. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 unselect_from_list(self, locator, *items)

    def unselect_from_list(self, locator, *items): """Unselects given values from select ...

  2. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 select_from_list(self, locator, *items)

    def select_from_list(self, locator, *items): """Selects `*items` from list identified ...

  3. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 unselect_from_list_by_label(self, locator, *labels)

    def unselect_from_list_by_label(self, locator, *labels): """Unselects `*labels` from ...

  4. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 unselect_from_list_by_value(self, locator, *values)

    def unselect_from_list_by_value(self, locator, *values): """Unselects `*values` from ...

  5. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 unselect_from_list_by_index(self, locator, *indexes)

    def unselect_from_list_by_index(self, locator, *indexes): """Unselects `*indexes` fro ...

  6. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 select_from_list_by_label(self, locator, *labels)

    def select_from_list_by_label(self, locator, *labels): """Selects `*labels` from list ...

  7. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 select_from_list_by_value(self, locator, *values)

    def select_from_list_by_value(self, locator, *values): """Selects `*values` from list ...

  8. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 list_should_have_no_selections(self, locator)

    def list_should_have_no_selections(self, locator): """Verifies select list identified ...

  9. Selenium2Library系列 keywords 之 _SelectElementKeywords 之 get_selected_list_values(self, locator)

    def get_selected_list_values(self, locator): """Returns the values of selected elemen ...

随机推荐

  1. VCL ActiveX 播放视频

    播放网络视频 string[] options = new string[] { ":sout=#duplicate{dst=display} :no-overlay" }; st ...

  2. TCL语言笔记:TCL基础语法

    一.什么是TCL Tcl 全称是 Tool command Language.它是一个基于字符串的命令语言,基础结构和语法非常简单,易于学习和掌握. Tcl 语言是一个解释性语言,所谓解释性是指不象其 ...

  3. IDEA查找功能小结

    查找类:Ctrl + N 支持模糊查询

  4. set集合_定长

    //set集合的操作        //便利初始化函数        NSSet *set1 = [[NSSet alloc] initWithObjects:@"aa", @&q ...

  5. eclipse Juno Indigo Helios Galileo这几种版本的意思(转)

    Galileo Ganymede Europa 这些名字代表eclipse不同的版本  2001年11月7日 ,Eclipse 1.0发布   半年之后,2002年6月27日Eclipse进入了2.0 ...

  6. Vim的tagbar插件

    1.tagbar针对当前文件,调用ctags来生成结果,并抓取其结果,像下边这样的 ctags -f - --format=2 --excmd=pattern --extra= --fields=nk ...

  7. nyoj-291 互素数个数 欧拉函数

    LK的数学题 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 LK最近遇到一个问题,需要你帮她一下.一个整数n,求[1,n)中,和n互素的数的个数.   输入 多组测 ...

  8. 函数buf_page_create

    /********************************************************************//** Initializes a page to the ...

  9. bzoj3261: 最大异或和

    可持久化trie.又是%%%Xs酱... #include<cstdio> #include<cstring> #include<iostream> #includ ...

  10. Linux LiveCD 的制作

    Knoppix,只需一张光盘, 就能够让我们在任何场所,随心所欲地使用 Linux1, 打破了操作系统只能先安装再使用的传统概念. Knoppix 最初的设计用途是教学,但由于这项技术很受欢迎,使得  ...