How to automate a Toast message in Appium without taking screen shot?











up vote
0
down vote

favorite












I want to test a Toast message without taking screen shot. Is there any other way to automate the Toast message?










share|improve this question
























  • You can get toast message text and verify it as expected
    – Ishita Shah
    Nov 12 at 11:11










  • Could u please tell me, how can we achieve that?
    – Navya Chinnari
    Nov 13 at 7:03










  • you can refer below example.
    – Ishita Shah
    Nov 13 at 7:16










  • How can we get toast message XPATH? (Regarding 1st two lines of code)
    – Navya Chinnari
    Nov 13 at 7:22












  • That you have to inspect it anyhow, It is bit complex, But it can inspect.
    – Ishita Shah
    Nov 13 at 7:24















up vote
0
down vote

favorite












I want to test a Toast message without taking screen shot. Is there any other way to automate the Toast message?










share|improve this question
























  • You can get toast message text and verify it as expected
    – Ishita Shah
    Nov 12 at 11:11










  • Could u please tell me, how can we achieve that?
    – Navya Chinnari
    Nov 13 at 7:03










  • you can refer below example.
    – Ishita Shah
    Nov 13 at 7:16










  • How can we get toast message XPATH? (Regarding 1st two lines of code)
    – Navya Chinnari
    Nov 13 at 7:22












  • That you have to inspect it anyhow, It is bit complex, But it can inspect.
    – Ishita Shah
    Nov 13 at 7:24













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I want to test a Toast message without taking screen shot. Is there any other way to automate the Toast message?










share|improve this question















I want to test a Toast message without taking screen shot. Is there any other way to automate the Toast message?







appium appium-android






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 at 8:32









greuze

2,31832550




2,31832550










asked Nov 12 at 10:44









Navya Chinnari

112




112












  • You can get toast message text and verify it as expected
    – Ishita Shah
    Nov 12 at 11:11










  • Could u please tell me, how can we achieve that?
    – Navya Chinnari
    Nov 13 at 7:03










  • you can refer below example.
    – Ishita Shah
    Nov 13 at 7:16










  • How can we get toast message XPATH? (Regarding 1st two lines of code)
    – Navya Chinnari
    Nov 13 at 7:22












  • That you have to inspect it anyhow, It is bit complex, But it can inspect.
    – Ishita Shah
    Nov 13 at 7:24


















  • You can get toast message text and verify it as expected
    – Ishita Shah
    Nov 12 at 11:11










  • Could u please tell me, how can we achieve that?
    – Navya Chinnari
    Nov 13 at 7:03










  • you can refer below example.
    – Ishita Shah
    Nov 13 at 7:16










  • How can we get toast message XPATH? (Regarding 1st two lines of code)
    – Navya Chinnari
    Nov 13 at 7:22












  • That you have to inspect it anyhow, It is bit complex, But it can inspect.
    – Ishita Shah
    Nov 13 at 7:24
















You can get toast message text and verify it as expected
– Ishita Shah
Nov 12 at 11:11




You can get toast message text and verify it as expected
– Ishita Shah
Nov 12 at 11:11












Could u please tell me, how can we achieve that?
– Navya Chinnari
Nov 13 at 7:03




Could u please tell me, how can we achieve that?
– Navya Chinnari
Nov 13 at 7:03












you can refer below example.
– Ishita Shah
Nov 13 at 7:16




you can refer below example.
– Ishita Shah
Nov 13 at 7:16












How can we get toast message XPATH? (Regarding 1st two lines of code)
– Navya Chinnari
Nov 13 at 7:22






How can we get toast message XPATH? (Regarding 1st two lines of code)
– Navya Chinnari
Nov 13 at 7:22














That you have to inspect it anyhow, It is bit complex, But it can inspect.
– Ishita Shah
Nov 13 at 7:24




That you have to inspect it anyhow, It is bit complex, But it can inspect.
– Ishita Shah
Nov 13 at 7:24












2 Answers
2






active

oldest

votes

















up vote
0
down vote













You can get toast message and define Success/Fail operation:



By toastContainer = By.xpath("//div[@id='toast-container']//*");
By toastMessageDA = By.xpath("//div[@class='toast-message']");

public String toastUtility() throws Exception {
toast_container_flag = false;
try {
if (driver.findElement(toastContainer).isEnabled()) {

toast_container_flag = true;

List<WebElement> findData = driver.findElements(toastContainer);
for (WebElement element : findData) {
if (element.getAttribute("class").toString().contains("toast toast")) {
toast_success_fail = element.getAttribute("class").toString();
}
}
validationMessage = "Toast: " + driver.findElement(toastMessageDA).getText();
js.executeScript("arguments[0].click();", driver.findElement(toastMessageDA));

if (toastr_success_fail.equals("toast toast-success")) {
System.out.println("Success Message");
} else if (toastr_success_fail.equals("toast toast-error")) {
System.out.println("Fail Message");
} else {
System.out.println("Other Message");
}
System.out.println(validationMessage);
testResult = validationMessage;
}
} catch (Exception e2) {
testResult = "Toast message is not generated.";
testlog.info(testResult);
System.out.println(testResult);
}
return testResult;
}





