I followed several of your interventions on this forum which are very interesting for me and that allowed me to use Katalon studio well I thank you very much
I am not a developer so I find it difficult to follow the code and script
For the moment and in the same context of the previous messages I am trying to know how to verify a message on a toast, but when I record a scenario, the toast is not detected by Katalon Studio therefore there is a solution to capture toast and do a test on the message that is on it.
I read your February 25 message on the same topic but I do not know where do I put the code you mentioned
Is it possible to make a demonstrative video in the subject âHow to detect a toast and check the text on itâ
I use Katalon Version: 5.10.1 Build: 1
Appium 1.8.1 (recomended by you)
Iâm using a local Samsung S7 device that is linked by USB to a Sierra macOS version 10.12.6
Thereâs not a whole lot to show in a video, but I can try to explain it step by step:
Record a test using the Record Mobile feature of Katalon Studio (you have probably already done this). You will probably not be able to record the toast message - weâll put that in later.
Once youâve finished recording your test, open your new test case file
Click the tab at the bottom of the test case for âScriptâ - youâll see the code for the test
At the top of the test file, copy and paste the following lines:
Could you please share your test script where youâre trying to read the toast? From the error message, it looks like several of the variables already exist, e.g. toast, driver and they are being redefined with the lines def toast = and def driver = within the same test script. Maybe you copy and pasted the lines a couple of times?
If youâre trying to use the variables again, you can remove the def from all but the first references to those variables in your test script.
When you run the test script from the 2nd image, do you see anything in the console for the line âToast element:â? Could you please include the contents of the console and the log tabs so I can investigate further?
It looks from the logs that the toast is definitely not found. Can you try removing the text qualifier from the xpath to open it up and make it more flexible? For example:
Thanks for the XML, thatâs very helpful. It looks like the toast message is part of the contents of the screen (if you look at the very end of the XML file, itâs there). So thatâs very weird that your test isnât seeing it.
I did notice that the bounds of the object are [0,0] to [0,0] which tells me that itâs probably not visible by the time that XML is logged.
A few things we can try:
Can you try putting that Mobile.delay statement back in to see if the check is happening too fast? I think you should be able to just use Mobile.delay(5) and not pass the FailureHandling parameter.
It looks like youâre using Appium 1.17.1. Iâm not sure if that would be an issue, but I usually have luck with Appium 1.15.1.
You also might want to make sure your Android Studio and Android SDK are up-to-date.
If youâre still not seeing it work after all this, could you please send an updated console log?
Going back to this solution. Do i still need to add another Verify command to verify the element was visible? Or is this our validation command already?
AppiumDriver<?> driver = MobileDriverFactory.getDriver()
def toast = driver.findElementByXPath(â//android.widget.Toast[@text=âAdded to cartâ]â)
println("Toast element: " + toast)
if (toast == null) {
KeywordUtil.markFailed(âERROR: Toast object not found!â)
}
Typically, if an element isnât visible, it wonât be found and returned by Katalon or Appium, so if your test doesnât error out when getting an element, you can consider it visible without need to further verify it.
When youâre running the test, and observing the simulator or device, do you actually see the toast message appear?
As for the test youâre trying to run, can change any of the test code you were using for the toast to this simple check to just see if the toast is there:
Then can you check if there is a message in the log that the test fails or âERROR: Toast object not foundâ
Could you also please share the script of the test youâre running (you can view the script display by clicking the âScriptâ tab thatâs located in the middle of the last screenshot you shared. That way I can get a better idea of the other test code youâre running.
Thanks for sharing the script. The key lines that would fail the test if the toast is not found are:
if (toast == null) {
KeywordUtil.markFailed('ERROR: Toast object not found!')
}
So if the toast is not found, the test will be marked as failed.
If you want to be specific about the text on the toast, then you can go back to the toast xpath definition of:
def toast = driver.findElementByXPath('//android.widget.Toast[@text="The email must be a valid email address."]')
In your script, you should then be able to get rid of these lines, which are redundant:
Mobile.verifyElementVisible(findTestObject('Login/InvalidEmail-toast'), 0)
Mobile.verifyElementText(findTestObject('Login/InvalidEmail-toast'), 'The email must be a valid email address.')
After those changes, if the test runs and doesnât fail, you can know that the toast was displayed and has the text youâre looking for.