public function testWithoutMagium()
 {
     // This test is based off of my own test environment and so everything up until the Twitter authentication will
     // not work.  So ignore the first part.
     $webDriver = RemoteWebDriver::create('http://*****:*****@data-strategy="twitter"]'));
     $webDriver->wait()->until(ExpectedCondition::visibilityOf($element));
     $element->click();
     // Start from here
     $configurationProvider = new StandardConfigurationProvider(new ConfigurationReader(), new ClassConfigurationReader(), new EnvironmentConfigurationReader());
     $collector = new DefaultPropertyCollector();
     $action = new AuthenticateTwitter($webDriver, new \Magium\Twitter\Themes\Twitter($configurationProvider, $collector), new Twitter($configurationProvider, $collector));
     $action->execute();
     $webDriver->quit();
 }
Example #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;
}
 public function setUp()
 {
     parent::setUp();
     $host = 'http://localhost:4444/wd/hub';
     $this->driver = RemoteWebDriver::create($host, DesiredCapabilities::firefox());
     $this->driver->manage()->window()->maximize();
 }
 /**
  * @return RemoteWebDriver
  */
 protected function getRemoteWebDriver()
 {
     if (null === $this->remoteWebDriver) {
         $this->remoteWebDriver = RemoteWebDriver::create($this->getKernel()->getContainer()->getParameter('cosma_testing.selenium.remote_server_url'), DesiredCapabilities::chrome());
     }
     return $this->remoteWebDriver;
 }
Example #5
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     if (version_compare(PHP_VERSION, '5.3.19', '<')) {
         self::markTestSkipped('UI test case requires at least PHP 5.3.19.');
     } else {
         if (!class_exists('\\Facebook\\WebDriver\\Remote\\RemoteWebDriver')) {
             self::markTestSkipped('Could not find RemoteWebDriver class. ' . 'Run "php ../composer.phar install" from the tests folder.');
         }
     }
     self::$config = phpbb_test_case_helpers::get_test_config();
     self::$root_url = self::$config['phpbb_functional_url'];
     // Important: this is used both for installation and by
     // test cases for querying the tables.
     // Therefore table prefix must be set before a board is
     // installed, and also before each test case is run.
     self::$config['table_prefix'] = 'phpbb_';
     if (!isset(self::$config['phpbb_functional_url'])) {
         self::markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.');
     }
     if (!self::$webDriver) {
         try {
             $capabilities = DesiredCapabilities::firefox();
             self::$webDriver = RemoteWebDriver::create(self::$host . ':' . self::$port, $capabilities);
         } catch (WebDriverCurlException $e) {
             self::markTestSkipped('PhantomJS webserver is not running.');
         }
     }
     if (!self::$already_installed) {
         self::install_board();
         self::$already_installed = true;
     }
 }
 /** 
  * Set Up.
  *
  */
 public function setUp()
 {
     parent::setUp();
     $host = 'http://localhost:4444/wd/hub';
     // this is the default
     $capabilities = DesiredCapabilities::firefox();
     $this->driver = RemoteWebDriver::create($host, $capabilities, 35000);
 }
 public static function createChromeMobile()
 {
     // For Chrome.
     $capabilities = DesiredCapabilities::chrome();
     $capabilities->setCapability(ChromeOptions::CAPABILITY, ['mobileEmulation' => ['deviceName' => 'Google Nexus 5']]);
     $config = WebDriverConfigFactory::createFromEnv();
     $config->setBrowserCapabilities($capabilities->toArray());
     return self::create($config);
 }
Example #8
0
 /**
  * TestCase constructor.
  */
 public function __construct()
 {
     parent::__construct();
     $this->createApp();
     $this->resetData();
     $this->driver = RemoteWebDriver::create('http://localhost:4444/wd/hub', DesiredCapabilities::chrome());
     $this->driver->manage()->window()->setSize(new WebDriverDimension(1440, 900));
     $this->driver->manage()->window()->setPosition(new WebDriverPoint(0, 0));
 }
