WaitforElement not showing as fail in the report if the element not found

I am using Appium Studio 11.7.103 and executed the scripts using eclipse.I had created my own framework for the android automation using pageobject model.
Problem: I am using below code.I am using this for the element to be visible and then continues the next functionality.
But the problem is after waiting if the element is not found the testcase fails and showing error in the eclipse console.But coming to the report it is displaying as pass.How to solve this issue I want to be failed if element not found.
public void waitforelement(By element){
WebDriverWait wait = new WebDriverWait(driver, 30);
}catch(Exception e){
Log_Message(“Unable to find the element”, “false”);

Can someone help me about this

Is your Assertion framework JUNIT or TESTNG ?? The wait.unit will throw a TimeoutException if the element is not found. Your exception handler will catch this and based on your code. This in of itself will not fail a test if JUNIT or TESTNG is being used.

If your code is using TESTNG for the assertion framework, you’d up date your exception handler with something like:

catch(Exception e){
Log_Message(“Unable to find the element”, “false”);

The assert will cause TESTNG to consider the test a failed test.

Thanks for the reply.I am using testng framework.I had changed and made some modification like removed implicity wait and using only explicit wait.So in explicit wait if I use 30 seconds,it will check for the element continuously for 30seconds.During that time if the element not found in the first check,the step in the report is displaying as fail but after second or third check if the element is found then the next step in the report is displayed as pass.But my testcase report showing as failed.How to solve this I want testcase to show as pass.

Please provide the code for us to look at

Thanks in advance.Below code is the common method for Waitforelement:

public void waitforelement(By element){
WebDriverWait wait = new WebDriverWait(driver, 45);
}catch(Exception e){
System.out.println(“error :”+e);
Log_Message(“Unable to find the element”, “false”);


Below code is the basetest/beforemethod :

dc.setCapability(“reportDirectory”, reportDirectory_total);
dc.setCapability(“reportFormat”, reportFormat);
dc.setCapability(“testName”, m.getName());
dc.setCapability(“autoAcceptAlerts”, false);
dc.setCapability(“attach.crash.logs.to.reports”, true);
dc.setCapability(“setShowPassImageInReport”, false);
dc.setCapability(“autoGrantPermissions”, true);
dc.setCapability(MobileCapabilityType.UDID, commonProperties.getProperty(“Android_UDID”));
dc.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, commonProperties.getProperty(“Android_Package_Name”));
dc.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, “.home.SplashActivity”);
dc.setCapability(MobileCapabilityType.NO_RESET, true);
dc.setCapability(MobileCapabilityType.FULL_RESET, false);
dc.setCapability(MobileCapabilityType.PLATFORM_NAME, commonProperties.getProperty(“Platform_name”));
dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, commonProperties.getProperty(“Platform_version”));
dc.setCapability(MobileCapabilityType.DEVICE_NAME, commonProperties.getProperty(“Device_name”));
dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, commonProperties.getProperty(“Automation_name”));
driver = new AndroidDriver(new URL(“http://localhost:”+commonProperties.getProperty(“Appium_host”)+"/wd/hub"), dc);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

Below are the teststeps and failed while waitforelement is executed during loading.The very next step the teststep showing as passed.So due to this my testcase showing as failed.

Hi @wakelt I had provide the detailed code. Could you please help me.

I don’t see where the waitForElement() method is called in your code. I see the implicit wait, but no waitForElement() calls. Is your intent to use waitForElements throughout the test, or just the first “findElement” ? Can you widen the xpaths so I can see them ? More precision in your description is required.

Remember that using “visibility” in your ExpectedCondition doesn’t just look for an elements presence. It also looks at height and width. If the element hasn’t been “rendered” yet, then you want to use “presenceOfElementLocated” as opposed to “visibilityOfElementLocated”.

I am using POM and I am calling waitforElement() in pageobject class (Teststep method) for findElement.

For example:

public void Verify_Request_Money_Success() {
CommonFunc cf=new CommonFunc(driver);
if(Payee_RequestMoney_Success_Popup().isDisplayed()) {
cf.Log_Message(“Request sent successfully”, “true”);
}else {
cf.Log_Message(“Request not sent”, “false”);

and xpath is declared as below :

By Payee_RequestMoney_Success_popup = By.xpath("//*[@text=‘Request Sent Successfully’]");

I don’t want to check for height and width.Just I need to wait for that element visible. So should I use “presenceOfElementLocated”?

Please answer the following question(s) so I can try to help:

  1. are the first two findElements using the “expected condition”, or only the first ?
  2. are the first two find element xpaths the same (I had asked for you to widen the xpaths in the illustration so I could see them)

1.yes,the first two findelements using the expected condition
2.yes,the first two findelement xpaths are same.

Hey If u don’t mind can we have a call so that I can share the screen so that it will be easy for both of us or else tell me ur personal mail id I will share the project files including the report.

Hi @wakelt I tried presenceOfElementLocated also.But still no use.

If you want someone to take a deep dive via phone call that should be someone from Experitest. I do not work for Experitest and look at the board when I have free time (which isn’t often :-).

I have seen problems in the past when mixing implicit and explicit waits. Can you comment out your implicit wait, or set to same value as your explicit wait, for the purposes of this debug effort ? any difference ?

I refer you to: http://www.aptuz.com/blog/selenium-implicit-vs-explicit-waits/

Hey thanks a lot. I had set the value for implicit wait and explicit wait as 45.Now its working fine for current functionlity. Need to check for flash messages whether this works or not. Will check and update you if it is working for flash messages also.

My invoice is in the mail :-).

Agains, mixing implicits and explicits in the same code is tricky. You should rethink this.

But if I removed implicits, its not working for Flash messages