TCL operates through the Xml-rpc interface Testopia

Source: Internet
Author: User
Tags require requires
Testopia is an open source test case management tool that exists in the form of a bugzilla plugin. Like Bugzilla, Testopia provides XML-RPC programming interfaces.

The company's automated testing framework needs to automatically update the test results to the Testopia function, Google, found on the Testopia official website provides python and Java samples, the address is: http://landfill.bugzilla.org/ testopia2/testopia/contrib/drivers/(This address mood is not very stable, testopia official words: occasionally goes down). Unfortunately, there is no Tcl, then studied a bit, summed up in this.

Tcl under the XMLRPC package provides a XML-RPC interface, can be loaded using "packages require XMLRPC", XMLRPC the next basic XML-RPC interface calls are mainly two steps:

1. Use:: Xmlrpc::create to create a TCL function equivalent to the interface.

2. Use the TCL function to complete the XML-RPC call.

Example:

Testopia's Product.get_cases API (link 1, Link 2 line 285) can get all the test cases under a Product, the API has only one parameter: $product-integer/string, INTEGER:PRODUCT_ID of the product in the Database, string:product name. The process of invoking this API:

Package require XMLRPC

set product_id
set Testopia_serverip 192.168.1.1
set URL http/$testopia _ serverip/bugzilla/xmlrpc.cgi

#创建与接口等价的Tcl函数
xmlrpc::create "product.get_cases" \
    -proxy $url \
    - params {product int}

#调用创建的Tcl函数
set testcase_info [product.get_cases $product _id]
puts $testcase _info

Xmlrpc::create the TCL function name is created in two formats:

Format 1:

Xmlrpc::create "API Name"; #Tcl函数名称与API名称完全一样

Format 2:

Xmlrpc::create "TCL Proc name"  \; #Tcl函数名称自定义, specify API by-name parameter name
    -name "API name"

The params is a list of API parameter names and parameter types, format: {parameter name parameter type}, parameter types are mainly string, int, double, boolean, and so on.

In addition, an API such as user.login requires a struct type parameter, which defines the structure type parameter as follows:

:: rpcvar::typedef {
    login string
    password string
    Remember Boolean
} login_struct

Methods for using structural parameters when Xmlrpc::create:

Xmlrpc::create "User.login" \
    -proxy $url \
    -params {login Login_struct}

The TCL function call requires a pass-through list:

User.login {LOGIN ABC password 123 remember 1}

After understanding the above content, we can refer to Testopia API interface for Call, API document address: http://landfill.mozilla.org/testopia/docs/en/html/api/. But there are two more points to note:

1. Testopia Log on all operations need to bring cookies, otherwise it will prompt "login Required", XMLRPC package does not provide a way to operate cookies, but provides a way to operate the HTTP header, we can crawl their own cookies, Then fill in the subsequent operation of the message, please refer to the following code.

2. When the information returned through the API has Chinese information, it may display garbled characters, which can be resolved by encoding conversion, such as "Encoding ConvertFrom utf-8 $content"

    below demonstrates login Testopia with a piece of code and gets the complete process for all testcase under the product.

Package require XMLRPC #定义登录参数结构:: rpcvar::typedef {Login String Password string Remember Boolean} Login_st Ruct set product_id 1 set testopia_serverip 192.168.1.1 set URL/http/$testopia _serverip/bugzilla/xmlrpc.cgi #创建登录, logout to and get the TCL function of product use case xmlrpc::create "User.login" \-proxy $url \-params {login login_struct} xmlrpc::create "User.logout  "\-proxy $url \-params {} xmlrpc::create" product.get_cases "\-proxy $url \-params {Product int} set Login_result [user.login {login ABC password 123 remember 1}] #获取登录id, set Coockie will be used when assembling login_id [string range $login _res Ult 3 end] #获取http头 set Http_meta [XMLRPC::d ump-meta user.login] #获取Cookie编号 regexp "bugzilla_logincookie= (\[a-za-z0-9\) +); "$http _meta match Login_cookie #组装完成的cookie set Full_cookie" bugzilla_login= $login _id; bugzilla_logincookie= $login _cookie "#设置cookie到http头 xmlrpc::configure-transport http-headers [list" Cookie "$full _ Cookie] Set testcases [product.get_cases $product _id] Set Testcases_encoded [Encoding ConvertFrom utf-8 $testcases] puts $testcases _encoded user.logout  

Results of the output:

{author_id 144 script {} estimated_time 00:00:00 case_id 7563 case_status_id 2 default_tester_id 144 requirement {} priori ty_id 1 category_id Summary RFC2544 test creation_date {2011-03-14 09:55:17} isautomated 0 arguments {}}

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.