com.github.lwfwind.automation:smart-api-framework

Support web service api automaton test based on testng and httpclient

Лицензия

Лицензия

Категории

Категории

Auto Библиотеки уровня приложения Code Generators
Группа

Группа

com.github.lwfwind.automation
Идентификатор

Идентификатор

smart-api-framework
Последняя версия

Последняя версия

2.5
Дата

Дата

Тип

Тип

jar
Описание

Описание

Support web service api automaton test based on testng and httpclient
Ссылка на сайт

Ссылка на сайт

https://github.com/lwfwind/smart-api-framework
Система контроля версий

Система контроля версий

https://github.com/lwfwind/smart-api-framework

Скачать smart-api-framework

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.github.lwfwind.automation/smart-api-framework/ -->
<dependency>
    <groupId>com.github.lwfwind.automation</groupId>
    <artifactId>smart-api-framework</artifactId>
    <version>2.5</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.lwfwind.automation/smart-api-framework/
implementation 'com.github.lwfwind.automation:smart-api-framework:2.5'
// https://jarcasting.com/artifacts/com.github.lwfwind.automation/smart-api-framework/
implementation ("com.github.lwfwind.automation:smart-api-framework:2.5")
'com.github.lwfwind.automation:smart-api-framework:jar:2.5'
<dependency org="com.github.lwfwind.automation" name="smart-api-framework" rev="2.5">
  <artifact name="smart-api-framework" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.lwfwind.automation', module='smart-api-framework', version='2.5')
)
libraryDependencies += "com.github.lwfwind.automation" % "smart-api-framework" % "2.5"
[com.github.lwfwind.automation/smart-api-framework "2.5"]

Зависимости

compile (16)

Идентификатор библиотеки Тип Версия
org.testng : testng jar 6.8.5
com.github.lwfwind.common : java-common-helper jar 2.6
dom4j : dom4j jar 1.6.1
mysql : mysql-connector-java jar 5.1.37
org.apache.httpcomponents : httpclient jar 4.5
log4j : log4j jar 1.2.17
commons-dbutils : commons-dbutils jar 1.6
org.apache.commons : commons-lang3 jar 3.4
xmlunit : xmlunit jar 1.3
jaxen : jaxen jar 1.1.6
xml-apis : xml-apis jar 1.4.01
commons-dbcp : commons-dbcp jar 1.4
net.sf.jacob-project : jacob jar 1.14.3
commons-net : commons-net jar 3.0.1
com.thoughtworks.qdox : qdox jar 1.12.1
commons-cli : commons-cli jar 1.4

Модули Проекта

Данный проект не имеет модулей.

Smart-api-framework - a light, common http api automation framework

Smart-api-framework is a light, common http api automation framework based on TestNG and HttpClient.

  • Tags: TestNG, HttpClient, XML, API, Automation, Test, Keyword-driver

Features

  • Support keyword-driver, no coding and easy to config
  • Support to execute run/debug test from xml directly due to the intellij idea plugin Aping
  • Support restful web server such as get, post, put and delete http method
  • Support concurrent
  • Re-run failed test cases
  • Easy integration with CI system

Architecture

Architecture

XML Structure

TestSuite -- config test url and httpMethod
    Function -- shared method for all case in current suite, only init once
    TestCase
        Before -- preset environment such as database
        Setup -- config setup url and httpMethod, such as login action
            Param -- config setup parameters
        Headers -- config request headers 
            Header -- config Header parameters
            Cookie -- config Cookie parameters
        Param -- config test parameters
        ExpectResults -- config expect result
            Contain	-- assert actual result contain specify string
            Pair -- assert actual result contain specify key-value
            AssertTrue -- assert expression is true
        After -- reset environment

Example

   Support shared function for all case in current suite, only init once

