Construction of four test reports for Web automation framework

Source: Internet
Author: User

Present situation:

Read the previous article, the landlord uses Python, so in the building test report this piece is used Unittest+htmltestrunner, and then found that the generated report, there is always so imperfect place, such as want to add pictures, such as the display style changes under And then try to modify a Htmltestrunner source code, although the picture came out, the display style can not be modified ... so ... The initiation of abandonment means ...

Problem:

1.unittest

UnitTest when the case exception or script execution exception, cannot continue to execute the next case ~, such as log on, background service exception, login user no menu permissions exception, new user status causes Unable to login exception, etc.

Unittest.assertequal, assertraises and other assertion methods are difficult to deal with complex functional logic ~ ~, such as the need for If/else, or, and combination of logical judgments.

2.htmlTestrunner

Case test data output information is not complete, the key can not do some cool things, automatic docking defect management system, automatic verification of defects (emphasis);

Historical data information cannot be saved;

The style is always so unsatisfied.

Scheme:

A. Result verification, test parameters output, test parameters output their own package;

B. Test data information is saved in MySQL;

C. Interface, JSP read MySQL data display.

Technical implementation:

A. A brief introduction to the following topics

B. Inserting and related initialization of database data

mysqldb.py

#coding =utf-8
Import MySQLdb
From com.iapppay.test.loginfo.loginfoobject Import *
# reload (SYS)
# reload (SYS). setdefaultencoding (' GBK ')

# def PRINTSTR (**kwargs):
# return KWARGS[0][3]

‘‘‘
Runtime CREATE TABLE ' RunTime ' (
' StartTime ' datetime DEFAULT NULL,
' EndTime ' datetime DEFAULT NULL,
' id ' int (one) not NULL auto_increment,
PRIMARY KEY (' id ')
) Engine=innodb auto_increment=5 DEFAULT Charset=utf8;

