Can someone explain to me in layman terms how command isEnabled() works in Appium Scenario: There are 3 checkboxes on a specific mobile page. - Checkbox 1, Checkbox2 & Checkbox3 “Checbox3” is disabled by default and only enables when we select “Checkbox2”
TC is to verify if “Checkbox3” is disabled by default and print the following output “Checkbox3 is currently Disabled”
Once the “Checkbox3” is enabled we need to print the following output “Checkbox3 is currently Enabled”
I am executing this as a TestNG and am using the following line of code
boolean FirstValue = XMLPage.ListofCheckboxes.get(2).isEnabled();
System.out.println(FirstValue);
if(FirstValue=false)
{
System.out.println("Checkbox3 is currently Disabled");
}
else
{
System.out.println("Checkbox3 is currently Enabled");
}
Thread.sleep(4000);
XMLPage.ListofCheckboxes.get(1).click();
boolean SecondValue = XMLPage.ListofCheckboxes.get(2).isEnabled();
System.out.println(SecondValue);
if(SecondValue=true)
{
System.out.println("Checkbox3 is currently Enabled");
}
else
{
System.out.println("Checkbox3 is currently Disabled");
}
Expected Output :
Actual Output:
The first time it encounters the if statement shouldn’t it print the output as "Checkbox3 is currently Disabled" I am not sure why it prints the output mentioned under ‘else’{i.e.:- "Checkbox3 is currently Enabled"}. As displayed in the output the value returned by command “boolean FirstValue = XMLPage.ListofCheckboxes.get(2).isEnabled();” is false and hence the code should print the output mentioned under ‘if’ and not ‘else’.
The if statement you are using in your code is wrong.
if statement in your code
if(FirstValue=false){
....
}
this is an assignment operation since you use a single = symbol. What it will do is, it will assign FirstValue equal to false, then since the value inside the if block now is false, it is going to the else block. This is a valid operation so it will compile fine. But the if statement should be a comparison step like below using == symbol,
if statement should be a comparison step,
if(FirstValue==false){
....
}
This is the reason for your wrong output.