Slowing Down Test Execution? On Purpose

Hey everyone.
Might be a dumb question but I find that some of the scripts on Android devices (real) are executing too quick and sometimes they fail because they are not finding the elements on the screen, its going so fast.

I am getting like a 50% pass rate as a result.

Is there a way to slow things down at all in the execution of it all?

Create is wrapper class which will wait till the element is display.
For example:
public void waitForElementToBeVisible(AndroidDriver driver,
WebElement parent, String locator[], int iteraionTimeoutInSecs,
int timeOutInSecs,boolean isThrown) throws Exception {
String elementName = (locator[0]).trim();
String elementType = (locator[1]).trim();
String elementValue = (locator[2]).trim();
String elementDescription = (locator[3]).trim();
boolean flag = false;
int count = 0;
while (flag == false) {
Thread.sleep(iteraionTimeoutInSecs * 1000);
try {
// WebElement element = getWebElement(driver,null, locator);
if (isDisplayed(driver, null, locator) == false) {
// while(!driver.findElement(By.id(elementID)).isDisplayed())
logAndroidDriverAPI.info(“Waiting for an element “”
+ elementName +” ["+elementValue
+ “] " to be displayed”,true);
count = count + iteraionTimeoutInSecs;
if (count >= timeOutInSecs) {
logAndroidDriverAPI.info("Element with name “”
+ elementName + “” value “” + elementValue
+ “” is not displayed after timeout "
+ timeOutInSecs,true);
// ErrorUtil.addVerificationFailure(new
// uiElementException("Timeout exception occoured while finding the UI element “+elementName
// +” elementIdentifier " +elementIdentifier));
break;
}
} else {
flag = true;
}
} catch (Exception e) {
logAndroidDriverAPI.error(“Waiting for an element “”
+ elementName + “” to be displayed with an exception”);
count = count + iteraionTimeoutInSecs;
if (count >= timeOutInSecs) {
logAndroidDriverAPI.error("Element with name “”
+ elementName + “” value “” + elementValue
+ “” is not displayed after timeout "
+ timeOutInSecs,true);
logAndroidDriverAPI.error(genCodes.getExceptionMessage(e));
if (isThrown){
throw e;
}else{
break;
}
//throw new AppiumServerException(e,locator);

			}
			
		}
	}
}

In the Ruby client there is a method which does just that:

wait{find_exact("text of the element")}

It waits until finds it by tying every 0.5 seconds by default and 30 seconds of timeout I think

That would be perfect @slipy12 I will give that a try. I am using Java but I think it has this function as well.
It doesn’t seem to happen on all devices, just more powerful ones with newer Android OS’s.

I just want to create tests that will work for all versions and devices we support.

Thanks again guys.

You should read up on Explicit Waits:

http://toolsqa.com/selenium-webdriver/implicit-explicit-n-fluent-wait/