Mink testing sites that use alert() and confirm()

3,737 views
Skip to first unread message

SimonC

unread,
Feb 21, 2012, 10:03:53 AM2/21/12
to Behat
Hi again.

I'm using Mink to test a site via the Sahi driver. The site uses
Javascript's confirm() function (eg to confirm deletion of a record),
and I need to test that this works for both 'ok' and 'cancel' buttons.

If I understand it correctly, Sahi supresses the actual alert/confirm
dialog, and defaults to simulating a positive response. This is a good
start, but I also need to test the negative response.

The Sahi documentation discusses this topic a bit (see
http://sahi.co.in/w/_expectconfirm ) but I'm unsure how to translate
this to Mink. Any help on this would be appreciated. :)

It would be good to be able to also run the same tests in Selenium,
but my main focus is Sahi at the moment.

Many thanks.


Simon C.

Darshan Mehta

unread,
Mar 14, 2012, 5:46:12 PM3/14/12
to be...@googlegroups.com
Simon, Did you get any solution to this problem?
Thanks.

ushap

unread,
Apr 18, 2012, 5:57:20 PM4/18/12
to be...@googlegroups.com
Hi Simon,

   Did you find out a solution to this? If so, please share with us.

Thanks,
Usha

Konstantin Kudryashov

unread,
Apr 21, 2012, 3:18:18 AM4/21/12
to be...@googlegroups.com
There's simply no solution. Alert or Ask are called modal windows, because they block currently running script loop till user close those dialogs.

There's simply no way to do it programmatically. That's basically the main reason, why modal dialogs in frontend are bad practice.

-- 
Konstantin Kudryashov
Sent with Sparrow

benjamin lazarecki

unread,
Jun 8, 2012, 10:02:35 AM6/8/12
to be...@googlegroups.com
Hi, with selenium2 you can play with alert, confirm and prompt.

Take a look to my this: https://gist.github.com/2888851

Konstantin Kudryashov

unread,
Jun 11, 2012, 6:27:36 AM6/11/12
to be...@googlegroups.com
Could you add issue to the Mink repo (if it doesn't exist yet).

SimonC

unread,
Jun 12, 2012, 6:45:35 AM6/12/12
to be...@googlegroups.com

Ticket 158 already covers this request, for other drivers. I have added a note to this ticket to specify Sahi: https://github.com/Behat/Mink/issues/158

Mike

unread,
Feb 13, 2013, 7:38:12 AM2/13/13
to be...@googlegroups.com
This looks like what is needed. How do I use this file? Here's what I've tried:

- I've added use Widop\Mink\Extension\PopupDictionary; to TraitedFeatureContext,
- I've put moved my own step definitions from InheritedFeatureContext to TraitedFeatureContext
- I've put class:  'TraitedFeatureContext' into behat.yml

When I do behat -dl the popup functions are listed OK, but when I run the scenario i get

PHP Fatal error:  Cannot access private property Behat\Mink\Driver\Selenium2Driver::$wdSession in /home/mike/Code/features/php54_bootstrap/PopupDictionary.php on line 16

I'm not that well up on traits or the Behat code to know what to do. Any ideas?

Vyacheslav Enis

unread,
May 26, 2013, 10:36:22 PM5/26/13
to be...@googlegroups.com
You must use getWebDriverSession() call instead of direct access to $wdSession.

$this->getSession()->getDriver()->getWebDriverSession()->accept_alert();

harinder kaur

unread,
May 25, 2016, 2:33:12 AM5/25/16
to Behat
I am unable to get getWebDriverSession(), please tell me what files/ dependencies should i use in my project.

Mike

unread,
Jun 2, 2016, 3:53:06 AM6/2/16
to Behat
I haven't used it in a long time but the outline of the file is as follows:

class InheritedFeatureContext extends Behat\MinkExtension\Context\MinkContext
{
    /**
     * @Then /^I wait for the suggestion box to appear$/
     */
    public function iWaitForTheSuggestionBoxToAppear()
    {
        print("In InheritedFeatureContext");
        $this->getSession()->wait(5000, "$('.suggestions-results').children().length > 0");
    }

    /**
     * @Given /^I confirm the popop$/
     */
    public function iConfirmThePopop()
    {
        $this->confirmPopup();
    }

    /**
     * @when /^(?:|I )cancel the popup$/
     */
    public function cancelPopup()
    {
        $this->getSession()->getDriver()->getWebDriverSession()->dismiss_alert();
    }

    /**
     * @When /^(?:|I )should see "([^"]*)" in popup$/
     *
     * @param string $message The message.
     *
     * @return bool
     */
    public function assertPopupMessage($message)
    {
        return $message == $this->getSession()->getDriver()->getWebDriverSession()->getAlert_text();
    }

    /**
     * @When /^(?:|I )fill "([^"]*)" in popup$/
     *
     * @param string $message The message.
     */
    public function setPopupText($message)
    {
        $this->getSession()->getDriver()->getWebDriverSession()->postAlert_text(array("text" => $message));
    }

HTH.

On Wednesday, 25 May 2016 08:33:12 UTC+2, harinder kaur wrote:
I am unable to get getWebDriverSession(), please tell me what files/ dependencies should i use in my project.,
Reply all
Reply to author
Forward
0 new messages