<TestSuite url="getMethod?" httpMethod="get">
    <Function name="suiteFunctionValue" clsName="test.java.LogicHandler" methodName="getSuiteFunctionValue" arguments="7936160"/>
    <Function name="SuiteFunctionMap" clsName="test.java.LogicHandler" methodName="getSuiteFunctionMap"/>
    <TestCase name="getMethod" desc="getMethod">
        <Before>
            <Function clsName="test.java.LogicHandler" methodName="update" arguments="1,0"/>
        </Before>
        <Setup name="setup" url="login" httpMethod="post">
            <Param name="username" value="13636426195">
            </Param>
            <Param name="password" value="bddeaa7037632c856a6b83e4037f314a" />
        </Setup>
        <Headers>
            <Header name="m-appkey" value="4272" />
            <Cookie name="unb" value="2020967487" />
        </Headers>
        <Param name="parameter1" value="#setup.errorCode+1#" />
        <Param name="parameter2" value="#suiteFunctionValue#" />
        <Param name="parameter3" value="#SuiteFunctionMap.key#" />
        <ExpectResults>
            <Pair>errorCode:#setup.errorCode#或者#setup.errorCode+1#</Pair>
            <Pair>errorMsg:约课成功</Pair>
            <Pair>errorMsg:#if(setup.errorCode==200){
                return "约课成功";
                }
                return "约课失败";#</Pair>
            <Contain>.*errorMsg.*</Contain>
        </ExpectResults>
        <After>
            <Function clsName="test.java.LogicHandler" methodName="reset"/>
        </After>
    </TestCase>
</TestSuite>

   Support function/sql action in before/after

<TestSuite url="V1/Students/login" httpMethod="post">
    <TestCase name="data1" desc="更改手机号登录">
        <Before>
            <Function clsName="test.java.LogicHandler" methodName="changeStudentsMobile" arguments="1"/>
            <Sql>update ebk_students set mobile=18078788787 where id=123456;</Sql>
        </Before>
        <Param name="username" value="#sql1.mobile#">
            <Sql name="sql">select trim(mobile) as mobile,password from ebk_students where id=123456;
            </Sql>
        </Param>
        <Param name="password" value="#sql.password#" />
        <ExpectResults>
            <Pair>errorCode:200</Pair>
            <Pair>errorMsg:登录成功</Pair>
        </ExpectResults>
        <After>
            <Function clsName="test.java.LogicHandler" methodName="resertStudentMobile"/>
            <Sql>update ebk_students set mobile=888888888 where id=123456;</Sql>
        </After>
    </TestCase>
</TestSuite>

   Support execute setup action before execution of test method

<TestSuite url="V1/ClassRecords/bookClass/" httpMethod="put">
  <TestCase name="data1" desc="约课成功">
        <Setup name="setup1" url="V1/Students/login/" httpMethod="post">
            <Param name="username" value="#sql1.mobile#">
                <Sql name="sql1">select id,mobile,password from ebk_students where status=1 and acoin>100 
                and level is not null;
                </Sql>
            </Param>
            <Param name="password" value="#sql1.password#" />
        </Setup>
        <Param name="cid" value="#sql4.id#">
            <Sql name="sql4">select id from ebk_class_records where status=0 and begin_time>unix_timestamp()
             and free_try=0 ;
            </Sql>
        </Param>
        <ExpectResults>
            <Pair>errorCode:200</Pair>
            <Pair>errorMsg:约课成功</Pair>
        </ExpectResults>
    </TestCase>
</TestSuite>

   Support get param's value from setup action response

<TestSuite url="V1/ClassRecords/bookClass/" httpMethod="put">
  <TestCase name="data1" desc="约课成功">
        <Setup name="setup1" url="V1/Students/login/" httpMethod="post">
            <Param name="username" value="#sql1.mobile#">
                <Sql name="sql1">select id,mobile,password from ebk_students where status=1 and acoin>100 
                and level is not null;
                </Sql>
            </Param>
            <Param name="password" value="#sql1.password#" />
        </Setup>
        <Param name="cid" value="#setup1.id#" />
        <ExpectResults>
            <Pair>errorCode:200</Pair>
            <Pair>errorMsg:约课成功</Pair>
        </ExpectResults>
    </TestCase>
</TestSuite>

   Support to get param's value from sql/function

<TestSuite url="V1/Students/login" httpMethod="post">
    <TestCase name="data3" desc="登录成功">
        <Param name="username" value="#sql1.mobile#">
            <Sql name="sql">select trim(mobile) as mobile from ebk_students where password =
                'e10adc3949ba59abbe56e057f20f883e'  and tx_sig_expiredtime> curdate()+86400;
            </Sql>
        </Param>
        <Param name="password" value="e10adc3949ba59abbe56e057f20f883e" />
        <Param name="code">
            <Function clsName="test.java.LogicHandler" methodName="codeGenerator" arguments="test"/>
        </Param>
        <ExpectResults>
            <Pair>errorCode:200</Pair>
            <Pair>errorMsg:登录成功</Pair>
        </ExpectResults>
    </TestCase>  
<TestSuite>

   Support Pair/Contain/AssertTrue type for expect results

<TestSuite url="V1/Students/login" httpMethod="post">
    <TestCase name="data3" desc="登录成功">
        <ExpectResults>
            <Pair>errorCode:#code#</Pair>
            <Contain>.*("id":"#sql.mobile#").*</Contain>
            <AssertTrue>"#code#"=="#sql.mobile#"</AssertTrue>
            <Sql name="sql">select trim(mobile) as mobile from ebk_students where password =
                            'e10adc3949ba59abbe56e057f20f883e'  and tx_sig_expiredtime> curdate()+86400;
                        </Sql>
            <Function name="code" clsName="test.java.LogicHandler" methodName="codeGenerator" />
        </ExpectResults>
    </TestCase>  
<TestSuite>

   Support sql/function for expect results

<TestSuite url="V1/Students/login" httpMethod="post">
    <TestCase name="data3" desc="登录成功">
        <ExpectResults>
            <Pair>errorCode:#code#</Pair>
            <Contain>.*("id":"#sql.mobile#").*</Contain>
            <Sql name="sql">select trim(mobile) as mobile from ebk_students where password =
                            'e10adc3949ba59abbe56e057f20f883e'  and tx_sig_expiredtime> curdate()+86400;
                        </Sql>
            <Function name="code" clsName="test.java.LogicHandler" methodName="codeGenerator" />
        </ExpectResults>
    </TestCase>  
<TestSuite>

   Support regular expression for expect result in contain/pair both

<TestSuite url="V2/ClassRecords/classDetail/" httpMethod="get">
    <TestCase name="GetClassDetailSuccess" desc="获取数据成功">
         <Param name="username" value="#sql.mobile#">
             <Sql name="sql">select c.begin_time as begin_time,s.mobile as mobile ,password,c.id as cid 
             from ebk_students as s left join ebk_class_records as c ON s.id = c.sid limit 100;
             </Sql>
        </Param>
        <Param name="password" value="#sql.password#" />
        <Param name="cid" value="#sql.cid#" />
        <ExpectResults>
            <Pair>errorCode:200</Pair>
            <Pair>errorMsg:老师已在(QQ|Skype)上等你,快去上课吧</Pair>
            <Contain>.*("id":"#sql.cid#").*("begin_time":"#sql.begin_time#").*</Contain>
        </ExpectResults>
    </TestCase>
</TestSuite>

   Support execute repeated times(invocationCount)

<TestSuite url="V1/Students/login" httpMethod="post" invocationCount="2000">
    <TestCase name="data1" desc="更改手机号登录">
        <Param name="username" value="#sql1.mobile#">
            <Sql name="sql">select trim(mobile) as mobile,password from ebk_students where id=123456;
            </Sql>
        </Param>
        <Param name="password" value="#sql.password#" />
        <ExpectResults>
            <Pair>errorCode:200</Pair>
            <Pair>errorMsg:登录成功</Pair>
        </ExpectResults>
    </TestCase>
<TestSuite>

   Support request headers

<TestSuite url="V1/Students/login" httpMethod="post">
    <TestCase name="data1" desc="更改手机号登录">
        <Headers>
            <Header name="Content-Type" value="application/x-www-form-urlencoded;charset=UTF-8" />
            <Cookie name="PHPSESSIONID" value="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" />
        </Headers>
        <Param name="key" value="value" />
        <ExpectResults>
            <Pair>errorCode:200</Pair>
            <Pair>errorMsg:成功</Pair>
        </ExpectResults>
    </TestCase>
<TestSuite>

Demo project please refer to smart-api-automation-example

Contributors

Charlie https://github.com/zhuyecao321
Niki https://github.com/ZhangyuBaolu
Wind https://github.com/lwfwind

Версии библиотеки

Версия
2.5
2.2
2.1
2.0
1.0