share|improve this answer




























    up vote
    0
    down vote













    Retrieval of toast messages is already supported for Android. Please look at the below release notes for Android.



    https://github.com/appium/appium/releases/tag/v1.6.3



    You need to use UIAutomator2 to work with toast messages in Android.



    Hope this helps.






    share|improve this answer





















    • Please tell me how to install UIAutomator2?
      – Navya Chinnari
      Nov 14 at 5:20










    • @NavyaChinnari Please update your Android SDK. If you already have updated sdk, then you can directly start using UIAutomator2.
      – Vinod
      Nov 15 at 6:03











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53260481%2fhow-to-automate-a-toast-message-in-appium-without-taking-screen-shot%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    You can get toast message and define Success/Fail operation:



    By toastContainer = By.xpath("//div[@id='toast-container']//*");
    By toastMessageDA = By.xpath("//div[@class='toast-message']");

    public String toastUtility() throws Exception {
    toast_container_flag = false;
    try {
    if (driver.findElement(toastContainer).isEnabled()) {

    toast_container_flag = true;

    List<WebElement> findData = driver.findElements(toastContainer);
    for (WebElement element : findData) {
    if (element.getAttribute("class").toString().contains("toast toast")) {
    toast_success_fail = element.getAttribute("class").toString();
    }
    }
    validationMessage = "Toast: " + driver.findElement(toastMessageDA).getText();
    js.executeScript("arguments[0].click();", driver.findElement(toastMessageDA));

    if (toastr_success_fail.equals("toast toast-success")) {
    System.out.println("Success Message");
    } else if (toastr_success_fail.equals("toast toast-error")) {
    System.out.println("Fail Message");
    } else {
    System.out.println("Other Message");
    }
    System.out.println(validationMessage);
    testResult = validationMessage;
    }
    } catch (Exception e2) {
    testResult = "Toast message is not generated.";
    testlog.info(testResult);
    System.out.println(testResult);
    }
    return testResult;
    }





    share|improve this answer

























      up vote
      0
      down vote













      You can get toast message and define Success/Fail operation:



      By toastContainer = By.xpath("//div[@id='toast-container']//*");
      By toastMessageDA = By.xpath("//div[@class='toast-message']");

      public String toastUtility() throws Exception {
      toast_container_flag = false;
      try {
      if (driver.findElement(toastContainer).isEnabled()) {

      toast_container_flag = true;

      List<WebElement> findData = driver.findElements(toastContainer);
      for (WebElement element : findData) {
      if (element.getAttribute("class").toString().contains("toast toast")) {
      toast_success_fail = element.getAttribute("class").toString();
      }
      }
      validationMessage = "Toast: " + driver.findElement(toastMessageDA).getText();
      js.executeScript("arguments[0].click();", driver.findElement(toastMessageDA));

      if (toastr_success_fail.equals("toast toast-success")) {
      System.out.println("Success Message");
      } else if (toastr_success_fail.equals("toast toast-error")) {
      System.out.println("Fail Message");
      } else {
      System.out.println("Other Message");
      }
      System.out.println(validationMessage);
      testResult = validationMessage;
      }
      } catch (Exception e2) {
      testResult = "Toast message is not generated.";
      testlog.info(testResult);
      System.out.println(testResult);
      }
      return testResult;
      }





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        You can get toast message and define Success/Fail operation:



        By toastContainer = By.xpath("//div[@id='toast-container']//*");
        By toastMessageDA = By.xpath("//div[@class='toast-message']");

        public String toastUtility() throws Exception {
        toast_container_flag = false;
        try {
        if (driver.findElement(toastContainer).isEnabled()) {

        toast_container_flag = true;

        List<WebElement> findData = driver.findElements(toastContainer);
        for (WebElement element : findData) {
        if (element.getAttribute("class").toString().contains("toast toast")) {
        toast_success_fail = element.getAttribute("class").toString();
        }
        }
        validationMessage = "Toast: " + driver.findElement(toastMessageDA).getText();
        js.executeScript("arguments[0].click();", driver.findElement(toastMessageDA));

        if (toastr_success_fail.equals("toast toast-success")) {
        System.out.println("Success Message");
        } else if (toastr_success_fail.equals("toast toast-error")) {
        System.out.println("Fail Message");
        } else {
        System.out.println("Other Message");
        }
        System.out.println(validationMessage);
        testResult = validationMessage;
        }
        } catch (Exception e2) {
        testResult = "Toast message is not generated.";
        testlog.info(testResult);
        System.out.println(testResult);
        }
        return testResult;
        }





        share|improve this answer












        You can get toast message and define Success/Fail operation:



        By toastContainer = By.xpath("//div[@id='toast-container']//*");
        By toastMessageDA = By.xpath("//div[@class='toast-message']");

        public String toastUtility() throws Exception {
        toast_container_flag = false;
        try {
        if (driver.findElement(toastContainer).isEnabled()) {

        toast_container_flag = true;

        List<WebElement> findData = driver.findElements(toastContainer);
        for (WebElement element : findData) {
        if (element.getAttribute("class").toString().contains("toast toast")) {
        toast_success_fail = element.getAttribute("class").toString();
        }
        }
        validationMessage = "Toast: " + driver.findElement(toastMessageDA).getText();
        js.executeScript("arguments[0].click();", driver.findElement(toastMessageDA));

        if (toastr_success_fail.equals("toast toast-success")) {
        System.out.println("Success Message");
        } else if (toastr_success_fail.equals("toast toast-error")) {
        System.out.println("Fail Message");
        } else {
        System.out.println("Other Message");
        }
        System.out.println(validationMessage);
        testResult = validationMessage;
        }
        } catch (Exception e2) {
        testResult = "Toast message is not generated.";
        testlog.info(testResult);
        System.out.println(testResult);
        }
        return testResult;
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 at 7:16









        Ishita Shah

        2,0451324




        2,0451324
























            up vote
            0
            down vote













            Retrieval of toast messages is already supported for Android. Please look at the below release notes for Android.



            https://github.com/appium/appium/releases/tag/v1.6.3



            You need to use UIAutomator2 to work with toast messages in Android.



            Hope this helps.






            share|improve this answer





















            • Please tell me how to install UIAutomator2?
              – Navya Chinnari
              Nov 14 at 5:20










            • @NavyaChinnari Please update your Android SDK. If you already have updated sdk, then you can directly start using UIAutomator2.
              – Vinod
              Nov 15 at 6:03















            up vote
            0
            down vote













            Retrieval of toast messages is already supported for Android. Please look at the below release notes for Android.



            https://github.com/appium/appium/releases/tag/v1.6.3



            You need to use UIAutomator2 to work with toast messages in Android.



            Hope this helps.






            share|improve this answer





















            • Please tell me how to install UIAutomator2?
              – Navya Chinnari
              Nov 14 at 5:20










            • @NavyaChinnari Please update your Android SDK. If you already have updated sdk, then you can directly start using UIAutomator2.
              – Vinod
              Nov 15 at 6:03













            up vote
            0
            down vote










            up vote
            0
            down vote









            Retrieval of toast messages is already supported for Android. Please look at the below release notes for Android.



            https://github.com/appium/appium/releases/tag/v1.6.3



            You need to use UIAutomator2 to work with toast messages in Android.



            Hope this helps.






            share|improve this answer












            Retrieval of toast messages is already supported for Android. Please look at the below release notes for Android.



            https://github.com/appium/appium/releases/tag/v1.6.3



            You need to use UIAutomator2 to work with toast messages in Android.



            Hope this helps.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 13 at 11:10









            Vinod

            714313




            714313












            • Please tell me how to install UIAutomator2?
              – Navya Chinnari
              Nov 14 at 5:20










            • @NavyaChinnari Please update your Android SDK. If you already have updated sdk, then you can directly start using UIAutomator2.
              – Vinod
              Nov 15 at 6:03


















            • Please tell me how to install UIAutomator2?
              – Navya Chinnari
              Nov 14 at 5:20










            • @NavyaChinnari Please update your Android SDK. If you already have updated sdk, then you can directly start using UIAutomator2.
              – Vinod
              Nov 15 at 6:03
















            Please tell me how to install UIAutomator2?
            – Navya Chinnari
            Nov 14 at 5:20




            Please tell me how to install UIAutomator2?
            – Navya Chinnari
            Nov 14 at 5:20












            @NavyaChinnari Please update your Android SDK. If you already have updated sdk, then you can directly start using UIAutomator2.
            – Vinod
            Nov 15 at 6:03




            @NavyaChinnari Please update your Android SDK. If you already have updated sdk, then you can directly start using UIAutomator2.
            – Vinod
            Nov 15 at 6:03


















             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53260481%2fhow-to-automate-a-toast-message-in-appium-without-taking-screen-shot%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to send String Array data to Server using php in android

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

            Is anime1.com a legal site for watching anime?