<commit_before><?php

/**
 * WebDriver - Client for Selenium 2 (a.k.a WebDriver)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @category  Libraries
 * @package   WebDriver
 * @author    <NAME> <<EMAIL>>
 * @copyright 2004-present Facebook
 * @copyright 2012-present MediaSift Ltd
 * @license   http://www.apache.org/licenses/LICENSE-2.0
 * @link      http://www.datasift.com
 * @link      http://facebook.com
 */

namespace DataSift\WebDriver;

/**
 * Main client for interacting with the WebDriver
 *
 * @category Libraries
 * @package  WebDriver
 * @license  http://www.apache.org/licenses/LICENSE-2.0
 * @link     http://www.datasift.com
 * @link     http://facebook.com
 */
class WebDriverClient extends WebDriverBase
{
    protected function getMethods()
    {
        // a list of the JsonWireProtocol methods that this class supports
        return array(
          'status' => 'GET',
        );
    }

    /**
     * create a new session / launch a new browser to control
     *
     * @param  string $browser
     *                the name of the browser to use
     * @param  array  $additional_capabilities
     *                a list of the capabilities that are needed for this test
     *
     * @return WebDriverSession
     *         the new WebDriverSession to use to control the browser
     */
    public function newSession($browser = 'chrome', $additional_capabilities = array())
    {
        // merge the browser name into any additional requested capabilities
        $desired_capabilities = array_merge(
            $additional_capabilities,
            array('browserName' => $browser)
        );

        // tell webdriver to create the new session
        $results = $this->curl(
            'POST',
            '/session',
            array('desiredCapabilities' => $desired_capabilities),
            array(CURLOPT_FOLLOWLOCATION => true)
        );

        // did we get a sessionId back?
        //
        // this happens when SauceLabs doesn't like what we've asked;
        // genuine Selenium WebDriver returns a proper error!
        if(!isset($results['sessionId'])) {
            throw new E5xx_SessionNotCreatedWebDriverError('no error message provided by selenium webdriver, sorry :(');
        }

        // return the session back to the caller
        return new WebDriverSession($results['info']['url'] . '/' .$results['sessionId']);
    }

    /**
     * get a list of active sessions
     *
     * @return array(WebDriverSession)
     *         a list of the sessions that webdriver currently knows about
     */
    public function getSessions()
    {
        // our return value
        $sessions = array();

        // get a raw list of the current sessions
        $result = $this->curl('GET', '/sessions');

        // convert the raw list into an array of WebDriverSession objects
        foreach ($result['value'] as $session) {
            $sessions[] = new WebDriverSession($this->url . '/session/' . $session['id']);
        }
<commit_msg>Fix: use the right URL for a new session<commit_after><?php

/**
 * WebDriver - Client for Selenium 2 (a.k.a WebDriver)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @category  Libraries
 * @package   WebDriver
 * @author    <NAME> <<EMAIL>>
 * @copyright 2004-present Facebook
 * @copyright 2012-present MediaSift Ltd
 * @license   http://www.apache.org/licenses/LICENSE-2.0
 * @link      http://www.datasift.com
 * @link      http://facebook.com
 */

namespace DataSift\WebDriver;

/**
 * Main client for interacting with the WebDriver
 *
 * @category Libraries
 * @package  WebDriver
 * @license  http://www.apache.org/licenses/LICENSE-2.0
 * @link     http://www.datasift.com
 * @link     http://facebook.com
 */
class WebDriverClient extends WebDriverBase
{
    protected function getMethods()
    {
        // a list of the JsonWireProtocol methods that this class supports
        return array(
          'status' => 'GET',
        );
    }

    /**
     * create a new session / launch a new browser to control
     *
     * @param  string $browser
     *                the name of the browser to use
     * @param  array  $additional_capabilities
     *                a list of the capabilities that are needed for this test
     *
     * @return WebDriverSession
     *         the new WebDriverSession to use to control the browser
     */
    public function newSession($browser = 'chrome', $additional_capabilities = array())
    {
        // merge the browser name into any additional requested capabilities
        $desired_capabilities = array_merge(
            $additional_capabilities,
            array('browserName' => $browser)
        );

        // tell webdriver to create the new session
        $results = $this->curl(
            'POST',
            '/session',
            array('desiredCapabilities' => $desired_capabilities),
            array(CURLOPT_FOLLOWLOCATION => true)
        );

        // did we get a sessionId back?
        //
        // this happens when SauceLabs doesn't like what we've asked;
        // genuine Selenium WebDriver returns a proper error!
        if(!isset($results['sessionId'])) {
            throw new E5xx_SessionNotCreatedWebDriverError('no error message provided by selenium webdriver, sorry :(');
        }

        // return the session back to the caller
        return new WebDriverSession($this->url . '/session/'. $results['sessionId']);
    }

    /**
     * get a list of active sessions
     *
     * @return array(WebDriverSession)
     *         a list of the sessions that webdriver currently knows about
     */
    public function getSessions()
    {
        // our return value
        $sessions = array();

        // get a raw list of the current sessions
        $result = $this->curl('GET', '/sessions');

        // convert the raw list into an array of WebDriverSession objects
        foreach ($result['value'] as $session) {
            $sessions[] = new WebDriverSession($this->url . '/session/' . $session['id']);
        }

{'fraction_non_alphanumeric': 0.10008505812305075, 'fraction_numerical': 0.005103487383045081, 'mean_word_length': 2.3611243449261554, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 10, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7549992', 'n_tokens_mistral': 1886, 'n_tokens_neox': 1817, 'n_words': 661}