Hi all,
How to read toast message in android version 7.
Thanks
Hi,
I am also facing the same issue. Any Solution?
Thanks
Solution found.
Use mobile screen(s) captured, then using the approach here to automate:
Do you have any sample scripts here?
Hi U.G.,
You can try this for Android toasts:
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory
import io.appium.java_client.AppiumDriver
AppiumDriver<?> driver = MobileDriverFactory.getDriver()
def toast = driver.findElementByXPath("//android.widget.Toast[@text='Added to cart']")
Hope this helps,
Chris
@Chris_Trevarthen This code didnāt work.
Can not capturer Toast message on Android. were you able to capture Toast message?
Iām able to capture the toast message on an Android emulator using API v27. Note that my tests are using āuiautomator2ā, which I think is whatās required for capturing the toasts. I didnāt have to do anything special to set that up, though, it seemed to be the default. You should be able to see in your logs the automationName
property of Desired Capabilities whether uiautomator 2 is being used.
I wonder if you could log out what Appium thinks is on the screen at the time when the toast appears. If you want to see some more detail about exactly what Appium/Katalon detects on the screen you can log out the XML contents of the screen. You should be able to do that by putting the following import statements at the top of your test case:
import com.kms.katalon.core.logging.KeywordLogger
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory
import io.appium.java_client.AppiumDriver
Then in the code for your test, add the following right after the toast is expected to appear:
AppiumDriver<?> driver = MobileDriverFactory.getDriver()
KeywordLogger log = new KeywordLogger()
log.logInfo(driver.getPageSource())
When the test runs, you should see an entry in the Log Viewer for āStatement - log.logInfo(driver.getPageSource())ā that shows the start of the XML for the screen. If you tap on it, youāll see all of the XML for the screen on the right-hand pane.
I would check that XML to see if the toast shows up there. If not, then you might consider adding a MobileBuiltInKeywords.delay()
of a second and try printing the screen again to see if the test check is firing before the toast appears.
Hope this helps,
Chris
My XML isnāt picking up the toast message. I try adding the delay but nothing is showing up.
is your value for automationName - āuiautomator 2ā with a space or āUiAutomator2ā?
AppiumDriver<?> what goes inside the "<?>"
āWhat version of Appium do you have?
When logging my Desired Capabilities, the automationName shows as uiautomator2
(all one word, all lower case). Hereās what my full Desired Capabilities output looks like:
{"desiredCapabilities":
{"app":"/Users/chris/mobile-beta.apk",
"autoGrantPermissions":true,
"automationName":"uiautomator2",
"bootstrapPath":"/Users/chris/WebDriverAgent",
"deviceId":"emulator-5554",
"deviceName":"emulator-5554 (Android SDK built for x86 - Android 8.1.0)",
"fullReset":false,
"newCommandTimeout":1800,
"noReset":true,
"platform":"ANDROID",
"platformName":"Android",
"udid":"emulator-5554",
"usePrebuiltWDA":true,
"useXctestrunFile":true
}
If you walk through your app with the Katalon Mobile Spy, are you able to see the toast, especially are you able to capture it as a Test Object when it shows on your screen? If not, that might be a sign of some other incompatibility with an Android SDK version.
ā Chris
Object Spy Isnāt seeing Toast message object. ā I will continue my investigation and see what I can find and up this this forum
Iāve been reading some Appium github posts from people who were unable to view toast messages, and it seems to point to having older versions of Android SDK. I wonder if youāre able to update your version of Android Studio to the latest, could you see the toast messages in the Spy Mobile then?
ā Chris
Did that yesterday but I think I uninstall my VDs and reinstall them and try again.
I updated/reinstalled Android SDK and all my VD.
I am running 5.10 katalon studio
I am running 1.10 Appium - uiautomator2 driver
Still not seeing - toast message
Thatās interesting - I would not have expected Appium 1.10 to work at all (itās been my experience that Katalon didnāt work with anything higher than Appium 1.8.1). Iām using Appium 1.8.1 and Katalon Studio 5.10.1. Any chance you could try with Appium 1.8.1?
NOTE: Appium 1.8.1 isnāt the same as Appium Desktop 1.8.1 - itās a bit confusing with the version numbers. If youāre using Appium Desktop, youāll need Appium Desktop 1.6.3.
ā Chris
Sorry guys was not on this forum actively.
@Zarashima, @U.G.Chinthaka_Devind, here the sample code that works on basic OCR:
-
First you make use Katalon API to capture some pictures/snapshots:
SnapTotal = total snapshots
ScrSnapDir = path to store snapshots as you would need to clear this prior snapshot, sorta like working directory for OCR.
for (def index : (0ā¦SnapTotal)) {
String filename = Mobile.concatenate([
ScrSnapDir,
ā\ā,
āfileā,
index,
ā.pngā] as String[], FailureHandling.STOP_ON_FAILURE)
Mobile.takeScreenshot(filename, FailureHandling.STOP_ON_FAILURE)
} -
You need Tess4j (tess4j-4.0.1.jar, in my case) for the basic OCR as here I not involving yet OpenCV (see another topic created today). Here the basic codes:
Tesseract instance = new Tesseract();
instance.setDatapath(TessDataDir);
instance.setLanguage(TessDataLang);Since Tess4j v4alpha, the whitelist seems broken; thus, left out from here.
Basically variables, you can assign via Katalon Profiles:
TessDataLang = āengā
TessDataDir = āD:\Dev\tools\tessdata.ocrā <- this host the Eng data dictionary (eng.traineddata)
Get files from: https://github.com/tesseract-ocr/tessdata -
Code to perform simple OCR, where imageFile is individual full-path-filename that you snapped earlier that you can perform a loop scan to stop when the TEXT you looking for found.
try {
String result = instance.doOCR(imageFile);
}
catch (TesseractException e) {
return āError while reading imageā
}Notes:
- result basically containing TEXT that from OCR.
- If no matched TEXT found after all snapped files processed and you sure one of the image is containing the TEXT that needs recognized; this you would need OpenCV to further enhanced the image for more āfinerā before passing to doOCR().
-
Here the list of Java imports used and you need to place all the depending JAR files imported to Katalon Project or manual copy to Drivers folder (restart Katalon) you are sorted.
import net.sourceforge.tess4j.Tesseract as Tesseract;
import net.sourceforge.tess4j.TesseractException as TesseractException;
Let me know any further help needed.
Cheers.
At least once, you would need the Mobile simulator for generating the snaps.
For the above simple OCR, you donāt need Appium or any Device-simulator to up, you can even create a simple UT just for OCR testing to one or some picture files.
You can make use, e.g., Chrome Headless for the UT.
@GeneralChingChicken, there are a few ways you can take photo of the toast message:
-
Manually and the toast message stay ālongā enough for the snap, e.g., Spy Mobile.
-
Automatically using loop, see my sample code step-1 (above).
That to perform right after some āsimulationā steps of which surely will trigger the toast message to appear, you just snap for some pictures immediately after your/the submission.
Before you get to either option 1 or 2, ensure you can manually simulate the toast-message successfully for starter.
Cheers.
Still no luck,
I did what you mention, and ran object spy but still no luck. No clue whats going on.
@GeneralChingChicken, you cannot use latest Appium version, but to downgrade it.
Try this command for specific version:
npm install -g appium@1.8.1
Check Katalon supported versions here.
Also, read here further details in relating to above npm command.
After npm install appium, you can then installing appium-doctor as I find this useful to help you resolved any other dependent issues or installer.
Cheers.
To help diagnose further, could you share the console log when you run your test? Iām especially interested in what Appium thinks is on the screen at the time the toast shows up (thatās the output from the driver.getPageSource()
command I mentioned above. However, having the full console log would be helpful.
Also, I realized that I didnāt answer your question from above about what what version of Appium or what goes in the ā?ā for AppiumDriver<?>
.
Iām using Appium Server 1.8.2-beta (although 1.8.1 should be fine for Android).
As for the ā?ā, you just leave it as-is - itās sort of a wildcard when accessing some types of classes.
Thanks,
Chris