How to read toast message in android


#21

Hi @Chris_Trevarthen

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

1000 Thanks in advance


#22

Refer to this guide: https://appiumpro.com/editions/64


#23

Hi @walpokbymon,

There’s not a whole lot to show in a video, but I can try to explain it step by step:

  1. 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.

  2. Once you’ve finished recording your test, open your new test case file

  3. Click the tab at the bottom of the test case for “Script” - you’ll see the code for the test

  4. At the top of the test file, copy and paste the following lines:

    import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory
    import io.appium.java_client.AppiumDriver
    import com.kms.katalon.core.util.KeywordUtil
    
  5. Find the spot in the test code right after you perform the action that triggers the toast.

  6. Copy and paste the following lines after the action that triggers the toast:

    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!')
    }
    
  7. Change the 'Added to cart' text to whatever the text of your toast should say.

  8. Save the test file

  9. Run your test

  10. Look at the “Console” tab of the test for the text “Toast element”

  11. If all goes well, your tests will pass. If for some reason the toast cannot be found, the test will fail when detecting it.

Hope this helps,

Chris


#24

Hi @Chris_Trevarthen

It works :tada::tada::tada:
You’re just awesome :muscle:

Thank you so much Chris :clap: