chuk-shirley
4/13/2018 - 12:16 PM

Behat + Mink wait for modal to be visible

Behat + Mink wait for modal to be visible

class MyContext extends RawMinkContext
{
    private function waitForMyModalToBeVisible()
    {
        $modalId = 'myModal'
        $this->spin(function($context) {
            return ($context->getSession()->getPage()->findById($modalId)->isVisible());
        });
    }
    
    private function spin($lambda)
    {
        while (true)
        {
            try {
                $var = $lambda($this);
                if ($lambda($this)) {
                    return true;
                }
            } catch (\Exception $e) {
                // do nothing
            }

            sleep(1);
        }
    }
}