Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
study
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Li Yongyu
study
Commits
9f3a6729
Commit
9f3a6729
authored
Mar 12, 2019
by
Li Yongyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update frame
parent
957164c5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
478 additions
and
195 deletions
+478
-195
build.xml
studycenter_Api_auto_test/build.xml
+3
-4
offcn_api_testData.java
..._auto_test/src/com/offcn/TestData/offcn_api_testData.java
+1
-0
HttpRequest.java
...ter_Api_auto_test/src/com/offcn/TestUnti/HttpRequest.java
+1
-0
Mail.java
studycenter_Api_auto_test/src/com/offcn/TestUnti/Mail.java
+10
-9
MapUtil.java
...ycenter_Api_auto_test/src/com/offcn/TestUnti/MapUtil.java
+57
-19
MyNewMail.java
...enter_Api_auto_test/src/com/offcn/TestUnti/MyNewMail.java
+0
-0
ReadExcels.java
...nter_Api_auto_test/src/com/offcn/TestUnti/ReadExcels.java
+5
-0
Reflect_api.java
...ter_Api_auto_test/src/com/offcn/TestUnti/Reflect_api.java
+1
-1
RequestDataUtils.java
...pi_auto_test/src/com/offcn/TestUnti/RequestDataUtils.java
+0
-0
ZipUtils.java
...center_Api_auto_test/src/com/offcn/TestUnti/ZipUtils.java
+19
-2
fileUntil.java
...enter_Api_auto_test/src/com/offcn/TestUnti/fileUntil.java
+188
-0
MyTestListener.java
..._Api_auto_test/src/com/offcn/listener/MyTestListener.java
+46
-0
SkipIInvokedMethodListener.java
...st/src/com/offcn/listener/SkipIInvokedMethodListener.java
+145
-0
system.xml
studycenter_Api_auto_test/src/resources/system.xml
+0
-160
test.properties
studycenter_Api_auto_test/src/resources/test.properties
+2
-0
No files found.
studycenter_Api_auto_test/build.xml
View file @
9f3a6729
...
...
@@ -9,7 +9,7 @@
<property
name=
"srcdir"
location=
"src"
/>
<property
name=
"libdir"
location=
"lib"
/>
<property
name=
"full-compile"
value=
"true"
/>
<property
name=
"basedir"
value=
"
E:\git\study\studycenter_Api_auto_test
"
/>
<property
name=
"basedir"
value=
"
.
"
/>
<path
id=
"classpath.test"
>
<fileset
dir=
"${libdir}"
>
...
...
@@ -62,9 +62,8 @@
</target>
<target
name=
"testoutput"
depends=
"runtest"
>
<java
classname=
"com.offcn.TestUnti.Mail"
classpath=
"${basedir}/bin"
>
<sysproperty
key=
"file.encoding"
value=
"UTF-8"
/>
<java
classname=
"com.offcn.TestUnti.MyNewMail"
classpath=
"${basedir}/bin"
classpathref=
"classes"
>
<sysproperty
key=
"file.encoding"
value=
"UTF-8"
/>
<classpath>
<pathelement
location=
"lib/javax.mail.jar"
/>
</classpath>
...
...
studycenter_Api_auto_test/src/com/offcn/TestData/offcn_api_testData.java
View file @
9f3a6729
...
...
@@ -6,6 +6,7 @@ import com.offcn.TestUnti.ReadExcels;
import
com.offcn.TestUnti.ReadProperties
;
public
class
offcn_api_testData
{
public
static
int
Testcount
=
0
;
//总得用力数量
@DataProvider
(
name
=
"renmai"
)
public
static
Object
[][]
dp
(){
...
...
studycenter_Api_auto_test/src/com/offcn/TestUnti/HttpRequest.java
View file @
9f3a6729
...
...
@@ -52,6 +52,7 @@ public class HttpRequest {
try
{
// String urlNameString = url ;
String
urlNameString
=
url
+
"?"
+
param
;
// System.out.println(urlNameString);
URL
realUrl
=
new
URL
(
urlNameString
);
// 打开和URL之间的连接
URLConnection
connection
=
realUrl
.
openConnection
();
...
...
studycenter_Api_auto_test/src/com/offcn/TestUnti/Mail.java
View file @
9f3a6729
...
...
@@ -39,16 +39,16 @@ public class Mail {
}
}
// 发件人的 邮箱 和 密码(替换为自己的邮箱和密码)
public
static
String
myEmailAccount
=
"
lyyazxhhwj@163
.com"
;
public
static
String
myEmailPassword
=
"
liyyandzxx
"
;
public
static
String
myEmailAccount
=
"
53055975@qq
.com"
;
public
static
String
myEmailPassword
=
"
qoqfoabljzyzbjdd
"
;
// 发件人邮箱的 SMTP 服务器地址, 必须准确, 不同邮件服务器地址不同, 一般格式为: smtp.xxx.com
// 网易163邮箱的 SMTP 服务器地址为: smtp.163.com
or smtp.qq.com
public
static
String
myEmailSMTPHost
=
"smtp.
163
.com"
;
// 网易163邮箱的 SMTP 服务器地址为: smtp.163.com
public
static
String
myEmailSMTPHost
=
"smtp.
qq
.com"
;
// 收件人邮箱(替换为自己知道的有效邮箱)
// public static String receiveMailAccount = "liyongyu@offcn.com";//rmscrum.list@finupgroup.com
public
static
String
receiveMailAccount
=
"
liyongyu
@offcn.com"
;
//rmscrum.list@finupgroup.com
public
static
String
receiveMailAccount
=
"
yaoshuai
@offcn.com"
;
//rmscrum.list@finupgroup.com
public
static
void
POP3
()
throws
Exception
{
// 1. 创建参数配置, 用于连接邮件服务器的参数配置
...
...
@@ -128,7 +128,7 @@ public class Mail {
// 4. Subject: 邮件主题
Date
date
=
new
Date
();
String
time
=
new
SimpleDateFormat
(
"yyyyMMdd"
).
format
(
date
);
message
.
setSubject
(
"
学习中心&在线课堂
自动化测试报告-"
+
time
,
"UTF-8"
);
message
.
setSubject
(
"
nwn
自动化测试报告-"
+
time
,
"UTF-8"
);
/*
* 下面是邮件内容的创建:
...
...
@@ -254,10 +254,11 @@ public class Mail {
public
static
InternetAddress
[]
parseAddress
(
String
personnel
){
String
addr
=
""
;
if
(
"all"
.
equals
(
personnel
)){
addr
=
"liyongyu@offcn.com;"
+
"lyyazxhhwj@163.com;553834369@qq.com"
;
//失败接收人
addr
=
"wufeifei66504@offcn.com;wenshuang@offcn.com;liyongyu@offcn.com;"
+
"zhanghua54164@offcn.com;liwendong@offcn.com;cuimengzhen@offcn.com;"
+
"zhangshijie62302@offcn.com;baimanbin@offcn.com"
;
}
else
{
addr
=
"
553834369@qq.com;liyongyu@offcn.com"
;
// 成功接收人
addr
=
"
wufeifei66504@offcn.com;wenshuang@offcn.com;liyongyu@offcn.com"
;
}
StringTokenizer
token
=
new
StringTokenizer
(
addr
,
";"
);
...
...
studycenter_Api_auto_test/src/com/offcn/TestUnti/MapUtil.java
View file @
9f3a6729
...
...
@@ -2,8 +2,12 @@ package com.offcn.TestUnti;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.LinkedHashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
...
...
@@ -14,19 +18,58 @@ import net.sf.json.JSONObject;
public
class
MapUtil
{
public
static
void
main
(
String
[]
args
)
{
//"id":code,"status":"0"
String
string
=
getParameter
(
"\"id\":code,\"status\":\"0\""
,
"id"
);
System
.
out
.
println
(
string
);
// HashMap<String, Object> hm=new HashMap<String, Object>();
// hm.put("1", "a1");
// hm.put("statusCode", "a2");
// hm.put("3", "a3");
// hm.put("errcode", "a4");
// hm.put("5", "a5");
// hm.put("errmsg", "a6");
// HashMap<String, Object> newhm=Expect(hm);
// System.out.println("@AfterClass_data_ext="+JSONObject.fromObject(newhm).toString());
HashMap
<
String
,
Object
>
hm
=
new
HashMap
<
String
,
Object
>();
hm
.
put
(
"1"
,
"a1"
);
hm
.
put
(
"statusCode"
,
"a2"
);
hm
.
put
(
"3"
,
"a3"
);
hm
.
put
(
"errcode"
,
"a4"
);
hm
.
put
(
"5"
,
"a5"
);
hm
.
put
(
"errmsg"
,
"a6"
);
HashMap
<
String
,
Object
>
newhm
=
Expect
(
hm
);
System
.
out
.
println
(
"@AfterClass_data_ext="
+
JSONObject
.
fromObject
(
newhm
).
toString
());
}
//降序排序
public
static
<
K
,
V
extends
Comparable
<?
super
V
>>
Map
<
K
,
V
>
sortByValueDescending
(
Map
<
K
,
V
>
map
)
{
List
<
Map
.
Entry
<
K
,
V
>>
list
=
new
LinkedList
<
Map
.
Entry
<
K
,
V
>>(
map
.
entrySet
());
Collections
.
sort
(
list
,
new
Comparator
<
Map
.
Entry
<
K
,
V
>>()
{
@Override
public
int
compare
(
Map
.
Entry
<
K
,
V
>
o1
,
Map
.
Entry
<
K
,
V
>
o2
)
{
int
compare
=
(
o1
.
getValue
()).
compareTo
(
o2
.
getValue
());
return
-
compare
;
}
});
Map
<
K
,
V
>
result
=
new
LinkedHashMap
<
K
,
V
>();
for
(
Map
.
Entry
<
K
,
V
>
entry
:
list
)
{
result
.
put
(
entry
.
getKey
(),
entry
.
getValue
());
}
return
result
;
}
//升序排序
public
static
<
K
,
V
extends
Comparable
<?
super
V
>>
Map
<
K
,
V
>
sortByValueAscending
(
Map
<
K
,
V
>
map
)
{
List
<
Map
.
Entry
<
K
,
V
>>
list
=
new
LinkedList
<
Map
.
Entry
<
K
,
V
>>(
map
.
entrySet
());
Collections
.
sort
(
list
,
new
Comparator
<
Map
.
Entry
<
K
,
V
>>()
{
@Override
public
int
compare
(
Map
.
Entry
<
K
,
V
>
o1
,
Map
.
Entry
<
K
,
V
>
o2
)
{
int
compare
=
(
o1
.
getValue
()).
compareTo
(
o2
.
getValue
());
return
compare
;
}
});
Map
<
K
,
V
>
result
=
new
LinkedHashMap
<
K
,
V
>();
for
(
Map
.
Entry
<
K
,
V
>
entry
:
list
)
{
result
.
put
(
entry
.
getKey
(),
entry
.
getValue
());
}
return
result
;
}
//马洪亮
// 生成数组格式的json串
public
static
String
getArrayJson
(
String
para
)
{
...
...
@@ -213,11 +256,7 @@ public class MapUtil {
StringBuffer
sb
=
new
StringBuffer
();
for
(
int
k
=
0
;
k
<
comma
;
k
++){
//此时是多个,,,
String
[]
str
=
strcomma
[
k
].
split
(
"\":\""
);
if
(
str
.
length
==
1
){
str
=
strcomma
[
k
].
split
(
":"
);
}
String
[]
str
=
strcomma
[
k
].
split
(
":"
);
String
str_strcomma
=
Arrays
.
toString
(
str
);
// System.out.println("str="+Arrays.toString(str));
//按参数传过来的字符串做为子串,在以逗号为节点的串中分别查找子串的关键字,
...
...
@@ -240,9 +279,8 @@ public class MapUtil {
int
comma
=
strcomma
.
length
;
StringBuffer
sb
=
new
StringBuffer
();
for
(
int
k
=
0
;
k
<
comma
;
k
++){
String
str_strcomma_s
=
strcomma
[
k
].
split
(
"="
)[
0
];
String
str_strcomma
=
strcomma
[
k
];
if
(
str_strcomma
_s
.
equal
s
(
Letter
)){
if
(
str_strcomma
.
contain
s
(
Letter
)){
int
start
=
str_strcomma
.
indexOf
(
'='
);
sb
.
append
(
str_strcomma
.
substring
(
start
+
1
,
str_strcomma
.
length
()));
return
sb
.
toString
();
...
...
studycenter_Api_auto_test/src/com/offcn/TestUnti/MyNewMail.java
0 → 100644
View file @
9f3a6729
This diff is collapsed.
Click to expand it.
studycenter_Api_auto_test/src/com/offcn/TestUnti/ReadExcels.java
View file @
9f3a6729
...
...
@@ -15,6 +15,8 @@ import org.apache.poi.ss.usermodel.Sheet;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.apache.poi.ss.usermodel.WorkbookFactory
;
import
com.offcn.TestData.offcn_api_testData
;
public
class
ReadExcels
{
private
String
fileName
;
private
String
SheetName
;
...
...
@@ -64,6 +66,9 @@ public class ReadExcels {
list
.
add
(
getCellValue
(
cell
));
}
}
offcn_api_testData
.
Testcount
=
arrmap
.
length
;
//保存总体的用例数量
Log
.
logInfo
(
"数据源读取记录:共有几列数据="
+
list
.
size
());
Log
.
logInfo
(
"数据源读取记录:共有几行数据="
+
arrmap
.
length
);
for
(
int
i
=
1
;
i
<
sheet
.
getPhysicalNumberOfRows
()
;
i
++){
...
...
studycenter_Api_auto_test/src/com/offcn/TestUnti/Reflect_api.java
View file @
9f3a6729
...
...
@@ -89,7 +89,7 @@ public class Reflect_api {
// }
// }
if
(
"
study
"
.
equals
(
system
)){
if
(
"
nwn
"
.
equals
(
system
)){
String
classReflectName
=
ReadProperties
.
GetPropertyByClassName
(
serviceUrl
);
if
(
classReflectName
!=
null
)
{
return
classRoute
+
classReflectName
;
...
...
studycenter_Api_auto_test/src/com/offcn/TestUnti/RequestDataUtils.java
View file @
9f3a6729
This diff is collapsed.
Click to expand it.
studycenter_Api_auto_test/src/com/offcn/TestUnti/ZipUtils.java
View file @
9f3a6729
...
...
@@ -17,7 +17,7 @@ import java.util.zip.ZipOutputStream;
* @author ZENG.XIAO.YAN
* @date 2017年11月19日 下午7:16:08
* @date 2017年11月19日 下午7:16:08
11
* @version v1.0
...
...
@@ -289,9 +289,10 @@ public class ZipUtils {
public
static
boolean
ZipTestResult
(
String
mailpath
){
deleteFile
(
mailpath
+
"测试报告详细资料.zip"
);
//删除文件
List
<
File
>
fileList
=
new
ArrayList
<>();
// fileList.add(new File(mailpath));
fileList
.
add
(
new
File
(
mailpath
+
"index.html"
));
fileList
.
add
(
new
File
(
mailpath
+
"overview.html"
));
fileList
.
add
(
new
File
(
mailpath
+
"reportng.css"
));
...
...
@@ -314,4 +315,20 @@ public class ZipUtils {
}
public
static
boolean
deleteFile
(
String
fileName
)
{
File
file
=
new
File
(
fileName
);
// 如果文件路径所对应的文件存在,并且是一个文件,则直接删除
if
(
file
.
exists
()
&&
file
.
isFile
())
{
if
(
file
.
delete
())
{
System
.
out
.
println
(
"删除单个文件"
+
fileName
+
"成功!"
);
return
true
;
}
else
{
System
.
out
.
println
(
"删除单个文件"
+
fileName
+
"失败!"
);
return
false
;
}
}
else
{
System
.
out
.
println
(
"删除单个文件失败:"
+
fileName
+
"不存在!"
);
return
false
;
}
}
}
studycenter_Api_auto_test/src/com/offcn/TestUnti/fileUntil.java
0 → 100644
View file @
9f3a6729
package
com
.
offcn
.
TestUnti
;
import
java.io.BufferedReader
;
import
java.io.BufferedWriter
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.OutputStreamWriter
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Set
;
import
com.offcn.listener.SkipIInvokedMethodListener
;
public
class
fileUntil
{
public
static
void
main
(
String
[]
args
)
{
try
{
readFile_
(
"caseOut.txt"
);
// WriterFile("12345");
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
public
static
String
readFile_
(
String
filename
)
throws
IOException
{
File
directory
=
new
File
(
"."
);
String
sourceFile
=
directory
.
getCanonicalPath
()
+
File
.
separator
+
"src"
+
File
.
separator
+
"resources"
+
File
.
separator
+
filename
;
FileInputStream
fis
=
new
FileInputStream
(
sourceFile
);
byte
[]
buf
=
new
byte
[
1024
];
int
len
=
0
;
StringBuffer
sb
=
new
StringBuffer
();
while
((
len
=
fis
.
read
(
buf
))!=-
1
){
sb
.
append
(
new
String
(
buf
,
0
,
len
));
// System.out.println(new String(buf,0,len));
}
fis
.
close
();
return
sb
.
toString
();
}
public
boolean
WriterFile
(
List
<
Set
<
String
>>
listt
){
File
directory
=
new
File
(
"."
);
String
sourceFile
;
try
{
sourceFile
=
directory
.
getCanonicalPath
()
+
File
.
separator
+
"src"
+
File
.
separator
+
"resources"
+
File
.
separator
+
"case.txt"
;
BufferedWriter
bw
=
new
BufferedWriter
(
new
FileWriter
(
sourceFile
));
String
cases
=
""
;
for
(
int
i
=
0
;
i
<
listt
.
size
();
i
++){
Object
[]
obj
=
listt
.
get
(
i
).
toArray
();
cases
=
Arrays
.
toString
(
obj
).
trim
();
cases
=
cases
.
substring
(
1
,
cases
.
length
()-
1
);
bw
.
write
(
cases
);
bw
.
newLine
();
}
bw
.
flush
();
bw
.
close
();
return
true
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
false
;
}
public
static
boolean
WriterFile_map
(
Integer
Percentage
){
File
directory
=
new
File
(
"."
);
String
sourceFile
;
try
{
sourceFile
=
directory
.
getCanonicalPath
()
+
File
.
separator
+
"src"
+
File
.
separator
+
"resources"
+
File
.
separator
+
"map.txt"
;
BufferedWriter
bw
=
new
BufferedWriter
((
new
OutputStreamWriter
(
new
FileOutputStream
(
sourceFile
),
"utf-8"
)));
String
cases
=
""
;
SkipIInvokedMethodListener
.
serviceUrlMap
=(
HashMap
<
String
,
Integer
>)
MapUtil
.
sortByValueDescending
(
SkipIInvokedMethodListener
.
serviceUrlMap
);
Set
<
String
>
keySet
=
SkipIInvokedMethodListener
.
serviceUrlMap
.
keySet
();
//有了Set集合。就可以获取其迭代器。
Iterator
<
String
>
it
=
keySet
.
iterator
();
boolean
sm
=
true
;
while
(
it
.
hasNext
()){
String
key
=
it
.
next
();
if
(
sm
){
cases
=
"<font size='4' color='#FF0000'>流程错误列表</font><table border='1'><th>URL</th><th>错误次数</th>"
;
bw
.
write
(
cases
);
bw
.
newLine
();
sm
=
false
;
}
//有了键可以通过map集合的get方法获取其对应的值。
Integer
value
=
SkipIInvokedMethodListener
.
serviceUrlMap
.
get
(
key
);
cases
=
"<tr><td>"
+
key
+
"</td><td>错误了"
+
value
+
"次。</td></tr>"
;
bw
.
write
(
cases
);
bw
.
newLine
();
}
if
(!
sm
){
cases
=
"</table>"
;
bw
.
write
(
cases
);
bw
.
newLine
();
}
boolean
asd
=
true
;
Set
<
String
>
keySet1
=
SkipIInvokedMethodListener
.
SkipMap
.
keySet
();
//有了Set集合。就可以获取其迭代器。
Iterator
<
String
>
it1
=
keySet1
.
iterator
();
while
(
it1
.
hasNext
()){
String
key1
=
it1
.
next
();
//有了键可以通过map集合的get方法获取其对应的值。
String
value1
=
SkipIInvokedMethodListener
.
SkipMap
.
get
(
key1
);
String
[]
valuearr
=
value1
.
split
(
"____"
);
double
v1
=
Double
.
valueOf
(
valuearr
[
0
]);
value1
=
valuearr
[
1
];
if
(
v1
>
Percentage
){
if
(
asd
){
cases
=
"<font size='4' color='#FF0000'>场景错误列表</font><table border='1'><th>包含错误的场景名称</th><th>场景包含错误案例数量</th><th>错误占比</th>"
;
bw
.
write
(
cases
);
bw
.
newLine
();
asd
=
false
;
}
cases
=
"<tr><td><font size='3' color='#0000CD'>"
+
key1
+
"</font></td>"
+
"<td><font size='3' color='#0000CD'>"
+
value1
+
"</font></td>"
+
"<td><font size='3' color='#0000CD'>"
+
v1
+
"%</font></td></tr>"
;
bw
.
write
(
cases
);
bw
.
newLine
();
}
}
if
(!
asd
){
cases
=
"</table>"
;
bw
.
write
(
cases
);
bw
.
newLine
();
}
bw
.
flush
();
bw
.
close
();
return
true
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
false
;
}
/**
* BufferedReader bufr = new BufferedReader(fr);
String line = null;
while((line=bufr.readLine())!=null)
{
System.out.print(line);
}
bufr.close();
*/
public
static
String
readFile_line
(
String
filename
)
throws
IOException
{
File
directory
=
new
File
(
"."
);
String
sourceFile
=
directory
.
getCanonicalPath
()
+
File
.
separator
+
"src"
+
File
.
separator
+
"resources"
+
File
.
separator
+
filename
;
BufferedReader
in
=
new
BufferedReader
(
new
InputStreamReader
(
new
FileInputStream
(
sourceFile
),
"utf-8"
));
BufferedReader
bufr
=
new
BufferedReader
(
in
);
String
line
=
null
;
StringBuffer
sb
=
new
StringBuffer
();
while
((
line
=
bufr
.
readLine
())!=
null
)
{
sb
.
append
(
line
);
}
bufr
.
close
();
in
.
close
();
return
sb
.
toString
();
}
}
studycenter_Api_auto_test/src/com/offcn/listener/MyTestListener.java
0 → 100644
View file @
9f3a6729
package
com
.
offcn
.
listener
;
import
org.testng.ITestContext
;
import
org.testng.ITestListener
;
import
org.testng.ITestResult
;
import
com.offcn.TestUnti.ReadProperties
;
import
com.offcn.TestUnti.fileUntil
;
public
class
MyTestListener
implements
ITestListener
{
public
static
Integer
SkippedCount
=
0
;
@Override
public
void
onFinish
(
ITestContext
arg0
)
{
String
Percentage
=
ReadProperties
.
GetTestPropertyByKey
(
"Percentage"
);
Integer
Percentage_Integer
=
Integer
.
valueOf
(
Percentage
);
fileUntil
.
WriterFile_map
(
Percentage_Integer
);
}
@Override
public
void
onStart
(
ITestContext
arg0
)
{
}
@Override
public
void
onTestFailedButWithinSuccessPercentage
(
ITestResult
arg0
)
{
}
@Override
public
void
onTestFailure
(
ITestResult
arg0
)
{
}
@Override
public
void
onTestSkipped
(
ITestResult
arg0
)
{
SkippedCount
++;
}
@Override
public
void
onTestStart
(
ITestResult
arg0
)
{
}
@Override
public
void
onTestSuccess
(
ITestResult
arg0
)
{
}
}
studycenter_Api_auto_test/src/com/offcn/listener/SkipIInvokedMethodListener.java
0 → 100644
View file @
9f3a6729
package
com
.
offcn
.
listener
;
import
java.math.BigDecimal
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
org.testng.IInvokedMethod
;
import
org.testng.IInvokedMethodListener
;
import
org.testng.ITestResult
;
import
org.testng.SkipException
;
import
com.offcn.TestData.offcn_api_testData
;
import
com.offcn.TestUnti.Log
;
public
class
SkipIInvokedMethodListener
implements
IInvokedMethodListener
{
//需求1,流程错误案例
public
static
String
Parameter_TCNO
=
""
;
//当前场景名称
public
static
String
Parameter_ServiceUrl
=
""
;
//错误的流程url
public
static
HashMap
<
String
,
Integer
>
serviceUrlMap
=
new
HashMap
<
String
,
Integer
>();
public
static
boolean
Success
=
true
;
//场景测试的状态,发生错误false,未发生错误true
//需求2,模块错误案例占比,数量
public
static
Integer
Parameter_TCNO_count
=
0
;
//存在错误的场景总数
public
static
Integer
SkipTestnumber
=
0
;
//错误用例次数
public
static
HashMap
<
String
,
String
>
SkipMap
=
new
HashMap
<
String
,
String
>();
//错误比例
//测试结果是成功还是失败还是跳过
public
static
Integer
resultStatus
=
0
;
//运行之前
@Override
public
void
beforeInvocation
(
IInvokedMethod
Method
,
ITestResult
result
)
{
//获取方法名称
String
MethodName
=
Method
.
getTestMethod
().
getMethodName
();
Object
s
[]=
result
.
getParameters
();
if
(
s
.
length
==
1
){
//当可以获取到用例的时候
String
Step
=
getParameter
(
Arrays
.
toString
(
s
),
"Step"
);
String
TCNO
=
getParameter
(
Arrays
.
toString
(
s
),
"TCNO"
);
String
[]
Parameters
=
TCNO
.
split
(
"_"
);
TCNO
=
Parameters
[
0
];
//查看是否上一条是错误的(错误场景名称和当前场景名称一致),并且当前用例Step不等于1,都满足就跳过当前即将要运行的这条
int
IntegerStep
=
Integer
.
parseInt
(
Step
.
trim
());
if
(
IntegerStep
!=
1
&&
!
Success
&&
"f"
.
equals
(
MethodName
)){
Log
.
logInfo
(
"跳过"
);
if
(
resultStatus
!=
3
){
recordTases
(
Parameter_ServiceUrl
);
//流程错误案例保存上一条的信息和次数
}
throw
new
SkipException
(
"skip the test"
);
}
else
if
(
IntegerStep
==
1
&&
TCNO
.
equals
(
Parameter_TCNO
)
&&
"f"
.
equals
(
MethodName
)){
//遇到1,场景状态清除
Success
=
true
;
}
else
if
(
IntegerStep
==
1
&&
!
TCNO
.
equals
(
Parameter_TCNO
)
&&
"f"
.
equals
(
MethodName
)
&&
Parameter_TCNO_count
!=
0
){
//计算该场景错误用例比例和该场景的错误案例数量
Success
=
true
;
double
TCNO_double
=
SkipTestnumber
/(
Parameter_TCNO_count
*
1.0
);
TCNO_double
=
m1
(
TCNO_double
*
100
);
SkipMap
.
put
(
Parameter_TCNO
,
TCNO_double
+
"____"
+
SkipTestnumber
);
SkipTestnumber
=
0
;
Parameter_TCNO
=
""
;
}
}
}
@Override
public
void
afterInvocation
(
IInvokedMethod
Method
,
ITestResult
result
)
{
try
{
resultStatus
=
result
.
getStatus
();
//获取方法名称
String
MethodName
=
Method
.
getTestMethod
().
getMethodName
();
Object
s111
[]=
result
.
getParameters
();
String
NO
=
getParameter
(
Arrays
.
toString
(
s111
),
"NO"
);
if
(
s111
.
length
==
1
){
//当可以获取到用例的时候
if
(!
result
.
isSuccess
()
&&
"f"
.
equals
(
MethodName
)){
SkipTestnumber
++;
Success
=
false
;
//记录本条用例错误,在下条用例前调用查看
//只要有错误就记录,用例名称、url、步骤数
Object
s
[]=
result
.
getParameters
();
Parameter_ServiceUrl
=
getParameter
(
Arrays
.
toString
(
s
),
"serviceUrl"
);
// recordTases(Parameter_ServiceUrl);
String
TCNO
=
getParameter
(
Arrays
.
toString
(
s
),
"TCNO"
);
String
[]
Parameters
=
TCNO
.
split
(
"_"
);
Parameter_TCNO
=
Parameters
[
0
];
Parameter_TCNO_count
=
Integer
.
valueOf
(
Parameters
[
1
]);
}
if
(
offcn_api_testData
.
Testcount
==
Integer
.
valueOf
(
NO
)
&&
!
Success
){
Success
=
true
;
double
TCNO_double
=
SkipTestnumber
/(
Parameter_TCNO_count
*
1.0
);
TCNO_double
=
m1
(
TCNO_double
*
100
);
SkipMap
.
put
(
Parameter_TCNO
,
TCNO_double
+
"____"
+
SkipTestnumber
);
SkipTestnumber
=
0
;
Parameter_TCNO
=
""
;
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
//记录测试过程中流程用例的错误数量
public
static
void
recordTases
(
String
serviceUrlName
){
Integer
value
=
serviceUrlMap
.
get
(
serviceUrlName
);
int
count
=
1
;
if
(
value
==
null
){
serviceUrlMap
.
put
(
serviceUrlName
,
count
);
}
else
{
serviceUrlMap
.
put
(
serviceUrlName
,
++
value
);
}
}
//在parameter中查看,是否有(第二个参数)verifyCode的关键字,有的话返回他的字母值
public
static
String
getParameter
(
String
parameter
,
String
Letter
){
if
(
parameter
==
null
){
return
""
;
}
String
[]
strcomma
=
parameter
.
split
(
","
);
int
comma
=
strcomma
.
length
;
StringBuffer
sb
=
new
StringBuffer
();
for
(
int
k
=
0
;
k
<
comma
;
k
++){
//此时是多个,,,
String
[]
str
=
strcomma
[
k
].
split
(
"="
);
String
str_strcomma
=
Arrays
.
toString
(
str
);
// System.out.println("str="+Arrays.toString(str));
//按参数传过来的字符串做为子串,在以逗号为节点的串中分别查找子串的关键字,
//在找到后的位置开始查找数字,最后把数字的字符串返回
if
(
str_strcomma
.
contains
(
Letter
)){
int
start
=
str_strcomma
.
indexOf
(
','
);
sb
.
append
(
str_strcomma
.
substring
(
start
+
2
,
str_strcomma
.
length
()-
1
));
return
sb
.
toString
();
}
}
return
sb
.
toString
();
}
public
double
m1
(
double
f
)
{
BigDecimal
bg
=
null
;
//new BigDecimal(f);
bg
=
BigDecimal
.
valueOf
(
f
);
double
f1
=
bg
.
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
).
doubleValue
();
return
f1
;
}
}
studycenter_Api_auto_test/src/resources/system.xml
View file @
9f3a6729
...
...
@@ -47,164 +47,5 @@
<sqlpwd>
offcn.com
</sqlpwd>
</system>
<system
name=
"xyzbxs"
>
<!-- 小雨直播 线上环境-->
<access_token_uri>
http://106.75.5.205:8082/uaa/oauth/token
</access_token_uri>
<client_id>
bestbuy-acceptance
</client_id>
<client_secret>
bestbuy-acceptance
</client_secret>
<grant_type>
client_credentials
</grant_type>
<isProduct>
N
</isProduct>
<RM_URI>
http://live.offcncloud.com
</RM_URI>
<RM_port></RM_port>
<RM_basePath></RM_basePath>
<redis_URI>
10.10.229.48
</redis_URI>
<redis_db_index>
5
</redis_db_index>
<sqlurl>
jdbc:mysql://59.110.207.90:3306/xyu?useUnicode=true
&
characterEncoding=UTF-8
&
zeroDateTimeBehavior=convertToNull
</sqlurl>
<sqlname>
master
</sqlname>
<sqlpwd>
EDCdd22LLZBCADF123
</sqlpwd>
</system>
<system
name=
"tk"
>
<!-- 题库 -->
<access_token_uri>
http://106.75.5.205:8082/uaa/oauth/token
</access_token_uri>
<client_id>
bestbuy-acceptance
</client_id>
<client_secret>
bestbuy-acceptance
</client_secret>
<grant_type>
client_credentials
</grant_type>
<isProduct>
false
</isProduct>
<RM_URI>
http://test.tiku.eoffcn.com
</RM_URI>
<RM_port></RM_port>
<RM_basePath></RM_basePath>
<redis_URI>
10.10.229.48
</redis_URI>
<redis_db_index>
5
</redis_db_index>
<sqlurl>
jdbc:mysql://180.76.155.235:3306/tiku?useUnicode=true
&
characterEncoding=UTF-8
&
zeroDateTimeBehavior=convertToNull
</sqlurl>
<sqlname>
tiku
</sqlname>
<sqlpwd>
PFQ6nJ7YlG8Y
</sqlpwd>
</system>
<system
name=
"tkxs"
>
<!-- 题库线上环境 -->
<access_token_uri>
http://106.75.5.205:8082/uaa/oauth/token
</access_token_uri>
<client_id>
bestbuy-acceptance
</client_id>
<client_secret>
bestbuy-acceptance
</client_secret>
<grant_type>
client_credentials
</grant_type>
<isProduct>
false
</isProduct>
<RM_URI>
http://test.tiku.eoffcn.com
</RM_URI>
<RM_port></RM_port>
<RM_basePath></RM_basePath>
<redis_URI>
10.10.229.48
</redis_URI>
<redis_db_index>
5
</redis_db_index>
<sqlurl>
jdbc:mysql://180.76.155.235:3306/tiku?useUnicode=true
&
characterEncoding=UTF-8
&
zeroDateTimeBehavior=convertToNull
</sqlurl>
<sqlname>
tiku
</sqlname>
<sqlpwd>
PFQ6nJ7YlG8Y
</sqlpwd>
</system>
<system
name=
"nwn"
>
<!-- nwn -->
<access_token_uri>
http://106.75.5.205:8082/uaa/oauth/token
</access_token_uri>
<client_id>
bestbuy-acceptance
</client_id>
<client_secret>
bestbuy-acceptance
</client_secret>
<grant_type>
client_credentials
</grant_type>
<isProduct>
false
</isProduct>
<RM_URI>
http://beta.alitest.eoffcn.com
</RM_URI>
<RM_port></RM_port>
<RM_basePath></RM_basePath>
<redis_URI>
10.10.229.48
</redis_URI>
<redis_db_index>
5
</redis_db_index>
<sqlurl>
jdbc:mysql://39.105.124.219:3312/nwn?useUnicode=true
&
characterEncoding=UTF-8
&
zeroDateTimeBehavior=convertToNull
</sqlurl>
<sqlname>
nwnBeta
</sqlname>
<sqlpwd>
Beta@
&
123
</sqlpwd>
</system>
<system
name=
"nwn_service"
>
<!-- nwn -->
<access_token_uri>
http://106.75.5.205:8082/uaa/oauth/token
</access_token_uri>
<client_id>
bestbuy-acceptance
</client_id>
<client_secret>
bestbuy-acceptance
</client_secret>
<grant_type>
client_credentials
</grant_type>
<isProduct>
false
</isProduct>
<RM_URI>
http://beta.alitest.eoffcn.com
</RM_URI>
<RM_port></RM_port>
<RM_basePath></RM_basePath>
<redis_URI>
10.10.229.48
</redis_URI>
<redis_db_index>
5
</redis_db_index>
<sqlurl>
jdbc:mysql://39.105.124.219:3312/nwn?useUnicode=true
&
characterEncoding=UTF-8
&
zeroDateTimeBehavior=convertToNull
</sqlurl>
<sqlname>
nwnBeta
</sqlname>
<sqlpwd>
Beta@
&
123
</sqlpwd>
</system>
<system
name=
"nwn_ht"
>
<!-- nwn -->
<access_token_uri>
http://106.75.5.205:8082/uaa/oauth/token
</access_token_uri>
<client_id>
bestbuy-acceptance
</client_id>
<client_secret>
bestbuy-acceptance
</client_secret>
<grant_type>
client_credentials
</grant_type>
<isProduct>
false
</isProduct>
<RM_URI>
http://beta.alitest.eoffcn.com
</RM_URI>
<RM_port></RM_port>
<RM_basePath></RM_basePath>
<redis_URI>
10.10.229.48
</redis_URI>
<redis_db_index>
5
</redis_db_index>
<sqlurl>
jdbc:mysql://39.105.124.219:3312/nwn?useUnicode=true
&
characterEncoding=UTF-8
&
zeroDateTimeBehavior=convertToNull
</sqlurl>
<sqlname>
nwnBeta
</sqlname>
<sqlpwd>
Beta@
&
123
</sqlpwd>
</system>
<system
name=
"nwn_template"
>
<!-- nwn -->
<access_token_uri>
http://106.75.5.205:8082/uaa/oauth/token
</access_token_uri>
<client_id>
bestbuy-acceptance
</client_id>
<client_secret>
bestbuy-acceptance
</client_secret>
<grant_type>
client_credentials
</grant_type>
<isProduct>
false
</isProduct>
<RM_URI>
http://beta.alitest.eoffcn.com
</RM_URI>
<RM_port></RM_port>
<RM_basePath></RM_basePath>
<redis_URI>
10.10.229.48
</redis_URI>
<redis_db_index>
5
</redis_db_index>
<sqlurl>
jdbc:mysql://39.105.124.219:3312/nwn_template?useUnicode=true
&
characterEncoding=UTF-8
&
zeroDateTimeBehavior=convertToNull
</sqlurl>
<sqlname>
nwnBeta
</sqlname>
<sqlpwd>
Beta@
&
123
</sqlpwd>
</system>
<system
name=
"nwn_package"
>
<!-- nwn -->
<access_token_uri>
http://106.75.5.205:8082/uaa/oauth/token
</access_token_uri>
<client_id>
bestbuy-acceptance
</client_id>
<client_secret>
bestbuy-acceptance
</client_secret>
<grant_type>
client_credentials
</grant_type>
<isProduct>
false
</isProduct>
<RM_URI>
http://beta.alitest.eoffcn.com
</RM_URI>
<RM_port></RM_port>
<RM_basePath></RM_basePath>
<redis_URI>
10.10.229.48
</redis_URI>
<redis_db_index>
5
</redis_db_index>
<sqlurl>
jdbc:mysql://39.105.124.219:3312/nwn_pack?useUnicode=true
&
characterEncoding=UTF-8
&
zeroDateTimeBehavior=convertToNull
</sqlurl>
<sqlname>
nwnBeta
</sqlname>
<sqlpwd>
Beta@
&
123
</sqlpwd>
</system>
<system
name=
"nwnht"
>
<!-- nwn后台 -->
<access_token_uri>
http://106.75.5.205:8082/uaa/oauth/token
</access_token_uri>
<client_id>
bestbuy-acceptance
</client_id>
<client_secret>
bestbuy-acceptance
</client_secret>
<grant_type>
client_credentials
</grant_type>
<isProduct>
false
</isProduct>
<RM_URI>
http://zgadmin.test.eoffcn.com
</RM_URI>
<RM_port></RM_port>
<RM_basePath></RM_basePath>
<redis_URI>
10.10.229.48
</redis_URI>
<redis_db_index>
5
</redis_db_index>
<sqlurl>
jdbc:mysql://39.105.124.219:3312/nwn?useUnicode=true
&
characterEncoding=UTF-8
&
zeroDateTimeBehavior=convertToNull
</sqlurl>
<sqlname>
nwnBeta
</sqlname>
<sqlpwd>
Beta@
&
123
</sqlpwd>
</system>
<system
name=
"nwngg"
>
<!-- nwn公共类 -->
<access_token_uri>
http://106.75.5.205:8082/uaa/oauth/token
</access_token_uri>
<client_id>
bestbuy-acceptance
</client_id>
<client_secret>
bestbuy-acceptance
</client_secret>
<grant_type>
client_credentials
</grant_type>
<isProduct>
false
</isProduct>
<RM_URI>
https://nwn.eoffcn.com
</RM_URI>
<RM_port></RM_port>
<RM_basePath></RM_basePath>
<redis_URI>
10.10.229.48
</redis_URI>
<redis_db_index>
5
</redis_db_index>
<sqlurl>
jdbc:mysql://39.105.124.219:3312/nwn?useUnicode=true
&
characterEncoding=UTF-8
&
zeroDateTimeBehavior=convertToNull
</sqlurl>
<sqlname>
nwnBeta
</sqlname>
<sqlpwd>
Beta@
&
123
</sqlpwd>
</system>
</systems>
\ No newline at end of file
studycenter_Api_auto_test/src/resources/test.properties
View file @
9f3a6729
xls
=
DataAll.xls
sheet
=
try
mysql_local_Online
=
local
Percentage
=
10
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment