So I have a keyword driven framework that executes on keywords. In one of the functions I have a if element exist condition. Now if that element doesn't exist I want qtp to not execute the next 3 keyword functions following it. Is there a way to do this? Thank you!
You could a global variable that records the number of keywords that should be skipped. When your element doesn't exist, you could set the skip count to 3. In your framework that reads each keyword, you could first check the current skip count. If it's 0, you execute the keyword normally. Otherwise, you decrease the skip count by 1 and exit without executing that keyword.
Can you not insert a conditional statement?
Therefore if the element exists, you can put the next 3 statements within the loop? Else, do nothing. Then have the code follow on as normal?
If you aren't comfortable in expert view, this shows how to do it in keyword view also:
http://www.softwaretestinghelp.com/conditional-loop-statements-qtp-tutorial-4/
Related
I'm designing a pseudocode version of a programme thingy I made, in which one of the sections is someone inputting a number to select an option. When someone inputs a number, a value from a list is output. I thought using an 'IF' statement nested within a 'CASE' statement would make that task run more efficiently, but I'm not sure if that would still conform to the acceptable 'CASE' statement format. This is what I was envisioning for the first option:
**
CASE category OF
'1' : PRINT "Members who have chosen to work as volunteers,"
IF MemberInfo[2] = 'yes'
PRINT "MemberInfo[0], MemberInfo[1]"
**
The following numbers in the main 'CASE' statement would then follow the same format. Is this okay, or should I just make various 'IF' statements?
It does not makes to use CASE here as we use CASE when there are multiple options to choose from. Given its just one condition and action based on that an 'if' is more appropriate.
An if nested within CASE is not a good programming structure. Go with either CASE or IF.
Input a number as category
If category is a number
then
print list
end if
Sure, that makes sense. Real code can do it, so why not pseudocode?
(But if the other cases have the same format, there's probably a better way to do it: maybe a map lookup or using the category more dynamically, depending on what's changing between each case statement, and what stays the same.)
I have a requirement where I need to validate cases that gets matches with the output JSON: I wrote code inside if controller:(so if all the cases matches, we will say pass and print the value) And its actually working fine..
("${C_etrTimestamp}"=="${ETRTIMESTAMP}")&&("${C_EventName}"=="${EVENTNAME}")&&("${C_EventType}"=="${EVENTTYPE}")&&("${C_AreaName}"=="${AREANAME}")&&("${C_AreaType}"=="${AREATYPE}")&&("${C_additionalInfo}"=="${ADDITIONALINFO}")&&("${C_resultStatusCode}"=="${RESULTSTATUSCODE}")&&("${C_resultStatusMessage}"=="${RESULTSTATUSMESSAGE}")
But I also need to print the results those doesn't matches: so I created another if controller. and inside that I wrote the below code:(but its not working for me) so the 1st if is getting executed. but the results those are not matching are not getting entered into the 2nd if controller.
("${C_etrTimestamp}"!=="${ETRTIMESTAMP}")or("${C_EventName}"!=="${EVENTNAME}")or("${C_EventType}"!=="${EVENTTYPE}")or("${C_AreaName}"!=="${AREANAME}")or("${C_AreaType}"!=="${AREATYPE}")or("${C_additionalInfo}"!=="${ADDITIONALINFO}")or("${C_resultStatusCode}"!=="${RESULTSTATUSCODE}")or("${C_resultStatusMessage}"!=="${RESULTSTATUSMESSAGE}")
can anyone suggest me what to do?
Instead of trying to negate every clause, make a second condition an exact opposite of the first with `!(...):
!(("${C_etrTimestamp}"=="${ETRTIMESTAMP}")&&("${C_EventName}"=="${EVENTNAME}")&&("${C_EventType}"=="${EVENTTYPE}")&&("${C_AreaName}"=="${AREANAME}")&&("${C_AreaType}"=="${AREATYPE}")&&("${C_additionalInfo}"=="${ADDITIONALINFO}")&&("${C_resultStatusCode}"=="${RESULTSTATUSCODE}")&&("${C_resultStatusMessage}"=="${RESULTSTATUSMESSAGE}"))
You could also simplify conditions to one comparison with all variables inside it (since you want all of them to match), make is a bit shorter and easier to read.
First If:
"${C_etrTimestamp}${C_EventName}${C_EventType}..."=="${ETRTIMESTAMP}${EVENTNAME}${EVENTTYPE}..."
Second If:
!("${C_etrTimestamp}${C_EventName}${C_EventType}..."=="${ETRTIMESTAMP}${EVENTNAME}${EVENTTYPE}...")
This is a basic question on the use of Trace Tables to assist in a dry run of a simple algorithm.
What I find most tricky is when to take a new line in the trace table? For example, take the following question:
Here is the array of integers which it applies to:
The following trace table is presented as one completes a dry run. Here is the solution:
I understand that initialising the variables Number, Lower & Upper appear on the first line, but when I go into the While Loop, I am tempted to put the value 5 on the first line also, for the variable Current. In essence, this is what I am tempted to do:
Why does this solution require that the value for Current, which is 5, appear on the second line? I suppose the question could be rephrased to 'When do I take a new line in a trace table?'
Thanks.
I think there is no specific way to do trace table, which means you have to setup your rules before you work and go on.
consider this example:
and this also:
did you notice the difference between loop iterator in each one. In first example they put the initialization value of the iterator in first line, and in second example they put the initialization of the loop iterator in the second line.
also have a look at wiki they also put the loop initialization in the second line.
also this video has similar example to those I posted here and is always start loop iterator in the second line.
also this example has totally different approach, which is each line of code in a new line in the trace table.
you can find also another different approach for trace table here
Finally:
In my opinion chose the rules that make sense for you, for example:
1-first line will contain the default values for the variables.
2-regarding loop iterations, put loop iterator in the same line as the variables that affected by this iteration, like the second example I posted above.
regarding your question I think it's more clear to put Current first value 5 in the second line, so you can track what each loop iteration affect your variables in a clear way.
I have this parameter as an array. The array is big, 100 cells. It is a parameter that can be initiated in omnet.ini file. The cells with even numbers should get value A and odd numbers should get value B. How can I do this in an automated manner?
Is there a way besides having all odd and even indices initiated one by one manually?
Wildcards can be useful but I do not know how to use them to separate odd and even indices.
Thanks.
You can access the actual module index with the index operator. Combining this with the conditional operator ?: you can easily define the value:
**.myModule[*].myParameter = index % 2 == 0 ? "A" : "B"
I'm not aware of any feature like this. There are a number of work-arounds you could use:
Provide two parameters and select the correct one in code
Use the volatile keyword (probably not appropriate here)
Put the entire thing in your .ini file
I'd personally implement the first approach, that way you can use the wildcard to pass both parameters ([*].myNode.parameterEven and [*].myNode.parameterUneven) and then set the correct values in your array in a for loop.
However, you could also use the volatile keyword in your NED file, see the manual for more details. However, this approach mostly works well if you have different parameters depending on which node you are assigning it to. For this case I think the first approach is better.
The last alternative is just putting the entire thing in your .ini file, which may be useful if you want to parameterize the array later.
I am new to Jmeter and trying to do a while loop operation with a condition. So please someone provide solution for the below query.
Query: I am trying to do DELETE request for 50 times using the id as reference. So I kept the condition as "${startId}<=${endId}" in the while loop. But the while loop is executing infinitely. Is there any simple mechanism to iterate the loop for 50 times by increment the startId till it reaches endId.
While Controller accepts function or variable. So you need to either:
provide a variable which has value of "true" and becomes "false" somewhere else
provide a function which returns "false" to exit from While loop.
With your condition it won't evaluate your expression hence it will never become "false". The solution is to wrap your statement into i.e. __javaScript function as:
${__javaScript(${startId}<=${endId},)}
For more information on JMeter functions see How to Use JMeter Functions post series.
You may take help of loop controller and pre-processor.
snaps :