0
Boolean EleWNote=this.commonMethods.elementIsVisible(WireNote);

if(EleWNote = true) {
    testStep.log(LogStatus.PASS, "The Element displayed " + wirenote + " successfully");
} else {
    testStep.log(LogStatus.FAIL, "The Element displayed " + wirenote + " not successful");
}

This the part of my code where i give the method and in brackets the web element name and i gave the wrong X path to the web element and it should show me that the element displayed wire note is not successful. but it shows successful.

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95

3 Answers3

2

Change

 if(EleWNote=true)

to

  if(EleWNote==true) 

or

  if(EleWNote)  // this is the recommend way

since EleWNote=true means to assign true to the variable EleWNote

flyingfox
  • 13,414
  • 3
  • 24
  • 39
0

You should write EleWNote==true not EleWNote=true it will assign value to EleWNote not compare them

check below code

if(EleWNote==true)
                {
                    testStep.log(LogStatus.PASS, "The Element displayed " + wirenote + " successfully");
                }
                else
                {
                    testStep.log(LogStatus.FAIL, "The Element displayed " + wirenote + " not successful");
}
Ankur Singh
  • 1,239
  • 1
  • 8
  • 18
0

The expression EleWNote=true assings true to EleWNote, and after it does, the if condition checks weather EleWNote is true, which is always.

You need to use the comparator operator == or === (which i recommend) in if conditions.

In your case since the variable is boolean, you can use if(EleWNote)

My recommended code

if(EleWNote)
{
     testStep.log(LogStatus.PASS, "The Element displayed " + wirenote + " successfully");
}
else
{
     testStep.log(LogStatus.FAIL, "The Element displayed " + wirenote + " not successful");
}
kkica
  • 4,034
  • 1
  • 20
  • 40