Exemplo n.º 1
1
 protected function getDefaultConfiguration()
 {
     $config = parent::getDefaultConfiguration();
     $capabilitities = $config['definition']['class']['Magium\\WebDriver\\WebDriverFactory']['create']['desired_capabilities']['default'];
     if ($capabilitities instanceof DesiredCapabilities) {
         /*
          * Following is browser-specific functionality.  Non-browser-generic commands can be set here.  This example
          * changes the language for the browser to Spanish.
          *
          * The code for the HTML page is
          * <html><body><?php echo $_SERVER['HTTP_ACCEPT_LANGUAGE']; ?></body></html>
          */
         $options = new ChromeOptions();
         $options->addArguments(['--lang=es']);
         $capabilitities->setCapability(ChromeOptions::CAPABILITY, $options);
     }
     return $config;
 }
Exemplo n.º 2
1
function getWebDriverInstance()
{
    // Provide a re-usable webdriver for selenium tests.
    global $_INI;
    static $webDriver;
    if (!isset($webDriver)) {
        $driverType = getenv('LOVD_SELENIUM_DRIVER');
        $host = 'http://localhost:4444/wd/hub';
        $capabilities = null;
        if ($driverType == 'chrome') {
            // This is the documented way of starting the chromedriver, but it fails. (at least
            // on my machine with version 2.23)
            // putenv('webdriver.chrome.driver=/usr/share/chromedriver');
            // $webDriver = ChromeDriver::start();
            // Start the chrome driver through the selenium server.
            fwrite(STDERR, 'Connecting to Chrome driver via Selenium at ' . $host . PHP_EOL);
            $options = new ChromeOptions();
            $options->addArguments(array('--no-sandbox'));
            $capabilities = DesiredCapabilities::chrome();
            $capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
        } else {
            // Create Firefox webdriver
            fwrite(STDERR, 'Connecting to Firefox driver via Selenium at ' . $host . PHP_EOL);
            $capabilities = array(WebDriverCapabilityType::BROWSER_NAME => 'firefox');
        }
        $webDriver = LOVDWebDriver::create($host, $capabilities, WEBDRIVER_MAX_WAIT_DEFAULT * 1000, WEBDRIVER_MAX_WAIT_DEFAULT * 1000);
        // Set time for trying to access DOM elements
        $webDriver->manage()->timeouts()->implicitlyWait(WEBDRIVER_IMPLICIT_WAIT);
        if (isset($_INI['test']['xdebug_enabled']) && $_INI['test']['xdebug_enabled'] == 'true') {
            // Load page of target host. This is necessary to set a cookie.
            $webDriver->get(ROOT_URL . '/src/');
            // Enable remote debugging by setting XDebug session cookie.
            $webDriver->manage()->addCookie(array('name' => 'XDEBUG_SESSION', 'value' => 'selenium'));
        }
    }
    // Wrap the webdriver instance in a custom processor.
    return $webDriver;
}