Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test Android toast messages in Appium ( selenium Java)

I am using Selenium with Java to run scripts on android (thru Appium server). I see that it is not possible to locate a toast by using selenium's

driver.findElement(By.LinkText("User not logged in")

in Appium

But can be used in Selendroid to capture toast messages.

I there a way I can use both Selendroid and Appium in the same script?

like image 483
RJX Avatar asked May 26 '15 12:05

RJX


1 Answers

Finally, we are able to read the toast message without the need of taking screenshots and performing OCR. I have tested this on Appium 1.15.1.

Toast messages comes under com.package.system.

Normally, Xpath for this will be "/hierarchy/android.widget.Toast". And, Class Name will be "android.widget.settings"

You can confirm this by refreshing element inspector screen when toast message is displayed.

WebDriverWait waitForToast = new WebDriverWait(driver.25);

waitForToast.until(ExpectedConditions.presenceOfElementLoacted(By.xpath("/hierarchy/android.widget.Toast")));

String toastMessage = driver.findElement((By.xpath("/hierarchy/android.widget.Toast")).getText();

System.out.println(toastMessage);
like image 133
Prajeeth Anand Avatar answered Oct 10 '22 23:10

Prajeeth Anand