public static function get($classname) {
        $contexts = self::$environment->getContexts();

        foreach ($contexts as $context) {
            if (is_a($context, $classname)) {
                return $context;
            }
        }

        $suitename = self::$environment->getSuite()->getName();
        // If default suite, then get the default theme name.
        if ($suitename == 'default') {
            $suitename = theme_config::DEFAULT_THEME;
        }
        $overridencontextname = 'behat_theme_'.$suitename.'_'.$classname;

        // If contexts has not been checked before and doesn't exist then just use core one.
        if (!isset(self::$nonexistingcontexts[$overridencontextname])) {
            try {
                $subcontext = self::$environment->getContext($overridencontextname);

                return $subcontext;
            } catch (Behat\Behat\Context\Exception\ContextNotFoundException $e) {
                // If context not found then it's not overridden.
                self::$nonexistingcontexts[$overridencontextname] = 1;
            }
        }

        // Get the actual context.
        return self::$environment->getContext($classname);
    }