51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 4876|回复: 3
打印 上一主题 下一主题

SOAP UI循序渐进之三(Update)

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2013-11-29 11:04:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 开着拖拉机上班 于 2013-12-3 16:47 编辑

为了测试项目的稳定性,需要实现7*24不间断的对service发出request并获取response的值,然后存储到Excel中。
    以上就是需求,从今天开始把学习成果记录在这里,供大家批评指正。
首先给大家看看一个case的step有哪些:
[img][/img]其中looper是用来控制循环执行这些step的;Read是从excel中读取数据并写入到properties中,供发送request使用;Write用于把response中的数据写入excel存储;delay类似于性能测试中的思考时间。

以上是项目基本背景:
说重点,直接上实现loop的脚本,超级简单
import groovy.transform.Field

testRunner.testCase.setPropertyValue("RUN", '1' )
def runCycle = (testRunner.testCase.getPropertyValue("RUN")).toInteger()

def size = 3 // sets the number of loops
for( counter in 0..size-1)
{
testRunner.runTestStepByName("Groovy Script - Read") // calls the excel file read step
testRunner.runTestStepByName("Delay 1") // calls the delay step for each loop
runCycle++
testRunner.testCase.setPropertyValue("RUN",runCycle.toString())
}

--------------------------------------------------------------------------------------------------------
之二:把excel里的数据取到SOAP UI的properties中,实现方式:
import groovy.transform.Field
import jxl.*
import jxl.write.*
Workbook workbook1 = Workbook.getWorkbook(new File("D:\\FAL\\SOAPUI_Automation\\output.xls"))
def sheetCounter = workbook1.getNumberOfSheets();
sheetNameArray = workbook1.getSheetNames();
def sNumber = 0
def accountId = new Object[sheetCounter][2]         
def tcuId = new Object[sheetCounter][2]
def vin = new Object[sheetCounter][2]
def userId = new Object[sheetCounter][2]
for( c in 0..sheetCounter-1) // loops through the excel sheets
{
readingSheetName = sheetNameArray[c]
//log.info "readingSheetName: ${readingSheetName}"
Sheet sNC = workbook1.getSheet(sheetNameArray[c])
Cell A2 = sNC.getCell(0,1) // getCell(column,row) count from 0,0 = cell A1
Cell B2 = sNC.getCell(1,1)
Cell C2 = sNC.getCell(2,1)
Cell D2 = sNC.getCell(3,1)
accountId[sNumber][0] = "AccountId${sNumber}"      //can i delete ?
accountId[sNumber][1] = A2.getContents()
//log.info accountId[2][0]
//log.info accountId[2][1]
tcuId[sNumber][0] = "TCUID${sNumber}"    //can i delete ?
tcuId[sNumber][1] = B2.getContents()
vin[sNumber][0] = "VIN${sNumber}"       //can i delete ?
vin[sNumber][1] = C2.getContents()
userId[sNumber][0] = "UserId${sNumber}"     //can i delete ?
userId[sNumber][1] = D2.getContents()

def propswrite = new java.util.Properties(); // sets the properties step for use with the soap request
propswrite = testRunner.testCase.getTestStepByName("Properties 1");
propswrite.setPropertyValue("AccountId",accountId[sNumber][1]);
propswrite.setPropertyValue("TCUID",tcuId[sNumber][1]);
propswrite.setPropertyValue("VIN",vin[sNumber][1]);
propswrite.setPropertyValue("UserId",userId[sNumber][1]);
propswrite.setPropertyValue("SheetName",readingSheetName);

testRunner.runTestStepByName("GetVehicleParkedLocation"); // calls the soap test step
testRunner.runTestStepByName("Groovy Script - Write"); // calls the excel file write step

sNumber++
}
workbook1.close()

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?(注-册)加入51Testing

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
 楼主| 发表于 2013-12-3 16:46:29 | 只看该作者
之三:把Response中的数据写入Excel


import groovy.transform.Field
import java.io.File;
import java.util.*;
import jxl.*;
import jxl.write.*;

def propsread = new java.util.Properties();
propsread = testRunner.testCase.getTestStepByName("roperties 1");
def writingSheetName = propsread.getPropertyValue("SheetName")
//log.info "writingSheetName: ${writingSheetName}"

def flag = (testRunner.testCase.getPropertyValue("RUN")).toInteger();
//log.info "initialWritingRow: ${flag}"