Example #9
0
 /**
  * Initialize a new webdriver connection if needed
  *
  * @access public
  */
 public static function get_webdriver()
 {
     if (self::$my_webdriver === null) {
         $capabilities = DesiredCapabilities::chrome();
         $driver = RemoteWebDriver::create(Config::$selenium_hub, $capabilities);
         self::$my_webdriver = $driver;
         self::$my_webdriver->manage()->timeouts()->implicitlyWait(5);
     }
     return self::$my_webdriver;
 }
 protected function setUp()
 {
     if (!empty(getenv('TRAVIS'))) {
         // running on TRAVIS CI
         $this->WEBSITE = 'http://127.0.0.1:8080';
         $this->BROWSER = DesiredCapabilities::firefox();
     } else {
         $this->WEBSITE = 'http://localhost/mylibrary-yii2/app/public/';
         $this->BROWSER = DesiredCapabilities::chrome();
     }
 }
 public function setUp()
 {
     $urlDoSistema = 'http://localhost:8000/';
     $hostDoSelenium = 'http://localhost:4444/wd/hub';
     //Define o WebDriver
     $driver = RemoteWebDriver::create($hostDoSelenium, DesiredCapabilities::chrome());
     //$this->setHost('localhost');    // Host do servidor Selenium
     $this->setPort(4444);
     // Porta do Servidor do Selenium
     $this->setBrowser('chrome');
     $this->setBrowserUrl($urlDoSistema);
 }
 public function setUp()
 {
     $targetUrl = 'http://phpunit-selenium2-samples.herokuapp.com/01/';
     $host = 'http://localhost:4444/wd/hub';
     $driver = RemoteWebDriver::create($host, DesiredCapabilities::firefox());
     //        $this->setHost('localhost');  // Selenium Server Host
     $this->setPort(4444);
     // Selenium Server Port
     $this->setBrowser('firefox');
     // firefox, chrome, iexplorer, safari
     $this->setBrowserUrl($targetUrl);
 }
Example #13
0
 public static function start(DesiredCapabilities $desired_capabilities = null, ChromeDriverService $service = null)
 {
     if ($desired_capabilities === null) {
         $desired_capabilities = DesiredCapabilities::chrome();
     }
     if ($service === null) {
         $service = ChromeDriverService::createDefaultService();
     }
     $executor = new DriverCommandExecutor($service);
     $driver = new static();
     $driver->setCommandExecutor($executor)->startSession($desired_capabilities);
     return $driver;
 }
Example #14
0
 public function setUp()
 {
     parent::setUp();
     $this->testId = uniqid();
     switch (getenv('CFX_WEB_BROWSER')) {
         case 'chrome':
             $browser = DesiredCapabilities::chrome();
             break;
         case 'firefox':
             $browser = DesiredCapabilities::firefox();
             break;
     }
     $this->driver = RemoteWebDriver::create(getenv('CFX_WEB_DRIVER'), $browser);
 }
Example #15
0
 /**
  * Set user agent
  */
 public function testSetUserAgent()
 {
     $useragent = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16';
     // setup
     $capabilities = DesiredCapabilities::firefox();
     /** @var FirefoxProfile $profile */
     $profile = $capabilities->getCapability(FirefoxDriver::PROFILE);
     $profile->setPreference('general.useragent.override', $useragent);
     $this->webDriver = RemoteWebDriver::create('http://' . self::HOST . '/wd/hub', $capabilities);
     // test
     $this->webDriver->get('http://demo.mobiledetect.net/');
     $elements = $this->webDriver->findElements(WebDriverBy::tagName('h1'));
     static::assertEquals(3, count($elements));
     $elementContainingQuestion = $elements[1];
     static::assertEquals('Is your device really a phone?', $elementContainingQuestion->getText());
     $this->webDriver->quit();
 }
Example #16
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var TestSuite $testSuite */
     $testSuite = (require $input->getOption('test-suite'));
     $host = $input->getOption('selenium-host');
     $facebookDriver = FacebookRemoteWebDriver::create($host, DesiredCapabilities::chrome());
     $remoteDriver = new RemoteWebDriver($facebookDriver, Url::fromString($input->getOption('base-url')));
     try {
         $testSuite->execute($remoteDriver);
     } catch (\Exception $e) {
         do {
             $message = $e->getMessage();
         } while ($e = $e->getPrevious());
     }
     $report = $this->formatReport($testSuite);
     $output->writeln((string) $report);
     if (isset($message)) {
         $output->writeln("<error>" . $message . "<error>");
     }
 }
