Runtime Test Data for Testscript in TestComplete - testcomplete

I started using Test Complete to automate Desktop application.
The issue is scripts holds the value which i entered while recording and the value is hard-coded.
i want the pass the value during run time. how can i achieve it?

This depends on how you want to do this. If you want to put it to your test as a parameter from another test or using a project's test item, you can define a keyword test parameter (see Keyword Test Parameters).
If you want to make a human user specify a value on runtime (although this is not very "automated"), you can create a user form that will request this value (see User Forms - Overview).
And if you want to pass a parameter to your test using command line, you can use script to read parameters from the TestComplete command-line, assign a project variable with this value and then use this variable instead of a hard coded value. See ParamStr Method, ParamCount Method and Project And Project Suite Variables.
And if you want to feed your test with some data from an external source, you can do this using the data-driven testing feature of TestComplete. See Data-Driven Testing.

Related

Is it possible to add an object refernce User Defined Variable in JMeter?

I can see that User Defined Variables can populate vars with string values only. Is there a way to populate an object reference User Defined Variable in User Defined Variables element.
I have tried as UDV values something like ${__groovy(new java.util.concurrent.ConcurrentHashMap())}. But this way leads to some string retrieved from the variable later.
I have even tried to use side effects of User Defined Variables groovy scripts like ${__groovy(vars.putObject("key", new java.util.concurrent.ConcurrentHashMap(); "assigned")}. But this one leads to some JMeter compilation error while being syntactically OK groovy script in my opinion.
I have tried using scripting pre-processors put on top of the test plan like one of SO answers suggested but they work before each sampler in the tree and thus do not what is intended do.
I still can't find a way to initialize an object reference variable in JMeter at the test plan initialization phase hijacking the thread initializing UDVs.
I know of possibilities to populate vars with putObject(<key>, <reference value>) from within scripting elements like JSR223/BeanShell/some others sampler/pre-processors etc.
But I want to populate the vars for all my thread groups at the initialization of the test plan in order to avoid using props imposing synchronized lock penalty on each put/get call. And there is no possibility to add a sampler at the top of the test plan.
EDIT after accepting correct answer by Dmitri T (for those who want to know the answer right away in more clear form):
${__groovy(vars.putObject("<key>"\, new HashMap()); "virtually anything")}
is correct (while indirect) way to populate an object reference variable in UDV test plan element.
while being syntactically OK groovy script in my opinion.
it's only your opinion, look at jmeter.log file and you will see interpretation error there
As per JMeter Documentation:
If a function parameter contains a comma, then be sure to escape this with "\", otherwise JMeter will treat it as a parameter delimiter. For example:
${__time(EEE\, d MMM yyyy)}
the correct syntax would be something like:
${__groovy(vars.putObject('key'\,new java.util.concurrent.ConcurrentHashMap()),)}
Demo:
More information: Apache JMeter Functions - An Introduction

Use todays date as a variable in Jmeter

I need to create a load test script using Jmeter for the some apis including this one:
https://myserver01.net/alert/bydate/${Today}
Now I use the date value manually , e.g everyday I manually change the date value in the request , e.g today I sent a request to https://myserver01.net/alert/bydate/2018-02-09. I want to make it automated so that whenever I run the test it will take todays date by default. I have seen this answers in the link http://www.jmeter-archive.org/way-to-get-current-date-into-a-variable-td512937.html but did not understand the methods. Like the first method says to define today in command line, which means I have to do it annually every time I initiate Jmeter. I want to avoid it and make it automated inside the script.
Add User Defined Variables configuration element somewhere to your Test Plan
Add the following entry there:
Name: Today
Value: ${__groovy(new Date().format('yyyy-MM-dd'),)}
Once done you will be able to refer today's date as ${Today} where required
More information:
__groovy() function
SimpleDateFormat documentation (explanation of yyyy-MM-dd pattern)
It is as simple as using JMeter __time function:
https://myserver01.net/alert/bydate/${__time(yyyy-MM-dd,)}
To test functions, you can use Function Helper Dialog which allows you to test:

what container we can use for global and environment variables in Jmeter for API testing

I am trying to use Jmeter for API automation testing.
But Jmeter hasn't provided any separate containers for global and environment variables similarly like SOAP-UI and Postman.
I tried to use property file which also shared among all the JSR223 throughout the project but property having many others keys too and I haven't got any option by which I can delete key which been initiated once. Moreover, I can update the value too which seems most preferable to use
Below code I am using to set and get the values
props.put("shubhamKey", "shubhamValue")
props.get("shubhamKey")
I can also update it using same key
props.put("shubhamKey", "shubhamNewValue")
But as I said we can't delete key once initiated and it seems dangerous to delete from properties as it has many other keys too which may be required by Jmeter internally
After seeing too many things I have seen "User Defined Variables" where I can specify my key-value pairs. I am able to get the value using below code:
vars.get("shubhamLocalVariable")
But I am not able to set the value using below code:
vars.put("shubhamUserKeyagain","shubhamUservalue")
neither I got any option by which I further update it or delete it.
so Is there any feasible thing to store variables in Jmeter which can be easily created/deleted/updated using the code and can even call by other containers like HTTP Request.
Moreover I also want a container which preserve the values so the next iteration and next time (any time like other day) it will start with latest values
User Parameters
Jsr223
Any workaround will be helpful and appreciated in advance
As for me, I'm using a JSR223 Sampler at the begining of every Thread.
And for me it works:
vars.put("checksums_1","")
vars.put("checksums_2","")
vars.put("checksums_3","")
Firstly you can delete properties by using:
props.remove("shubhamKey");
And if you use specific prefix/suffix it shouldn't effect JMeter internally.
User Defined Variables isn't the best way to handle dynamic values, it's used for static variables
Note that all the UDV elements in a test plan - no matter where they are - are processed at the start.
But you can set variable by string or variable or function, e.g:
For defining variables during a test run, see User Parameters which use similar assignments.

Coded UI Test data driven in UIMap.cs

I have a lot of codeduitest. There are common test step in each test method. For example; this.UImap.navigatetourl(); I have moved it in UIMap.cs. Because I have changed code for navigatetourl().I want to run the same test method for different urls. I can use data driven test in CodedUITest but I want to use data driven test in UIMap.cs. What can I do?
Thanks,
Take your UIMap.NavigateToUrl() method and add a parameter to it for the URL you want to go to. Use that value to set the appropriate *Params property in your UIMap before actually doing the the navigation. (I'm assuming you recorded a navigation action of some kind?)
In your CodedUI test, take the relevant value from your data source and pass it through to the UIMap.NavigateTo() method as the URL parameter value.

Using parameters as user Defined Variables?

We run our tests in non gui mode and pass in various parameters like Server, port, threads etc. We'd also like to run our test in GUI mode, and be able to change these parameters in the GUI.
What I wanted to do, was use 2x User Defined variable objects, and have one with static data we can edit, and another with parameters. That way the actual test plan doesn't change, but we can set variables as parameters, and just disable the static data one. Or disable the parameterized one when we want to run with static data.
But this doesn't seem to work - no errors nothing.
I do something similar, but I used a UDF for this.
What I did was set up my variables and use default values.
VARNAME VALUE
otl_PROTOCOL ${__P(otl_protocol,https)}
otl_PORT ${__P(otl_port,443)}
otl_THREADS ${__P(otl_threads,1)}
otl_REPS ${__P(otl_reps,1)}
otl_RAMP ${__P(otl_ramp,0)}
I did one for server name as well. This way, I can use the defaults here or I can pass in parameters in either the command line args or in my user.properties. This works very well for me.
How are you passing in values from non-GUI mode? via CSV, using properties, User-Parameters, etc.?
If CSV, this is an easy fix. Simply create a User Defined Variables (UDV) object at the Test Plan Level and "hard code" all your parameters (Server, port, etc.). Keep your CSV config. If you run in GUI mode, disable the CSV and enable the UDV. When you save the file, keep the CSV enabled and the UDV disabled - that way when you run from non-GUI it'll read the CSV file.
If using properties, I would do the following: Create a UDV with all your parameters (Server, etc.). Before entering values, copy the component so you have TWO identical UDVs. In UDV 1, enter the property value from the command line. In UDV 2, enter the "hard coded" values. Throughout your script, replace any references to the properties with variable references. It would look something like this:
UD1: UD2:
Name Value Name Value
SERVER ${__P(Server)} SERVER devdomain.com
PORT ${__P(Port)} PORT 4111
Some HTTP Request
Domain: ${SERVER}
If using user-parameters, it would be the same concept as above.
Actually i am using a function named as regular expression for getting value.
here i have to use variable under variable because there is lots of value with same boundary, so i have selected one paragraph as ${ABC} and fetching value from this paragraph ${XYLEM}. both the variable created as regular expression.tried with ${__V(ABC${XYLEM})};
${__setProperty{Search_Investment_Banking,$Investment_Banking}};

Resources