Workbook workbook = Workbook.getWorkbook(new File("D:\\FAL\\SOAPUI_Automation\\GetVehicleParkedLocation.xls"))
WritableWorkbook copy = Workbook.createWorkbook(new File("D:\\FAL\\SOAPUI_Automation\\GetVehicleParkedLocation.xls"), workbook) // creates a copy to append data
WritableSheet sheet = copy.getSheet(writingSheetName)
//log.info(sheet.isHidden())
//log.info sheet.getRows()
//log.info sheet.getColumns()
flag = sheet.getRows().toInteger()
//log.info "actualWritingRow: ${flag}"

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def responseAsXml = context.expand( '${GetVehicleParkedLocation#Response}' ) // gets the xml response
def holderResponse = groovyUtils.getXmlHolder(responseAsXml)
if( holderResponse !=null )
{
// declare namespace according to xml request
holderResponse.declareNamespace('veh', 'http://ns.hughestelematics.com/Gateway/service/VehicleParkedLocationService')
holderResponse.declareNamespace('v1', 'http://xmlns.hughestelematics.com/Gateway/VehicleParkedLocation/V1')
holderResponse.declareNamespace('v11', 'http://xmlns.hughestelematics.com/Gateway/Common/Header/V1')
def E2_Timestamp
E2_Timestamp = holderResponse.getNodeValue("//veh:GetVehicleParkedLocationResponse[1]/v1:GetVechicleLocationResponse[1]/v1:Header[1]/v11:Timestamp[1]")
//log.info E2_Timestamp
def F2_Altitude
F2_Altitude = holderResponse.getNodeValue("//veh:GetVehicleParkedLocationResponse[1]/v1:GetVechicleLocationResponse[1]/v1ata[1]/v1:Altitude[1]")
def G2_Course
G2_Course = holderResponse.getNodeValue("//veh:GetVehicleParkedLocationResponse[1]/v1:GetVechicleLocationResponse[1]/v1ata[1]/v1:Course[1]")
def H2_Latitude
H2_Latitude = holderResponse.getNodeValue("//veh:GetVehicleParkedLocationResponse[1]/v1:GetVechicleLocationResponse[1]/v1ata[1]/v1atitude[1]")
def I2_Longitude
I2_Longitude = holderResponse.getNodeValue("//veh:GetVehicleParkedLocationResponse[1]/v1:GetVechicleLocationResponse[1]/v1ata[1]/v1ongitude[1]")
def J2_PrecisionInMeters
J2_PrecisionInMeters = holderResponse.getNodeValue("//veh:GetVehicleParkedLocationResponse[1]/v1:GetVechicleLocationResponse[1]/v1ata[1]/v1ocationPrecision[1]/v1recisionInMeters[1]")
def K2_PrecisionTrueness
K2_PrecisionTrueness = holderResponse.getNodeValue("//veh:GetVehicleParkedLocationResponse[1]/v1:GetVechicleLocationResponse[1]/v1ata[1]/v1ocationPrecision[1]/v1recisionTrueness[1]")
def L2_statusReceivedTimeStamp
L2_statusReceivedTimeStamp = holderResponse.getNodeValue("//veh:GetVehicleParkedLocationResponse[1]/v1:GetVechicleLocationResponse[1]/v1ata[1]/v1:statusReceivedTimeStamp[1]")
Label label_Timestamp = new Label(4, flag, E2_Timestamp); // fills excel cells with the results
sheet.addCell(label_Timestamp);
Label label_Altitude = new Label(5, flag, F2_Altitude); //column=0=A,row=0=1, cell A1
sheet.addCell(label_Altitude);
Label label_Course = new Label(6, flag, G2_Course);
sheet.addCell(label_Course);
Label label_Latitude = new Label(7, flag, H2_Latitude);
sheet.addCell(label_Latitude);
Label label_Longitude = new Label(8, flag, I2_Longitude);
sheet.addCell(label_Longitude);
Label label_PrecisionInMeters = new Label(9, flag, J2_PrecisionInMeters);
sheet.addCell(label_PrecisionInMeters);
Label label_PrecisionTrueness = new Label(10, flag, K2_PrecisionTrueness);
sheet.addCell(label_PrecisionTrueness);
Label label_statusReceivedTimeStamp = new Label(11, flag, L2_statusReceivedTimeStamp);
sheet.addCell(label_statusReceivedTimeStamp);
}

def logArea = com.eviware.soapui.SoapUI.logMonitor.getLogArea("SoapUI log"); // reads the soapui log
def M2_soapuiLog
if( logArea !=null )
{
def model = logArea.model
if( model.size > 0 )
M2_soapuiLog = (model.getElementAt(model.size-1)).toString()
//log.info M2_soapuiLog
Label label_soapuiLog = new Label(12, flag, M2_soapuiLog);
sheet.addCell(label_soapuiLog);
}

copy.write()
copy.close()
workbook.close()
回复 支持 反对

使用道具 举报

  • TA的每日心情
    奋斗
    2020-10-9 10:10
  • 签到天数: 1205 天

    连续签到: 1 天

    [LV.10]测试总司令

    3#
    发表于 2014-3-13 14:40:28 | 只看该作者
    看看,谢谢分享
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    奋斗
    2019-12-31 08:59
  • 签到天数: 975 天

    连续签到: 1 天

    [LV.10]测试总司令

    4#
    发表于 2014-3-21 14:29:27 | 只看该作者
    都是代码,,看不懂,。。
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-11-26 13:09 , Processed in 0.077772 second(s), 30 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表