Hi,
Basically the requirement is "If either of the two conditions are satisfied than pass it" else fail it
I tried operator like || , ^ nothing worked
if(condition 1 || condition 2)
I tried
if (condition 1 ^ condition 2)
I tried
if(condition1)
{
}
else if (condition 2)
{
}
Else
{
}
Did Not worked
Please let me know what logic can we right to handle such scenario
Please let me know for more details
Regards
How to design nested if-else statement in C# Ranorex
Re: How to design nested if-else statement in C# Ranorex
Hi,
Try this...
Try this...
If it does not help, please post exact conditions you are using.if (condition1| condition2)
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
Re: How to design nested if-else statement in C# Ranorex
This is the piece of code which I am trying to execute
It is successfully executing if block
But in case if "IF" block does not executed, rather then going to else if block it is failing
#region validateDifferenceInReports()
public void validateDifferenceInReports()
{
try
{
if(excelrepo.NewTableCompareTableCompareBeyo.Container1DifferenceRowS.Visible)
{
HtmlReports.SuccessReport("To verify that the difference in the report is not more than 2", "Successfully verified the difference in the report is 2 which is acceptable");
}
else if(excelrepo.NewTableCompareTableCompareBeyo.Container2DifferenceRowS.Visible)
{
HtmlReports.SuccessReport("To verify that the difference in the report is not more than 1", "Successfully verified the difference in the report is 1 which is acceptable");
}
else
{
HtmlReports.FailureReport("To verify that the difference in the report is not more than 2","The difference in the reports is more than 2");
}
}
catch(Exception ex)
{
HtmlReports.FailureReport("To verify that the difference in the report is not more than 2","The difference in the reports is more than 2" + ex.Message);
throw;
}
}
#endregion
It is successfully executing if block
But in case if "IF" block does not executed, rather then going to else if block it is failing
#region validateDifferenceInReports()
public void validateDifferenceInReports()
{
try
{
if(excelrepo.NewTableCompareTableCompareBeyo.Container1DifferenceRowS.Visible)
{
HtmlReports.SuccessReport("To verify that the difference in the report is not more than 2", "Successfully verified the difference in the report is 2 which is acceptable");
}
else if(excelrepo.NewTableCompareTableCompareBeyo.Container2DifferenceRowS.Visible)
{
HtmlReports.SuccessReport("To verify that the difference in the report is not more than 1", "Successfully verified the difference in the report is 1 which is acceptable");
}
else
{
HtmlReports.FailureReport("To verify that the difference in the report is not more than 2","The difference in the reports is more than 2");
}
}
catch(Exception ex)
{
HtmlReports.FailureReport("To verify that the difference in the report is not more than 2","The difference in the reports is more than 2" + ex.Message);
throw;
}
}
#endregion
Re: How to design nested if-else statement in C# Ranorex
Hi,
Basically, after some code re-formating, your code looks like this:
But in my opinion, you should test 'visible' attribute, only after knowing the given element exists! So better code would be like this:
If you directly test 'Visible' attribute and the element does not exists (yet), the code may actually immediately fail (after reaching repo element's Effective Timeout) on 'element does not exists' exception and so it may never reach second 'else if' statement. So you should always test the element's existence, before testing its 'Visibility' (or whatever element's attribute or action).
Additionally, I would suggest to avoid referencing repo elements directly in code and rather use them as method parameters, like this:Hope this helps?
Basically, after some code re-formating, your code looks like this:
Code: Select all
#region validateDifferenceInReports()
public void validateDifferenceInReports()
{
try
{
if(excelrepo.NewTableCompareTableCompareBeyo.Container1DifferenceRowS.Visible)
{
HtmlReports.SuccessReport("To verify that the difference in the report is not more than 2", "Successfully verified the difference in the report is 2 which is acceptable");
}
else if(excelrepo.NewTableCompareTableCompareBeyo.Container2DifferenceRowS.Visible)
{
HtmlReports.SuccessReport("To verify that the difference in the report is not more than 1", "Successfully verified the difference in the report is 1 which is acceptable");
}
else
{
HtmlReports.FailureReport("To verify that the difference in the report is not more than 2","The difference in the reports is more than 2");
}
}
catch(Exception ex)
{
HtmlReports.FailureReport("To verify that the difference in the report is not more than 2","The difference in the reports is more than 2" + ex.Message);
throw;
}
}
#endregion
Code: Select all
#region validateDifferenceInReports()
public void validateDifferenceInReports()
{
try
{
if(excelrepo.NewTableCompareTableCompareBeyo.Container1DifferenceRowSInfo.Exists())
{
if (excelrepo.NewTableCompareTableCompareBeyo.Container1DifferenceRowS.Visible)
{
HtmlReports.SuccessReport("To verify that the difference in the report is not more than 2", "Successfully verified the difference in the report is 2 which is acceptable");
}
}
else if(excelrepo.NewTableCompareTableCompareBeyo.Container2DifferenceRowSInfo.Exists())
{
if (excelrepo.NewTableCompareTableCompareBeyo.Container2DifferenceRowS.Visible)
{
HtmlReports.SuccessReport("To verify that the difference in the report is not more than 2", "Successfully verified the difference in the report is 2 which is acceptable");
}
else
{
HtmlReports.FailureReport("To verify that the difference in the report is not more than 2","The difference in the reports is more than 2");
}
}
else
{
HtmlReports.FailureReport("To verify that the difference in the report is not more than 2","The difference in the reports is more than 2");
}
}
catch(Exception ex)
{
HtmlReports.FailureReport("To verify that the difference in the report is not more than 2","The difference in the reports is more than 2" + ex.Message);
throw;
}
}
#endregion
Additionally, I would suggest to avoid referencing repo elements directly in code and rather use them as method parameters, like this:
Code: Select all
#region validateDifferenceInReports()
public void validateDifferenceInReports(RepoItemInfo container1, RepoItemInfo container2)
{
try
{
if(container1.Exists())
{
if (container1.CreateAdapter<Ranorex.Unknown>(false).Visible)
{
HtmlReports.SuccessReport("To verify that the difference in the report is not more than 2", "Successfully verified the difference in the report is 2 which is acceptable");
}
}
else if(container2.Exists())
{
if (container2.CreateAdapter<Ranorex.Unknown>(false).Visible)
{
HtmlReports.SuccessReport("To verify that the difference in the report is not more than 2", "Successfully verified the difference in the report is 2 which is acceptable");
}
else
{
HtmlReports.FailureReport("To verify that the difference in the report is not more than 2","The difference in the reports is more than 2");
}
}
else
{
HtmlReports.FailureReport("To verify that the difference in the report is not more than 2","The difference in the reports is more than 2");
}
}
catch(Exception ex)
{
HtmlReports.FailureReport("To verify that the difference in the report is not more than 2","The difference in the reports is more than 2" + ex.Message);
throw;
}
}
#endregion
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
Re: How to design nested if-else statement in C# Ranorex
Hi,
Thanks a lot for this information
Its really helpful
Regards
Thanks a lot for this information
Its really helpful
Regards