Web 测试工具合集

来源:互联网 发布:网络电视的使用方法 编辑:程序博客网 时间:2024/05/14 04:31

1. Selenium

Commonly Used Selenium Commands

To conclude our introduction of Selenium, we’ll show you a few typical Seleniumcommands. These are probably the most commonly used commands for building tests.

open
opens a page using a URL.
click/clickAndWait
performs a click operation, and optionally waits for a new page to load.
verifyTitle/assertTitle
verifies an expected page title.
verifyTextPresent
verifies expected text is somewhere on the page.
verifyElementPresent
verifies an expected UI element, as defined by its HTML tag, is present onthe page.
verifyText
verifies expected text and its corresponding HTML tag are present on the page.
verifyTable
verifies a table’s expected contents.
waitForPageToLoad
pauses execution until an expected new page loads. Called automatically whenclickAndWait is used.
waitForElementPresent
pauses execution until an expected UI element, as defined by its HTML tag,is present on the page.

Assertion or Verification?

Effectively an “assert” will fail the testand abort the current test case, whereas a “verify” will fail the test andcontinue to run the test case.

Locating Elements

Locating by Identifier

identifier=continue

Locating by Name

name=continue value=Clear

Locating by XPath

  • xpath=/html/body/form[1] (3) - Absolute path (would break if the HTML waschanged only slightly)
  • //form[1] (3) - First form element in the HTML
  • xpath=//form[@id='loginForm'] (3) - The form element with attribute named ‘id’ and the value ‘loginForm’

    Locating Hyperlinks by Link Text

    link=Cancel

    Locating by DOM

    dom=document.getElementById('loginForm')

    Locating by CSS

  • css=form#loginForm (3)


  • css=input[name="username"] (4)

    The “AndWait” Commands

    the AndWaitalternative (e.g. clickAndWait) tells Selenium to wait for the page toload after the action has been done.

    The waitFor Commands in AJAX applications

    This is done using waitFor commands, as waitForElementPresent orwaitForVisible, which wait dynamically, checking for the desired conditionevery second and continuing to the next command in the script as soon as thecondition is met.


    2. Curl

    curl http://yilmazhuseyin.com/blog/dev/curl --request GET 'http://yilmazhuseyin.com/blog/dev/'
     curl --request POST 'http://www.somedomain.com/' curl --request DELETE 'http://www.somedomain.com/' curl --request PUT 'http://www.somedomain.com/'
    ::::/bin/bash# send login data with POST requestcurl --request POST 'http://www.somedomain.com/login/' \--data 'username=myusername&password=mypassword'# send search data to with get requestcurl --request GET 'http://www.youtube.com/results?search_query=my_keyword'# send PUT request with datacurl --request PUT 'http://www.somedomain.com/rest-api/user/12345/'\--data 'email=myemail@gmail.com'# same thing but this one get data from a file named data.txtcurl --request PUT 'http://www.somedomain.com/rest-api/user/12345/'\--data @data.txt
    curl --request GET 'http://www.somedomain.com/user/info/' \--header 'sessionid:1234567890987654321'
    curl --request GET 'http://somedomain.com/' --include  #Get header together with response
    curl --form upload=@localfilename --form press=OK [URL]  #file upload
    curl --upload-file uploadfile http://www.example.com/receive.cgi #upload a file
    curl --user-agent "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)" [URL] # user agent
    curl https://secure.example.com #https
    curl --data "<xml>" --header "Content-Type: text/xml"  --request PROPFIND url.com #XML
    curl dict://dict.org/d:bash #Using dict protocol
    #fetch multiple files
    $ curl -O http://www.gnu.org/software/gettext/manual/html_node/index.html -O http://www.gnu.org/software/gettext/manual/gettext.html

    3. JMeter

    JMeter的脚本是.jmx,可以通过Badboy录制获得

    JMeter几乎提供任何一种系统的测试配置。总的来说,下列协议被包含在内:

    • Web: HTTP, HTTPS网站 ‘web 1.0′ web 2.0 (ajax, flex 和 flex-ws-amf): 测试一个潜在的网页及其行为
    • Web 服务: SOAP / XML-RPC.
    • 通过JDBC驱动的数据库。几乎支持任何一种数据库,你需要的就是一个合适的驱动程序包,并放到在JMeter安装目录的正确位置。例如做一个MySQL数据库测试。
    • 路径: LDAP.
    • 基于JMS的面向消息的服务
    • 使用POP3, IMAP, SMTP协议的邮件服务.
    • FTP服务
    • 使用JUnit和Java应用程序的进行的功能测试

    测试计划与组件

    基本上,使用JMeter可以进行如下操作:创建,配置,执行测试计划及结果分析。测试计划是对已配置的本地或远程服务器(或客户端)的请求集执行的具体说明。

    线程组(ThreadGroup)

    一个线程组基本上是不同的测试计划元素的组合,它是一个测试计划的核心,它控制着基本核心参数。

    为了创建一个测试计划,首先你不得不去创建一个线程组,配置如下参数:线程数量,过渡时期,循环次数和正常情况或者错误情况下的行为:

    • 线程数:执行测试计划的线程数,这个参数对于配置负载和压力测试非常重要。
    • 过渡期:JMeter开始启动所有线程所需时间。
    • 循环次数:即迭代次数,也就是测试计划被执行的次数
    • 错误行为:错误场景下的行为模式:阻止当前线程,停止整个测试,继续执行…

    采样器(Samplers)

    采样器用于发送请求到不同类型的服务器。它们是每一个测试计划的基本要素,一切都围绕这些采样器而工作:采样器执行请求(基于配置的请求),这些请求产生一个或多个响应,后续将被分析。

    这里有一个在JMeter可用的采样器列表(在本教程我们将看到其中一些):

    • 访问日志采样器
    • AJP采样器
    • Bean shell取样器
    • BSF采样器
    • 调试采样器
    • FTP采样器
    • HTTP采样器
    • Java采样器
    • JDBC采样器
    • JMS(几个)采样器
    • JSR223采样器
    • JUnit采样器
    • LDAP(几个)采样器
    • 邮件阅读器
    • MongoDB采样器
    • 操作系统进程取样器
    • SMTP采样器
    • SOAP
    • TCP采样器
    • 测试行动

    逻辑控制器(Logic Controllers)

    逻辑控制器允许你配置一个线程组内不同采样器的执行顺序。该列表包含了在JMeter所有可用的逻辑控制器:

    • 简单控制器
    • 循环控制器
    • 一次性控制器
    • 交错控制器
    • 随机控制器
    • 随机顺序控制器
    • 流量控制器
    • 运行时控制器
    • I控制器
    • While控制器
    • Switch控制器
    • ForEach控制器
    • 模块控制器
    • include控制器
    • 事务控制器
    • 记录控制器

    监听器(Listeners)

    监听器提供不同的方式查看由采样器请求产生的结果。监听器以报表、树型结构、或简明的日志文件的形式分析结果

    这些都是JMeter可用的监听器:

    • 样品结果配置保存
    • 全图景结果集
    • 图表结果集
    • 样条线可视化工具
    • 断言结果集
    • 树形结果集
    • 整合报告
    • 表格结果集
    • 简单数据输出
    • 监测结果集
    • 分布图(alpha)
    • 整合图
    • Mailer可视化工具
    • Beanshell监听器
    • 总结报告

    定时器(Timers)

    可以使用定时器来定义请求之间的等待时间。如果不指定,JMeter会一个请求完成后立即执行下一个请求,没有任何等待时间。

    可在JMeter使用的计时器如下:

    • 恒定的定时器
    • 高斯随机定时器
    • 均匀随机定时器
    • 恒定吞吐量定时器
    • 同步定时器
    • jsr223定时器
    • Beanshell定时器
    • BSF定时器
    • 泊松随机定时器

    断言(Assertions)

    断言通过验证采样器请求产生的响应,来验证测试计划的有效性。它基本上类似于单元测试断言,用来检测被测试应用程序的响应质量。你可以为每个测试计划配置任何生效的断言。

    这里是一个在JMeter可以使用的断言列表:

    • Bean shell断言
    • BSF断言
    • 比较断言
    • jsr223断言
    • 响应断言
    • Duration断言
    • XML Assertion
    • BeanShell Assertion
    • MD5Hex Assertion
    • HTML Assertion
    • XPath Assertion
    • XML Schema Assertion

    配置节点(Configuration nodes)

    通过使用配置元素你可以将不同的参数传递给取样器请求。他们提供了创建变量(不同的和动态的)的一种方式,这些参数之后被采样器所使用。在采样器被执行前,参数所属节点启动时,这些参数被执行;这就是为什么采样器可以依赖这些变量。

    这里是一个在JMeter使用的所有配置节点列表:

    • 计数器
    • CSV数据集配置
    • FTP请求缺省值
    • HTTP授权管理
    • HTTP缓存管理
    • HTTP cookie管理
    • HTTP代理服务器
    • HTTP请求缺省值
    • HTTP头部管理
    • Java请求缺省值
    • 密钥库配置
    • JDBC连接值
    • 登录配置元素
    • LDAP请求缺省值
    • LDAP扩展请求缺省值
    • TCP采样器配置
    • 用户自定义变量
    • 简单配置元素
    • 随机变量

    前置处理器(Pre processors)

    在采样器执行前,前置处理器被触发。他们可用于从响应中提取变量,这些变量后续将通过配置元素被采样器所使用。

    下面都是可以用来作为前置处理器的元素:

    • HTML链接解析器
    • HTTP URL重写修改器
    • HTTP用户参数修改器
    • 用户参数
    • JDBC前置处理器
    • jsr223前置处理器
    • 正则表达式的用户参数
    • Beanshell前置处理器
    • BSF的前置处理器

    后置处理器(Post processors)

    后置处理器是取样器被执行后被触发执行的元素。他可用于解析响应数据,提取变量,以便后续使用
    下列元素可用于后置处理器:

    • 正则表达式提取器
    • XPath提取器
    • Result status动作处理器
    • jsr223 后置处理器
    • JDBC 后置处理器
    • BSF后置处理器
    • jQuery/CSS 提取器
    • Beanshell 后置处理器
    • Debug后置处理器

    测试计划元素执行顺序

    测试计划的元素是有序的,通过以下方式执行:

    1–配置节点

    2–前置处理器

    3–定时器

    4–取样器

    5–后置处理器(只在有结果可用情况下执行)

    6–断言(只在有结果可用情况下执行)

    7–监听器(只在有结果可用情况下执行)

    一个测试计划可以包含一个或多个测试计划。通过功能性或者技术逻辑将测试组织在一起是一种常见的做法。


    详细例子见http://www.open-open.com/lib/view/open1416970019487.html

  • 可用的请求

  • 0 0