Example #17
0
 public function run()
 {
     if ($this->remoteWebDriver === null) {
         $this->remoteWebDriver = RemoteWebDriver::create('http://127.0.0.1:8910', DesiredCapabilities::phantomjs());
     }
     $script = '';
     $script .= file_get_contents(__DIR__ . '/js/jquery-2.2.2.min.js');
     $script .= "\n\n";
     $script .= file_get_contents(__DIR__ . '/js/frontendscraper.js');
     $script .= "\n\n";
     while ($job = $this->jobBuffer->getJob()) {
         $status = $this->createInitStatus($job);
         $this->remoteWebDriver->get($job->url);
         $inject = $script;
         $inject .= file_get_contents($this->jobScriptDir . '/' . $job->script);
         $inject .= "\n\n return phantomScraper.getResult();";
         $res = $this->remoteWebDriver->executeScript($inject);
         $this->addJobs($res['jobs']);
         $this->addData($res['data']);
         $this->updateStatus($status);
     }
 }
 public function __construct($config = [])
 {
     parent::__construct($config);
     $getAllSessions = RemoteWebDriver::getAllSessions($this->host);
     if ($this->sessionId && ArrayHelper::inMultiArray($this->sessionId, $getAllSessions, 'id')) {
         $this->driver = RemoteWebDriver::createBySessionID($this->sessionId, $this->host);
     } else {
         $desired_capabilities = DesiredCapabilities::firefox();
         $fp = new FirefoxProfile();
         $desired_capabilities->setCapability(WebDriverCapabilityType::NATIVE_EVENTS, true);
         if (isset($this->proxy['ip'])) {
             $this->proxy['port'] = ArrayHelper::getValue($this->proxy, 'port');
             $fp->setPreference('network.proxy.ssl_port', $this->proxy['port']);
             $fp->setPreference('network.proxy.ssl', $this->proxy['ip']);
             $fp->setPreference('network.proxy.http_port', $this->proxy['port']);
             $fp->setPreference('network.proxy.http', $this->proxy['ip']);
             $fp->setPreference('network.proxy.type', 1);
         }
         $desired_capabilities->setCapability(FirefoxDriver::PROFILE, $fp);
         $this->driver = RemoteWebDriver::create($this->host, $desired_capabilities, 600000, 600000);
         $this->sessionId = $this->driver->getSessionID();
     }
 }
 public function testUsingSelenium()
 {
     require_once '../vendor/autoload.php';
     // start Firefox with 5 second timeout
     $host = 'http://localhost';
     // this is the default
     $capabilities = DesiredCapabilities::firefox();
     $driver = RemoteWebDriver::create($host, $capabilities, 5000);
     // navigate to 'http://docs.seleniumhq.org/'
     $driver->get('http://docs.seleniumhq.org/');
     // adding cookie
     $driver->manage()->deleteAllCookies();
     $driver->manage()->addCookie(array('name' => 'cookie_name', 'value' => 'cookie_value'));
     $cookies = $driver->manage()->getCookies();
     print_r($cookies);
     // click the link 'About'
     $link = $driver->findElement(WebDriverBy::id('menu_about'));
     $link->click();
     //        $this->webDriver->get($this->baseUrl);
     //
     //        $body = $this->webDriver->findElement(WebDriverBy::tagName('body'));
     //
     //        $this->assertContains(trans('public.words.welcome'), $body->getText());
 }
 public function getErrors(UriInterface $uri)
 {
     $host = $this->host . ':' . $this->port . '/wd/hub';
     $options = new ChromeOptions();
     $options->addExtensions(array(__DIR__ . '/extension/console2var.crx'));
     $caps = DesiredCapabilities::chrome();
     $caps->setCapability(ChromeOptions::CAPABILITY, $options);
     $driver = RemoteWebDriver::create($host, $caps);
     $filteredErrors = [];
     try {
         $driver->get((string) $uri);
         $errors = $driver->executeScript("return localStorage.getItem(\"js_errors\")", array());
         $errorList = explode('###', $errors);
         foreach ($errorList as $errorElement) {
             if ($errorElement != "") {
                 $filteredErrors[] = trim($errorElement);
             }
         }
     } catch (\Exception $e) {
         $filteredErrors[] = "Selenium/Webdriver crashed. " . $e->getMessage();
     }
     $driver->quit();
     return $filteredErrors;
 }
Example #21
0
 public function setUp()
 {
     $capabilities = DesiredCapabilities::firefox();
     $this->webDriver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $capabilities);
     //        $this->webDriver->manage()->timeouts()->implicitlyWait( 60 ) ;
 }
