Dialysis qtp automated testing framework saffron

Source: Internet
Author: User

1. Why should I use the framework?

Original article address: Http://www.uml.org.cn/Test/200810108.asp  Author: Chen nengtech

Framework is the basis of a set of automated testing specifications and test scriptsCodeAnd a set of testing ideas and practices. It can be used to reduce redundant code, improve code productivity, and improve code reusability and maintainability. For example, qtestware is one of the qtp automated testing frameworks.

2. Introduction to Saffron

saffro N is a simple qtp testing framework prototype for web development. It was written by Adam Gensler in 9.1 and requires qtp version or later. The complete saffron script code can be obtained at the following address: http://www.itestware.com/ctest/index.php? Option = com_content & view = article & id = 62: webqtp-Saffron & catid = 35: testing_is_believing

3. How to Use saffron?

The saffron framework exists in the form of vbs files. Therefore, the method of use is relatively simple. You can import the files directly in the test script as resources ,:

After the import, you can see all saffron functions in the "available keywords" View ,:

Select a function and drag it to the editor of the expert view ,:

After receiving a URL address, such as the http://www.itestware.com, you can use the browseto function in the saffron framework to navigate to the specified URL address, as shown in the following script:
'Browseto (URL)
Browseto http://www.itestware.com"

4. Saffron framework code analysis

To gain an in-depth understanding of saffron and the use of the framework, we will introduce the main functions in saffron and conduct an in-depth analysis of the saffron code.

4.1 navigate to the specified URL

Saffron uses the browseto function to navigate to the specified URL. If the browser has not been started, call the function launch to open the browser. The browseto function is defined as follows:
  Public Function browseto (URL)
  Thirdlevel = ""
  Report micpass, "navigate to URL", "navigating to URL:" & quote (URL)
  If initialized then
  Execute generatedescription ("Browser") & "navigate" & quote (URL)
  Else
  Launch "website", URL
  End if
  Reporter. Filter = rfdisableall
  End Function

In the script, it determines whether the browser is initialized. If yes, it performs a navigation action to navigate to the specified URL. The navigation action is completed by executing this script:
 Execute generatedescription ("Browser") & "navigate" & quote (URL)

Execute is a function used to execute the specified VBScript statement. The generatedescription function is defined as follows:
  'Generates a generic description based up on the "level" viarable
  'Levelstr-will be one of the values that is in the Level Array
  'Returns-string representative of the object hierarchy
  Public Function generatedescription (levelstr)
  L = indexof (Level, levelstr)
  If l> = 0 then
  Fdesc = level (0) & "(" & quote (DESC (0 ))&")."
  If l> = 1 then
  Fdesc = fdesc + level (1) & "(" & quote (DESC (1 ))&")."
  If 2> = l then
  If thirdlevel <> "then
  Fdesc = fdesc + level (2) & "(" & quote (DESC (2) & "," & quote ("Name: =" & thirdlevel )&")."
  End if
  End if
  End if
  End if
  Generatedescription = fdesc
  End Function

4.2 return the description of the test object.

the generatedescription function is used to return descriptive statements of objects. For example, if you specify browser, the following statements are returned:
"browser (" micclass: = Browser "). "

This statement represents The current browser object, followed by a dot, is to facilitate the navigation operation of the browser object after "navigate", and the specified URL string, such as "http://blog.csdn.net/testing_is_believing ". In execute, the VBScript statement is actually executed as follows:
browser ("micclass: = Browser "). navigate http://blog.csdn.net/testing_is_believing

After the saffron framework is encapsulated, you only need to use the following statement to achieve the same effect:
Browseto http://blog.csdn.net/testing_is_believing"

4.3 start the browser

Saffron uses the browseto function to navigate to the specified URL. However, if the browser is not started, it first calls the launch function to open the browser. The launch function is defined as follows:
  Prepares the framework for usage, and configures all internal framework
  'Variables and structures
  'Apptype-used to launch different types of applications based
  '   Upon different technologies -- currently there is only web
  'Val   -String that represents what to launch
  'Returns-always returns true
  Public Function launch (apptype, Val)
  If "website" = apptype then
  Thirdlevel = ""
  Report micpass, "initialize", "Initializing framework"
  Level = Split (weblevels, leveldelimiter,-1, 1)
  Desc = Split (weblevelsdesc, leveldescdelimiter,-1, 1)
  Object = Split (objects, objectdelimiter,-1, 1)
  Objectdescription = Split (objectsdescription, objectsdescriptiondelimiter,-1, 1)
  Closebrowsers
  Set Ie = Createobject ("internetexplorer. application ")
  Ie. Visible = true
  Ie. navigate Val
  While IE. Busy
  Wait 1
  Wend
  End if
  Initialized = true
  Launch = true
  End Function

the script is displayed. Create a COM Object for IE, set the visible attribute of IE to Tue, make the browser visible, and call the navigate method of the IE Object to navigate to the specified URL. In addition to creating the COM Object of IE, the launch function also initializes other aspects of the framework.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.