I am comparing values in Groovy as follows:
if (creds.username == env.Username && creds.password == env.Password)
{
foundUser = true;
break;
}
It should return foundUser = true , but the issue is the second comparison, ( creds.password == env.Password ) if I take that out it works .
Any ideas as to why this may happen ?
I wrote the following script:
def testStep = testRunner.testCase.testSteps["3D Secure Call"]
def str = new StringBuilder();
for (prop in testStep.getPropertyList()){
if(prop.getName() != "K" && prop.getName() != "RawRequest" && prop.getName() != "Domain" && prop.getName() != "Password" && prop.getName() != "ResponseAsXml" && prop.getName() != "Request" && prop.getName() != "RawRequest" && prop.getName() != "Response" && prop.getName() != "Username" && prop.getName() != "Endpoint"){
str.append(prop.getName() + "=" + testStep.getPropertyValue(prop.getName()) + "&" )
}
}
str.append("K=1473942615907cuwmviz")
And i am getting the following (As expected):
K M=10000330&PKey=c74737d2a1e27d2efec56cf8148bc6e2b68eac48a8daed17e795421c4acc51&a4=50000&a5=EUR&XID=12345678912345678912&K=1473942615907cuwmviz
Now what i am trying to achieve is sending this string to MD5 hashing function suggested here:
import java.security.MessageDigest
def generateMD5_A(String s){ MessageDigest.getInstance("MD5").digest(s.bytes).encodeHex().toString() }
I cannot achieve passing the generated string into this function and getting a new result.
Any suggestions?
achieved by doing:
def generateMD5_A(String s){ MessageDigest.getInstance("MD5").digest(s.bytes).encodeHex().toString() }
generateMD5_A(str.toString());
I have a large nested if. One portion of the nested if works, however, in the second portion only some of the nested if works. I cannot get the switch case to work.
//Match Scoring //All work, when I flip Poker on top of Match the first and second ifs do not work
if playerMatchCardsArray[0] == playerMatchCardsArray[1] &&
playerMatchCardsArray[1] == playerMatchCardsArray[2]{
} else if playerMatchCardsArray[0] == playerMatchCardsArray[1] ||
playerMatchCardsArray[1] == playerMatchCardsArray[2] ||
playerMatchCardsArray[0] == playerMatchCardsArray[2]{
} else if playerMatchCardsArray[0] != playerMatchCardsArray[1] ||
playerMatchCardsArray[1] != playerMatchCardsArray[2] ||
playerMatchCardsArray[0] != playerMatchCardsArray[2] {
//Poker Scoring //All work, when I flip Poker on top of Match. However the following lines work do not work
// SUITED THREE OF A KIND //does not work
if firstRandomNumber == secondRandomNumber && secondRandomNumber == thirdRandomNumber {
// STRAIGHT FLUSH // works
} else if straightCardsArray[0] == 1 && straightCardsArray[1] == 2 && straightCardsArray[2] == 3 &&
flushFirstRandomNumber == flushSecondRandomNumber &&
flushFirstRandomNumber == flushThirdRandomNumber{
// THREE OF A KIND // does not work
} else if pairFirstRandomNumber == pairSecondRandomNumber &&
pairFirstRandomNumber == pairThirdRandomNumber {
//STRAIGHT FORMULA // works
} else if straightCardsArray[0] == 1 && straightCardsArray[1] == 2 && straightCardsArray[2] == 3 {
// SUITED PAIR // does not work
} else if firstRandomNumber == secondRandomNumber ||
secondRandomNumber == thirdRandomNumber ||
firstRandomNumber == thirdRandomNumber {
// PAIR // does not work
} else if pairFirstRandomNumber == pairSecondRandomNumber ||
pairFirstRandomNumber == pairThirdRandomNumber ||
pairSecondRandomNumber == pairThirdRandomNumber {
// FLUSH // works
} else if flushFirstRandomNumber == flushSecondRandomNumber &&
flushFirstRandomNumber == flushThirdRandomNumber {
Thank you in advance for your time and assistance. It's greatly appreciated!
It was the '}' that was causing the issue.
I want to ask a question that how can i get the parent id of child node in aciTree. If uservchecked the child node then i want to save its id with its parent id.
Any help in this regard will be highly appreciated.
I have gone through aciTree documentation http://acoderinsights.ro/source/aciTree/documentation.html# but didn't found any method to get the parent id on child selection.
if (eventName == 'checked') {
if (bankUsers.indexOf(api.getId(item)) == -1) {
if (api.getId(item) == -2 || api.getId(item) - 3) {
bankUsers = new Array();
bankUsers[0] = api.getId(item);
} else {
bankUsers.push(api.getId(item));
}
}
} else if (eventName == 'unchecked') {
if (bankUsers.indexOf(api.getId(item)) != -1) {
if (api.getId(item) == -2 || api.getId(item) - 3) {
bankUsers = new Array();
} else {
bankUsers.splice(bankUsers.indexOf(api.getId(item)), 1);
}
}
}
you can use this function :
var parentID = api.itemData(api.parent(item)).id;
as simple as this.
if .id give undefiend you can use the following:
var parentID = api.getId(api.parent(item));
How can I simply the below if statements?
if ( isset(var1) & isset(var2) ) {
if ( (var1 != something1) || (var2 != something2) ) {
// ... code ...
}
}
Seems like this could be condensed to only one IF statement but am not certain if I'd use an AND or OR
Boolean varsAreSets = isset(var1) & isset(var2); // or some other name that indicates what this is doing
Boolean someMeaningfulName = (var1 != something1) || (var2 != something2); // would suggest a meaningful name but don't know what this is accomplishing
if ( varsAreSets && someMeaningfulName ) {
// ... code ...
}
This makes the code very readable and helps you and whoever reads the code understand what these checks are actually doing.
if (isset(var1) && ((var1 != something1) || (var1 != something2)))
// ... code ...
}
You would use an and because you can only get to the // ... code ... part if both if-statements are true.
You can do:
if(isset(var1) && isset(var2) && ( (var1 != something1) || (var1 != something2) ) ){
//..code
}
As a general example:
if( cond1 && cond2 ) {
if( cond3 || cond4) {
// ...code..
}
}
The code will be executed only when both cond1 and cond2 are true and either of cond3 or cond3 is true.
It's a question of in what order your computer interprets boolean logic:
Take for example the following conditions:
A: False
B: True
if you were to write if (A && B) what your computer actually does is think:
Is A true? No.
Well, A and B can't be true because A isn't true. Therefore this statement is false. [computer ignores the rest of the logic]
Because of this, when you evaluate the statement isset(var1) && ( (var1 != something1) || (var1 != something2) ) it first checks isset(var1) and if that's false, then it skips the rest of the condition, just like your double-if statement.
if ( isset(var1) && isset(var2) && ( (var1 != something1) || (var2 != something2) ) ) {
// ... code ...
}
if (isset(var1) && isset(var2) && ((var1 != something1) || (var2 != something2)))
{
// ... code ...
}
Another option:
if (isset(var1) && isset(var2)
&& !(var1 == something1 && var2 == something2)) {
...
I think most of the examples above that have 1 IF may spit out an error if var1 or var2 is NOT set
(isset($var1) && isset($var2)) ? ($var1!='something1' && $var2!='something2') ? $go=TRUE : $go=FALSE : $go = FALSE;
if ($go){
echo 'hello';
}