Casedata CREATE TABLE ' casedata ' (
' id ' int (one-by-one) not NULL auto_increment,
' casedata ' varchar ($) DEFAULT NULL COMMENT ' case parameters ',
' caseinfo ' varchar ($) Default null COMMENT ' case output information ',
' status ' varchar (6) default null COMMENT ' Validation result ',
' casebank ' varchar (+) default null COMMENT ' remarks ',
' casetime ' datetime DEFAULT null COMMENT ' execution time ',
' s Ystem ' varchar ' default null COMMENT ' system ',
' action ' varchar (a) default null COMMENT ' function ',
' imageinfo ' varchar ( () default null COMMENT ' picture information ',
' caser ' int (one) default null COMMENT ' Case point ',
PRIMARY KEY (' id ')
) Engine=inno DB auto_increment=1159 DEFAULT Charset=utf8;

‘‘‘

Insert = "INSERT INTO ' casedata ' (' casedata ', ' caseinfo ', ' status ', ' Casebank ', ' casetime ', ' system ', ' action ') VALUES (' SA Sdasd ', ' sadasd ', ' fase ', ' sdasd ', NULL, ' admin ', ' login ', ' caser ');
#访问数据库
Try
Conn =mysqldb.connect (host= "192.168.0.157", port=3306,user= "root", passwd= "123456", db= "WebTest", charset= "UTF8") # V35test_iapppay,webtest
Except Mysqldb.error as E:
Logging. ERROR (e)
Pass

#插入数据公共方法

def insertdata (str):
cursor = Conn.cursor ()
Try
Cursor.execute (str)
Conn.commit ()
Except Exception as E:
Logging. ERROR (e)
Pass
Conn.close

insertdata.py

#coding =utf-8
‘‘‘
Created on 2014?? 7?? 17??

@author: Ф Shaobin
‘‘‘
Import time

#获取当前时间

Def dateTime ():
Return Time.strftime ('%y-%m-%d%h:%s ', Time.localtime (Time.time ()))

#初始化生成insert SQL

def data (Casedata,caseinfo,status,casebank,casetime,system,action,imageinfo):
data = "INSERT INTO ' casedata ' (' casedata ', ' caseinfo ', ' status ', ' Casebank ', ' casetime ', ' system ', ' action ', ' Imageinfo ') VALUES (' "+casedata+" ', ' "+caseinfo+" ', ' "+status+" ', ' "+casebank+" ', ' "+casetime+" ', ' "+system+" ', ' "+action+" ', ' "+ imageinfo+ "');"
Return data

#对特殊字符处理

def Returnargs (*args):
data = ""
For I in (Range Len (args)):
Data + = str (args[i])
data = Data.replace ("'", "\ \")
return str (data)

#初始化时间插入sql

def runtimedata (starttime,endtime):
data = "INSERT into RunTime (starttime,endtime) VALUES ('" +starttime+ "', '" +endtime+ ");"
Return data

3.jsp page Access

<%@ page language= "java" contenttype= "text/html; charset=utf-8" pageencoding= "UTF-8" import= "java.sql.*"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd";
<%
String par = request.getparameter ("pay");
%>
<style media= "screen" type= "text/css";
Body {font-family:verdana, Arial, Helvetica, Sans-serif; font-size:80%; }
Table {font-size:100%;}
Pre {}
/*--heading----------------------------------------------------------------------*/
H1 {
font-size:16pt;
Color:gray;
}
. heading {
MARGIN-TOP:0EX;
Margin-bottom:1ex;
}
. Heading. attribute {
Margin-top:1ex;
margin-bottom:0;
}
. Heading. description {
Margin-top:4ex;
Margin-bottom:6ex;
}
. overflow{
Overflow:auto;
}
#show_detail_line {
Margin-top:3ex;
Margin-bottom:1ex;
}
</style>

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title> AI bei Automatic monitoring interface </title>
<body>

<script language= "javascript" type= "Text/javascript" >
alert (<%=par%>);
/* LEVEL-0:PASS; 1:false; 2:error 3:all */
function ShowCase (level) {
if (level = = 0) {
par = "Hello1";
alert (<%=par%>);
}
if (level = = 1) {
par = "Hello2";
alert (<%=par%>);
}
if (level = = 2) {
par = "Hello3";
alert (<%=par%>);
}
if (level = = 3) {
par = "Hello4";
alert (<%=par%>);
}
}


</script>
<div class= ' Heading ' >
<p class= ' attribute ' ><strong>start time:</strong> 2014-07-16 16:17:45</p>
<p class= ' attribute ' ><strong>Duration:</strong> 0:00:00.027000</p>
<p class= ' attribute ' ><strong>Status:</strong> pass 1 false 1 Error 1</p>
</div>
<p id= ' show_detail_line ' > Test results:
<a href= ' javascript:showcase (0) ' >Pass</a>
<a href= ' javascript:showcase (1) ' >false</a>
<a href= ' javascript:showcase (2) ' >Error</a>
<a href= ' javascript:showcase (3) ' >All</a>
</p>

<div class = ' Heading ' >
<table border=1 style= "Table-layout:fixed;word-wrap:break-word;" width= "100%" id = ' overflow ' >
<tr>
<td width = "3%" >ID</td>
<td width = "20%" > Test data </td>
<td width = "20%" > Test output </td>
<td width = "5%" > Test results </td>
<td width = "10%" > Test notes </td>
<td width = "10%" > Execution Time </td>
<td width = "5%" > System </td>
<td width = "5%" >action</td>
<td width = "5%" > Pictures </td>
</tr>
<%
Class.forName ("Com.mysql.jdbc.Driver"). newinstance ();
Connection con=java.sql.drivermanager.getconnection ("jdbc:mysql://192.168.0.157/webtest?useunicode=true& Characterencoding=utf-8 "," root "," 123456 ");
Statement stmt=con.createstatement ();
ResultSet rst=stmt.executequery ("Select Id,casedata,caseinfo,status,casebank,casetime,system,action,imageinfo From Casedata ORDER by id DESC ");
while (Rst.next ())
{
Out.println ("<tr>");
Out.println ("<td>" +rst.getstring ("id") + "</td>");
Out.println ("<td>" +rst.getstring ("Casedata") + "</td>");
Out.println ("<td>" +rst.getstring ("Caseinfo") + "</td>");
Out.println ("<td>" +rst.getstring ("status") + "</td>");
Out.println ("<td>" +rst.getstring ("Casebank") + "</td>");
Out.println ("<td>" +rst.getstring ("casetime") + "</td>");
Out.println ("<td>" +rst.getstring ("system") + "</td>");
Out.println ("<td>" +rst.getstring ("action") + "</td>");
Out.println ("<td>" +rst.getstring ("imageinfo") + "</td>");
Out.println ("<td>" + "Out.println ("</tr>");
}
Closing connections, freeing resources
Rst.close ();
Stmt.close ();
Con.close ();
%>
</table>
</div>
</body>

Note: The Com.mysql.jdbc.Driver lib package needs to be imported

Finally: here, a test report is set up, and finally the data is inserted into the data sheet.

Building the four test reports for the Web Automation framework

Related Article

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.