Results 1 to 6 of 6

Thread: Handling Alerts - Webdriver scenario

  1. #1
    Sencha User oracle7's Avatar
    Join Date
    Jan 2020
    Posts
    13

    Default Answered: Handling Alerts - Webdriver scenario

    Hi,

    have any of you had case with handling alerts after submiting login details?

    Apparently it should be:

    driver.switchTo().alert().dismiss();But I'm not sure how should I execute it.
    Does it go as

    ST.execute(function(){
    driver.switchTo().alert().dismiss();

    })

    which doesn't really work.

    or something like:

    ST.Alert()
    .execute(function(Alert) {
    driver.switchTo().alert().dismiss();
    });

    Either way i want it to be dismissed.

  2. If it's a browser alert, you can try the following in a WebDriver scenario in order to check the alert text, and also accept (close) the alert:

    Code:
    it('should click a button and check alert box', function(done) {
        ST.element('input[value="Click"]')
            .click()
            .and(function() {
                var driver = ST.defaultContext.driver;
                
                driver.alertText()
                    .then(function(text) {
                        expect(text).toContain('hello');  // Check contents of "alert" text
                    })
                    .alertAccept()  // Accept / close the alert
                    .then(done);
            });
    });

  3. #2
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    London, England
    Posts
    383
    Answers
    68

    Default

    If it's a browser alert, you can try the following in a WebDriver scenario in order to check the alert text, and also accept (close) the alert:

    Code:
    it('should click a button and check alert box', function(done) {
        ST.element('input[value="Click"]')
            .click()
            .and(function() {
                var driver = ST.defaultContext.driver;
                
                driver.alertText()
                    .then(function(text) {
                        expect(text).toContain('hello');  // Check contents of "alert" text
                    })
                    .alertAccept()  // Accept / close the alert
                    .then(done);
            });
    });
    Daniel Gallo
    Sales Engineer
    Sencha

  4. #3
    Sencha User oracle7's Avatar
    Join Date
    Jan 2020
    Posts
    13

    Default

    and afterwards if I want to navigate to different url should I use ST.navigate("url") or driver.url("url")

    First option lefts hanging.
    is due to context of the driver?

  5. #4
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    London, England
    Posts
    383
    Answers
    68

    Default

    Where exactly have you placed the "ST.navigate" code? Have you tried placing it in a separate test, to make sure it's executed after the alert has been dismissed?
    Daniel Gallo
    Sales Engineer
    Sencha

  6. #5
    Sencha User oracle7's Avatar
    Join Date
    Jan 2020
    Posts
    13

    Default

    Quote Originally Posted by daniel.gallo View Post
    Where exactly have you placed the "ST.navigate" code? Have you tried placing it in a separate test, to make sure it's executed after the alert has been dismissed?
    Yes I tried it works in separate test, but the issue is that I have to record elements afterwards (insert step recorder).
    So let's assume that I have:
    • Login screen
    • alert (open application in new Window?)
    • Completely new window (in which should I implement ST.navigate)
    • record elements on that new window


    So there's too much shenanigans with switching between windows in sencha test.
    So i tried

    login screen
    open new window -> dismiss alert
    ST.navigate to application (session stays, can't navigate before entering credentials)


    I tried ST.navigate separate test but then I can't make login stuff. (two separate url)
    Maybe if someone from sencha support can reach me via Private message so I can explain scenario further, our company has enterprise license.

  7. #6
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    London, England
    Posts
    383
    Answers
    68

    Default

    The Event Recorder is designed to record against the original browser window, rather than new windows/tabs, so you would need to navigate the current tab to the page you need to record in order to capture actions against it.

    You are welcome to share more details or ask additional questions via support tickets in the Support Portal.
    Daniel Gallo
    Sales Engineer
    Sencha

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •