dongpuchao1680 2016-04-20 21:48
浏览 159

尝试使用Selenium运行behat时,继续发生致命错误

I have been trying to figure this out for 3 hours, and can't seem to understand why this is not working. My selenium server starts up fine.

When I run behat using selenium I keep getting the following error on my terminal

 Fatal error: Call to a member function open() on null (Behat\Testwork\Call\Exception\FatalThrowableError)

I am have no idea what this error message means. If someone can please help me figure this out I would really appreciate it.

Here below is my features context code where the issue is happening

use Behat\Behat\Tester\Exception\PendingException;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext;
use Behat\Mink\Driver\Selenium2Driver;

/**
 * Defines application features from the specific context.
 */
class FeatureContext extends MinkContext implements Context, SnippetAcceptingContext
{

    public  $session;

    public function __construct()
    {


        $driver = new \Behat\Mink\Driver\Selenium2Driver('firefox');
        $this->session = new \Behat\Mink\Session($driver);
    }



}
  • 写回答

1条回答 默认 最新

  • douling6469 2016-04-22 12:08
    关注

    Do something like below:

    class FeatureContext extends MinkContext
    {
        public function __construct()
        {
            // Don't do anything with session or driver here
        }
    
        /**
         * @Then /^I need selenium driver for this step$/
         */
        public function iNeedSeleniumDriverForThisStep()
        {
            $driver = $this->getSession()->getDriver();
    
            if (!$driver instanceof Selenium2Driver) {
                throw new UnsupportedDriverActionException('Selenium2Driver not installed.');
    
                return;
            }
    
            // ......
            // ......
            // Do whatever you want
        }
    }
    

    Example behat.yml

    default:
        context:
            class: FeatureContext
        extensions:
            Behat\Symfony2Extension\Extension:
                mink_driver: true
                kernel:
                    env: test
                    debug: true
            Behat\MinkExtension\Extension:
                base_url: 'http://symfony.local/app_test.php/'
                files_path: %behat.paths.base%/build/dummy/
                javascript_session: selenium2
                browser_name: firefox
                goutte: ~
                selenium2: ~
        paths:
            features: %behat.paths.base%/src
            bootstrap: %behat.paths.features%/Context
    

    Also search for Selenium2Driver and selenium keyword in this site: http://www.inanzzz.com/index.php/posts/behat

    评论

报告相同问题?