Does anyone know how to pass a local variable to PlatonScript procedure as an argument?
I just don't want to use global variables.
Thanks
When you create a procedure that has parameters you have to declare it like
<p_targetsData>
<![CDATA[START:p_targetsData(testvar1,testvar2)
testvar1 = "test"
testvar2 = 123
RETURN 1 ]]>
</p_targetsData>
when you want to call it and pass the parameters you write
#testvar1:STRING
#testvar2:INTEGER
CALL p_targetsData(testvar1,testvar2)
jPlaton uses calling by reference so after the CALL execution your variables will still have their real value
Related
I Have a scenario like need to pass a random variable example ${__Random(1,25,)} in inside one more variable like
Globel variable:
Test = TestResults
${__Random(1,25,)}
Sample Request Data:
${Test(randome variable)}, ${Test(randome variable)},${Test(randome variable)},-------- ${Test(randome variable)}
Sample expected response:
TestResults1,TestResults10,TestResults5,----------- TestResults20
How should I pass this scenario?
Use the V function
${__V(TestResults${__Random(1,25,)})}
V (variable) function returns the result of evaluating a variable name expression. This can be used to evaluate nested variable references
You can replace TestResults with ${yourVarName} if you want to dynamically use additional variable
I would like to read values from a select query and use the values sequentially in a API call.
Since the database values get stored as var_1, var_2 ... var_N
So how do i increment the number for the variable?
I used a counter and pre processor to increment the number in variable
vars.put ("email", "email"+"_"+vars.get("counter"))
But the final variable is not getting replaced by the value from the select query
eg select query result from a debug sampler
email_1=hata.pd.h13u#yopmail.com
email_2=hata.pd.h13u#yopmail.com
email_3=hataiot.test13#mailinator.com
email_4=hataiot.test12#mailinator.com
--combining the variable and counter:
vars.put ("email", "email"+"_"+vars.get("counter"))
--using the variable in the API post body
{
"username":"${email}",
"password":"test1234"
}
Actual result:
POST data:
{
"username":"email_1",
"password":"test1234"
}
Expected result:
{
"username":"hata.pd.h13u#yopmail.com",
"password":"test1234"
}
TIA
${__V(email_${counter})}
Try this one, see also the documentation: http://jmeter.apache.org/usermanual/functions.html#what_can_do
Note that variables cannot currently be nested; i.e. ${Var${N}} does not work. The __V (variable) function can be used to do this: ${__V(Var${N})}. You can also use ${__BeanShell(vars.get("Var${N}")}.
Have you considered using ForEach Controller? It's super-handy for iterating the variables from extractors or JDBC test elements.
If you still want to continue with the current approach you need to change this line:
vars.put ("email", "email"+"_"+vars.get("counter"))
to this one:
vars.put ("email", vars.get("email"+"_"+vars.get("counter")))
Because you're putting into email variable stuff like email_1, email_2, etc. instead of actual ${email_1} variable value.
References:
JMeter Functions and Variables
How to Retrieve Database Data for API Testing with JMeter
I've a script named script 1 that creates a text file and stores some string values into it.
I need to call this script script 1 into another script file named script 2 but only part of it (script 1). I don't want to call the part of the script (script 1) that will store string values.
How can I call only part of the script 1 into script 2? I'm using TestComplete to run these scripts.
You can pass some parameter in script 1 which you can check every time before storing some values in file
function script1(flag)
----create text file---
if flag<>false then
--stores some string values--
end if
end function
function script2
Call script1(false)
end function
If you can't make any changes like passing some parameter in script1(as it might be called from other scripts also and then you will have to change signature everywhere), then you can create a global variable and before calling it from script2, assign some value in that variable and check that value in script1.
dim flag=true
function script1()
----create text file---
if flag<>false then
--stores some string values--
end if
end function
function script2()
flag=false
call script1()
flag=true
end function
Hope this solves your problem. Otherwise, share some sample code so that I can understand the scenario better.
This is an example, you can execute all of the "body" content or you can cut some lines or whatever you need.
You put Both files in the same folder
This is the content of Script1.vbs
a=5
msgbox "hello world"
b=3
msgbox cstr(a*b)
This is the content of Script2.vbs
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile(".\script1.vbs",1,FALSE)
ts.ReadLine
body = ts.ReadLine
ts.Close
Execute body
I'm trying to call PL/SQL procedure from SoapUi with Groovy and I get error like: "..that function does not exist" I guess that this part of code is for calling PL/SQL functions, and when I check it with PL/SQL function - it works. Could anyone help with solution for calling PL/SQL procedure with Groovy?
Sample of code that works for calling PL/SQL Function:
sql.call("{? = call IFSUI_SG_CA_TEST_UTILS.getCustomerAccountData(?, ?, ?)}", [Sql.VARCHAR, customerNo, accountNo, accountIbanNo]) { result ->
log.info (results);
}
I finally finded it, here is example of calling PL/SQL procedure from Groovy with also IN OUT parameter, I hope that it will save time someone :)
With IN parameter:
sql.call("{call IFSUI_SG_CA_TEST_UTILS.getCustomerAccountData(?,?,?)}",
[customerNo,accountNo,accountIbanNo])
customerNo,... are variables
With IN OUT parameter:
sql.call("{call IFSUI_SG_CA_TEST_UTILS.getCustomerAccountData(?,?,?)}",
[Sql.inout(Sql.VARCHAR(customerNo)), Sql.inout(Sql.VARCHAR(accountNo)),
Sql.inout(Sql.VARCHAR(accountIbanNo))])
My question involves the use of QTP / VBScript.
Goal: From the qtp main starting file, initialize an array of classes, and pass that array as a parameter to a re-usable action via a parameter.
Problem: I am not able to pass an array of classes to my re-usable action.
Details:
I have two files: “application_main” and “personal_action”.
application_main is the entry point into qtp/vbscript.
personal_action is a re-usable action
Inside application_main, we have a call to InvokeApplication, proceeded by a few other declarations.
I am able to initialize an array and proceed to pass it as a parameter from my application_main to my personal_action:
From application_main:
Dim myArray
myArray = new Array(object1, object2, object3)
RunAction “personal_action”, oneIteration, myInteger, myBoolean, myArray
On the personal_action page, I edit the parameter properties via:
Edit->Action->ActionProperties. I select the Parameters tab.
In it, I have the option to define the amount of incoming parameters and each individual type. These available types seem to be restricted to:
String, Boolean, Date, Number, Password, Any
I set my 1st parameter as: Number
I set my 2nd parameter as: Boolean
I set my 3rd parameter as: Any
Upon running, I am prompted with this:
The type you specified for the ‘myArray’ parameter in your RunAction
statement does not match the type defined in the action.
Question: I am able to pass the Number and Boolean fine, but when an array is involved, qtp/vbscript doesn't seem to handle it well. Why am I not able to pass an array to an action via parameters from the main startup file? This seems like a common and simple task. Could I be so wrong?
Any help is appreciated. Thank you.
As per my knowledge, QTP will NOT allow this. There is no parameter type that can be used to represent an Array. This might be a limitation of QuickTest Professional.
Rather than passing array you can pass the Array elements as a string separated with delimiters.
Example:
"Item1^Item2^............" where "^" is the delimiter
then you can use split function of vb script, to get your array back.
Again doing the same thing with object,we have to give try for this
use lib file in your action ...
Create array public in lib
but in end for any case test or interation vararray=null
rodrigonw.
Sugestion... use function for include your lib in your actions (lib path)
Lib soluction
''######################################LIB"
'lib Passsagem de valores entre array
Dim arrayyy()
Sub setArrayyy(strvalores,redimencionaArray)
On error resume next
tamanho=UBound(arrayyy,1)
If Err.Number=9 then
ReDim arrayyy(0)
redimencionaArray=false
end if
err.Clear
On error goto 0
If redimencionaArray Then
tamanho=tamanho+1
ReDim preserve arrayyy(tamanho)
end if
arrayyy(tamanho)=strvalores
'arrayyy=arrayyy
End Sub
function getArrayyy() getArrayyy=arrayyy End function
''######################################"'Action X
call setArrayyy("X",false)
call setArrayyy("A",true)
call setArrayyy("D",true)
call setArrayyy("B",true)
''######################################'Action y
x=getArrayyy()
for countx=0 to ubound(x)
msgbox x(countx)
next