you never doubt youself,I belive!

How to build Automation Framework 如何搭建自动化测试框架【译】

上一篇 / 下一篇  2010-02-06 11:04:15 / 个人分类:测试基础知识

How to build Automation Framework

如何搭建自动化测试框架

 

Objective

目标


·Why need to build the framework?

·为什么需要搭建框架?
-Many times, we have lots of test cases, if no one manage them, you will find that it's hard to find someone you want. Also, if they are not managed by the regular rule, it's very hard to transfer these cases to next person. So we need to build  the test cases frame. that everyone needs to follow the same rule. Same as  Automation framework, we need a framework to let all QA know how to automate their cases.

-很多时候,我们有很多的测试用例,如果没有管理这些用例的话,你将很难找到你所需要的用例。 同样,如果没有一个有规律的法则来管理的话,我们很难将这些用例交接给其他人使用。所以我们需要建立一个框架,以便于每个人都按照相同规则来执行。 比如自动化框架,所建立的框架需要让QA知道如何自动的使用这些测试用例。


How to build?

如何建立?


·Some people may say we are testing different projects, different products, and  different functions, how to build only one framework for these different  requirement?

·有人或许会说,我们所测试的项目、产品或功能都是不同的,那么如何建立一个框架能满足不同的需求呢?
·For the detail, you are right, but for general, we can build a basic frame. to fit  the general purpose, here, what I’m talking is about this.

·关于细节,你是对的;但总体来说,我们可以建立基本框架来满足普遍的用途,下面我将详细讲解这些。


·Purpose 1: Group your automated test cases.

·目标1:将测试用例分组
  -Every case needs to follow this rule:

  -所有的用例都需要遵循以下规则:
    ·UI action (Click, Edit …..)

    ·用户界面测试(点击,编辑...)
    ·Handle the unexpected error.

    ·处理未知错误
    ·Validation, return the result of this case: pass/fail

    ·验证,返回用例结果:通过/失败
  -You can keep this case as a QTP test or as an function or a VBS file

  -你可以将这些用例保存在QTP里 或者 作为功能模块、VBS脚本文件
  -Once you created more cases, then you can group them as one group and save to a place that easier for QTP to access.

  -当你编写更多用例之后你可以将其分文别类放在一个个的组里,便于QTP访问
·Example: here I use the excel to keep all test cases

·例如:以下我将所有的测试用例放在excel表格中

图片

·Purpose 2: Create function library

·目标2:创建功能模块库

- This is very useful concept to reduce your code quantity and increase your code quality.

-这是个对于缩减代码量和增加代码质量很有帮助的概念。
- Of course, according the different situation, we can separate the function to different level.

-当然,根据不同的情况,我们可以将系统功能分为不同的级别。


Common level
High Level
 ….
·Here I just create one function lib, and it contains two functions (meanwhile they are cases) 

·以下是我编写的功能类库,它包括两个功能(同时使用这些用例)
Function CreateTest()
 …steps
 ….validation
 ….return value
 End Function
 Function BuildNumber()
 …steps
 ….validation
 ….return value
 End Function

 

·Purpose 3: Output the result.

·目标:输出结果

-There is important thing after execute all the cases, that’s result analysis, so we need to make the result clear and easy

 to read and analysis.

- 当所有测试用例结束后测试结果分析是非常重要的,所以我们需要让测试结果清晰并且易读和分析
-Example: in Purpose 1, see the status and result.

-例如:在目标1中,看到的状态和结果


·Purpose 4: Define the driver. 

·目标4:定义驱动
 - This is the most important things in the whole framework, like the brain of  human.

-这是在整个框架的创建中最重要的一步,就像人的脑袋一样重要
 - It must contain these function:

-它必须包括以下功能
    ·Read out the test cases from case file( created in purpose 1)

    ·从用例文件中读取出测试用例(在目标1中创建)
    ·Execute the test case one by one

    · 一个一个地执行测试用例
    ·Get the return value for each cases and save to the output results

    ·从每个用例中获取返回值 并且将其保存输出到结果文件中。
    ·Some exceptions handle

   ·一些异常的处理


Driver example

驱动例子

TestFile = "D:\casesfile.xls"
ResultFile = "D:\resultfile.xls"

caseSheet = 1 'Specify the case sheet
varSheet = 2 'Specify the var value sheet
' Import the case file
DataTable.Import (TestFile)
rcnt = DataTable.GetSheet(caseSheet).GetRowCount
'Execute test scenarios one by one and update result file
iter =1
DataTable.GetSheet(caseSheet).SetCurrentRow iter
For iter = 1 to rcnt

 executeFlag=False 
 DataTable.GetSheet(caseSheet).SetCurrentRow iter 
    ScenarioName=DataTable("CaseName", caseSheet)
    Datatable("Status", caseSheet)= ""
    Datatable("result", caseSheet)= ""
 
 results=eval(ScenarioName)
 status = Split(results,"|")
 Datatable("Status", caseSheet) = status(0)
 Datatable("result", caseSheet)= status(1)
 DataTable.Export ResultFile
Next


KeyView of framework

框架视图

 

图片

 


Conclusion

结尾


·This is a high level framework for the automation testing strategy, for the detail  execution, we still need to add more thing to make it more powerful.

·这是一个自动化测试框架的策略高度,执行的细节,我们仍然需要增加更多东西,使之更加强大。


TAG:

luozhi4102的个人空间 引用 删除 luozhi4102   /   2010-09-08 23:44:39
 

评分:0

我来说两句

Open Toolbar