Example #22
0
/**
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * For the full copyright and license information, please view the LICENSE
 *
 * @category    blackakula
 * @package     wdebug
 * @copyright   Copyright (c) Sergii Kyrychenko <*****@*****.**>
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
# Server run example:
# java -Dwebdriver.chrome.driver="W:\chromedriver.exe" -jar selenium-server-standalone-2.32.0.jar
include 'vendor/autoload.php';
$host = 'http://localhost:4444/wd/hub';
$driver = FBRemote\RemoteWebDriver::create($host, FBRemote\DesiredCapabilities::chrome());
$driver->get('http://example.com/');
$debugger = new Wdebug\Debug($driver);
$debugger->execute(function ($type, $data) {
    switch ($type) {
        case 'deleteLocator':
            echo 'Deleted locator "' . $data['key'] . "\"\n";
            break;
        case 'setLocator':
            if (empty($data['oldKey'])) {
                echo 'Added locator "' . $data['key'] . "\"\n";
            } else {
                echo 'Changed locator "' . $data['oldKey'] . '" -> "' . $data['key'] . "\"\n";
            }
            echo '  - type:  ' . $data['locatorType'] . "\n";
            echo '  - value: ' . $data['locatorValue'] . "\n";
Example #23
0
 protected function setUp()
 {
     $host = 'http://localhost:4444/wd/hub';
     $browser = DesiredCapabilities::chrome();
     $this->webDriver = RemoteWebDriver::create($host, $browser);
 }
 public function testShouldSetupFirefoxProfileAndDisableReaderViewForFirefoxBrowser()
 {
     $capabilities = DesiredCapabilities::firefox();
     /** @var FirefoxProfile $firefoxProfile */
     $firefoxProfile = $capabilities->getCapability(FirefoxDriver::PROFILE);
     $this->assertInstanceOf('Facebook\\WebDriver\\Firefox\\FirefoxProfile', $firefoxProfile);
     $this->assertSame('false', $firefoxProfile->getPreference(FirefoxPreferences::READER_PARSE_ON_LOAD_ENABLED));
 }
 /**
  * @return DesiredCapabilities
  */
 public static function htmlUnitWithJS()
 {
     $caps = new DesiredCapabilities(array(WebDriverCapabilityType::BROWSER_NAME => WebDriverBrowserType::HTMLUNIT, WebDriverCapabilityType::PLATFORM => WebDriverPlatform::ANY));
     return $caps->setJavascriptEnabled(true);
 }
 /**
  * Setup test case
  */
 public function setUp()
 {
     // DesiredCapabilities::chrome();
     $this->webDriver = RemoteWebDriver::create($this->webDriverUrl, DesiredCapabilities::firefox());
 }
<?php

use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
require '../../vendor/autoload.php';
$host = 'http://localhost:4444/wd/hub';
//run all tests in firefox
$capabilities = DesiredCapabilities::firefox();
$driver = RemoteWebDriver::create($host, $capabilities, 5000);
$f = 0;
$s = 0;
require 'add_car.php';
require 'delete_car.php';
require 'view_car_details.php';
$driver->close();
print "[firefox] " . ($f + $s) . " tests run. {$s} passed. {$f} failed." . PHP_EOL;
//run all tests in chrome
$capabilities = DesiredCapabilities::chrome();
$driver = RemoteWebDriver::create($host, $capabilities, 5000);
$f = 0;
$s = 0;
require 'add_car.php';
require 'delete_car.php';
require 'view_car_details.php';
$driver->close();
print "[chrome] " . ($f + $s) . " tests run. {$s} passed. {$f} failed." . PHP_EOL;
 /**
  * This method is invoked before a test method
  */
 public function setUp()
 {
     $this->webDriver = RemoteWebDriver::create($this->seleniumServerUrl, DesiredCapabilities::firefox());
 }
Example #29
0
<?php

// An example of using php-webdriver.
namespace Facebook\WebDriver;

use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
require_once 'vendor/autoload.php';
// start Firefox with 5 second timeout
$host = 'http://localhost:4444/wd/hub';
// this is the default
$capabilities = DesiredCapabilities::firefox();
$driver = RemoteWebDriver::create($host, $capabilities, 5000);
// navigate to 'http://docs.seleniumhq.org/'
$driver->get('http://docs.seleniumhq.org/');
// adding cookie
$driver->manage()->deleteAllCookies();
$driver->manage()->addCookie(array('name' => 'cookie_name', 'value' => 'cookie_value'));
$cookies = $driver->manage()->getCookies();
print_r($cookies);
// click the link 'About'
$link = $driver->findElement(WebDriverBy::id('menu_about'));
$link->click();
// print the title of the current page
echo "The title is '" . $driver->getTitle() . "'\n";
// print the URI of the current page
echo "The current URI is '" . $driver->getCurrentURL() . "'\n";
// Search 'php' in the search box
$input = $driver->findElement(WebDriverBy::id('q'));
$input->sendKeys('php')->submit();
// wait at most 10 seconds until at least one result is shown
Example #30
0
 /**
  * @return DesiredCapabilities The DesiredCapabilities for Chrome with this options.
  */
 public function toCapabilities()
 {
     $capabilities = DesiredCapabilities::chrome();
     $capabilities->setCapability(self::CAPABILITY, $this);
     return $capabilities;
 }