zoukankan      html  css  js  c++  java
  • Selenium学习(二)-selenium命令(command)

    Command表示要执行的操作是什么,这些Selenium命令通常被称为“selense”,他是一套用于执行测试的命令集。

    在selenese中,一部分命令基于HTML标记,用于测试UI元素是否存在、验证指定内容是否正确、检查链接是否可用,并可用输入字段、选择列表的选项、提交表单并操作表格中的数据等;另一个部分命令辅助测试,例如验证窗口大小、鼠标位置、警告信息、Ajax功能、弹出窗口、事件处理以及其他Web应用程序功能。

    Selenium命令分为三种:Action(操作),Accessor(存储),Assertion(断言)。

    一、Action:用于操作一般应用程序
    1、浏览器的操作
    (1)open(URL):打开指定的URL
    (2)goBack():相当于浏览器上的后退键
    (3)refresh():相当于浏览器上的刷新按钮
    (4)windowsFocus():用于激活当前选中的浏览器窗口
    (5)windowsMaximize():用于将当前选中的浏览器窗口最大化
    (6)close():相当于浏览器的关闭按钮
    2、界面元素的基本操作
    (1)type(locatoe,value):用于在input类型的元素中输入值,也可用于给下拉列表框、复选框赋值。
    (2)typeKeys(locatoe,value):用于模拟键盘敲击事件。
    (3)click(locator):单击链接、复选框或单选按钮。
    (4)clickAt(locator,coordString):与click命令相似,当需要填写坐标。
    (5)doubleClick(locator):双击。如果双击动作会导致页面重新加载,最好在后面添加wautForPageToLoad命令。
    (6)doubleClickAt(locator):与doubleClick想死你,但需要填写坐标。
    (7)select(selectLocator,optionLocator):该选项用于在下拉列表框中选择指定选项。
    关于选项的定位方式:a.label=文本值;b.value=真实值(即在html标记语言中的定义);c.id=id,基于选项的id;d.index=index,选项的索引,从0开始。
    (8)check(locator):勾选复选框或单选框。
    (9)uncheck(locator):取消勾选。
    (10)focus(locator):将焦点转移到指定的元素上。
    3、鼠标键盘模拟操作
    4、设置类操作
    5、测试控制/调试类操作
    (1)pause(waitTime):使测试在指定时间内暂停执行
    (2)break():暂停当前正在执行的测试,直到用于手动单击继续按钮。
    (3)captureEntirePageScreeshot(filename,kwargs):将当前窗口进行截图并保存。
    (4)highlight(locator):暂时将指定元素的背景色改为黄色,并在稍后取消该效果,一般用于调试。
    (5)echo(message):将指定信息打印出来。

    二、Accessor:用于检查应用程序的状态,并将结果存储在变量中
    (1)store(expression,variableName):将指定的值存储在变量中。
    (2)storeTitle(variableName):用于存放网页标题。
    (3)storeLocation(variableName):用于存储当前网页的URL。
    (4)storeValue(locator,variableName):用于存储input元素所存放的值。
    (5)storeEditable(locator,variableName):用于存储input元素的可编辑状态,可以则返回true,否则返回false。
    (6)storeText(locator,variableName):用于某个元素的文本值。
    (7)storeChecked(locator,variableName):用于存储复选框或单选框的勾选情况,勾选则返回true,否则返回false。
    (8)storeSelectedIndex(selectLocator,variableName):获取所选项在列表中的索引。
    (9)storeSelectedLable(selectLocator,variableName):获取指定列表中所选项的文本值。
    (10)storeSelectedValue(selectLocator,variableName):获取指定列表中所选项的真实值。
    (11)storeSelectOption(selectLocator,variableName):获取指定列表中所有选项的文本值,以逗号隔开。
    (12)storeTable(tableCellAddress,variableName):获取表格中某个单元格的值。
    (13)storAttribute(attributeLocator,variableName):获取指定属性的值。Target:格式为“元素定位表达式”+“@属性名称”
    (14)storeTextPresent(pattern,variableName):验证指定的文本是否在页面中出现,出现则返回true,否则返回false。
    (15)storeElementPresent(location,variableName):验证元素是否存在与页面中,出现则返回true,否则返回false。
    (16)storeVisible(location,variableName):验证指定元素是否在页面中显现,出现则返回true,否则返回false。
    (17)storeSpeed(variableName):获取执行速度。

    三、Assertion:与Accessor相似,主要用于验证某个命题是否为真,预期结果与实际结果进行比较的过程。
    分为assert(断言),verify(验证),waitFor(等待)三类命令;
    这三类命令有分为五种验证手段:Title(获取页面标题),Value(获取元素的值),Text(获取元素的文本内容),Table(获取元素的标签),ElementPresent(获取当前元素)。
    区别:如果assert失败,测试就会中断;而verify失败时,失败将会记录下来,但测试依然会继续执行;而waitFor用于等待,直到等待的条件为真,条件为真,那么测试就会通过。
    (title)
    1、验证网页标题是否等于或不等于期望值:assertTitle(pattern)/assertNotTitle(pattern)/verutyTitle(pattern)/verifyNotTitle(pattern)/waitForTitle(pattern)/waitForNotTitle(pattern)。
    2、验证网页的URL是否等于或不等于期望值:assertLocation(pattern)/assertNotLocation(pattern)/verutyLocation(pattern)/verifyNotLocation(pattern)/waitForLocation(pattern)/waitForNotLocation(pattern)。
    (value)

    3、验证input元素的值是否等于或不等于期望值:assertValue(location,pattern)/assertNotValue(location,pattern)/verutyValue(location,pattern)/verifyNotValue(location,pattern)/waitForValue(location,pattern)/waitForNotValue(location,pattern)。
    4、验证input元素的可编辑状态是否为预期状态:assertEditable(location)/assertNotEditable(location)/verutyEditable(location)/verifyNotEditable(location)/waitForEditable(location)/waitForNotEditable(location)。

    (text)
    5、验证某个元素的文本值是否等于期望值:assertText(location,pattern)/assertNotText(location,pattern)/verutyText(location,pattern)/verifyNotText(location,pattern)/waitForText(location,pattern)/waitForNotText(location,pattern)。

    (Table)
    6、验证表格(table元素)中某个单元格(td元素)的值是否为期望值:assertTable(tableCellAddress,pattern)/assertNotTable(tableCellAddress,pattern)
    /verutyTable(tableCellAddress,pattern)/verifyNotTable(tableCellAddress,pattern)/waitForTable(tableCellAddress,pattern)/waitForNotTable(tableCellAddress,pattern)。

    (ElementPresent)
    7、验证指定元素是否存在于页面上:assertElementPresent(location)/assertNotElementPresent(location)/verutyElementPresent(location)/verifyNotElementPresent(location)/waitForElementPresent(location)/waitForNotElementPresent(location)。

    8、验证页面中是否显示指定元素:assertVisible(location)/...
    9、验证指定的文本是否在页面中出现:assertTextPresent(pattern)/...
    10、验证指定属性的值是否为期望值:assertAttribute(attributeLocation,pattern)/...

    11、验证复选框或单选框的勾选情况是否符合期望:assertChecked(location)/...
    12、验证所选项在列表中的索引是否符合期望值:assertSelectedIndex(selectLocation,pattern)/...
    13、验证指定列表中所选项的文本值是否符合期望值:assertSelectedLable(selectlocation,pattern)/...
    14、验证指定列表中所选项的真实值(value属性)是否为期望值:assertSelectedValue(selectlocation,pattern)/...
    15、验证指定列表中所有选项的文本是否符合期望值:assertSelectedOption(selectlocation,pattern)/...

    更多的command可查看selenium帮助手册,查阅更多的action等
    本博文参考书《selenium自动化测试指南》,赵卓著;《selenium2自动化测试实战 基于Python语言》,虫师著;《零基础实现web自动化测试》,温素剑著

  • 相关阅读:
    LeetCode 485. Max Consecutive Ones
    LeetCode 367. Valid Perfect Square
    LeetCode 375. Guess Number Higher or Lower II
    LeetCode 374. Guess Number Higher or Lower
    LeetCode Word Pattern II
    LeetCode Arranging Coins
    LeetCode 422. Valid Word Square
    Session 共享
    java NIO
    非阻塞IO
  • 原文地址:https://www.cnblogs.com/lxoc/p/6716459.html
Copyright © 2011-2022 走看看