PHP Mink/Zombie - handling hanging processes after a fatal exception?

江枫思渺然 提交于 2019-11-29 18:02:26

First thing to do in order to avoid fatal exceptions is to implement/use methods with proper error handling. You can create a method to check if the element is not null and if it is to throw a custom exception.

For example in your case findField method will return null if the element is not found, in this case setValue will e used on a non-object resulting in a fatal error.

An example of exception handling is:

public function fillWith($locator, $text){
        $element = $this->getSession()->getPage()->find("xpath", $locator);

        if($element === null){
            throw new Exception("Element $locator not found");
        }else{
            $element->setValue($text);
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!