コード例 #1
4
ファイル: test.php プロジェクト: Anenome/submitter-approver
/**
 * @param $web
 * @param $input_id
 * @param $value
 * @return mixed
 */
function write_in_input(RemoteWebDriver $web, $input_id, $value)
{
    $input = $web->findElement(WebDriverBy::id($input_id));
    $input->click();
    $web->getKeyboard()->sendKeys($value);
    return $input;
}
コード例 #2
1
 /**
  * @param string $prefix
  * @param RemoteWebElement $element
  *
  * @return string
  * @throws RuntimeException
  */
 protected function takeScreenshot($prefix, RemoteWebElement $element = null)
 {
     $screenshotPath = $this->getScreenshotPath($prefix);
     $this->webDriver->takeScreenshot($screenshotPath);
     if (!file_exists($screenshotPath)) {
         throw new RuntimeException('Could not save screenshot');
     }
     if ($element === null) {
         return $screenshotPath;
     }
     $elementWidth = $element->getSize()->getWidth();
     $elementHeight = $element->getSize()->getHeight();
     $elementSrcX = $element->getLocation()->getX();
     $elementSrcY = $element->getLocation()->getY();
     // Create image instances
     $src = imagecreatefrompng($screenshotPath);
     $dest = imagecreatetruecolor($elementWidth, $elementHeight);
     // Copy
     imagecopy($dest, $src, 0, 0, $elementSrcX, $elementSrcY, $elementWidth, $elementHeight);
     imagepng($dest, $screenshotPath);
     if (!file_exists($screenshotPath)) {
         throw new RuntimeException('Could not save screenshot');
     }
     return $screenshotPath;
 }
コード例 #3
1
 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();
 }
コード例 #4
0
 public function tearDown()
 {
     parent::tearDown();
     if ($this->webDriver !== NULL) {
         $this->webDriver->close();
     }
 }
コード例 #5
0
ファイル: Unit.php プロジェクト: tigron/skeleton-test
 /**
  * This method is called after the last case in the test has been run.
  * We can safely terminate the webdriver connection here.
  *
  * @access public
  */
 public static function tearDownAfterClass()
 {
     if (self::$my_webdriver !== null) {
         self::$my_webdriver->quit();
         self::$my_webdriver = null;
     }
 }
コード例 #6
0
 public function quit()
 {
     try {
         $this->driver->quit();
     } catch (UnknownServerException $e) {
     }
 }
コード例 #7
0
ファイル: GoogleTest.php プロジェクト: luckily/selenium-php
 public function testSearch()
 {
     $this->webDriver->get($this->url);
     $input = $this->webDriver->findElement(WebDriverBy::cssSelector('#lst-ib'));
     $input->sendKeys('yiiframework');
     $this->webDriver->getKeyboard()->pressKey(WebDriverKeys::ENTER);
     // waiting for google load ajax complete.
     sleep(2);
     $response = $this->webDriver->findElement(WebDriverBy::cssSelector('#ires div.srg div.g div.rc h3.r a'))->getText();
     sleep(3);
     $this->assertContains('Yii PHP Framework', $response);
 }
コード例 #8
0
ファイル: GitHubTest.php プロジェクト: luckily/selenium-php
 public function testSearch()
 {
     $this->webDriver->get($this->url);
     $form = $this->webDriver->findElement(WebDriverBy::cssSelector('form.js-site-search-form'));
     $input = $form->findElement(WebDriverBy::cssSelector('input[type=text].js-site-search-focus'));
     $input->sendKeys('yii 1.1');
     $form->submit();
     $link = $this->webDriver->findElement(WebDriverBy::cssSelector('ul.repo-list li.repo-list-item h3.repo-list-name a'));
     $link->click();
     $repositoryMeta = $this->webDriver->findElement(WebDriverBy::cssSelector('span.repository-meta-content'))->getText();
     sleep(3);
     $this->assertContains('Yii PHP Framework 1.1', $repositoryMeta);
 }
コード例 #9
0
 /**
  * @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;
 }
コード例 #10
0
 public function setUp()
 {
     parent::setUp();
     $host = 'http://localhost:4444/wd/hub';
     $this->driver = RemoteWebDriver::create($host, DesiredCapabilities::firefox());
     $this->driver->manage()->window()->maximize();
 }
コード例 #11
0
 public function getDriver()
 {
     if (self::$driver == null) {
         self::$driver = RemoteWebDriver::create('http://127.0.0.1:4444/wd/hub', $this->BROWSER);
     }
     return self::$driver;
 }
コード例 #12
0
ファイル: phpbb_ui_test_case.php プロジェクト: bantu/phpbb
	/**
	 * Take screenshot. Can be used for debug purposes.
	 *
	 * @throws Exception When screenshot can't be created
	 */
	public function take_screenshot()
	{
		// Change the Path to your own settings
		$screenshot = time() . ".png";

		self::$webDriver->takeScreenshot($screenshot);
	}
コード例 #13
0
ファイル: Debug.php プロジェクト: blackakula/wdebug
 /**
  * Revert highlighted elements to original style values
  */
 private function revertHighlighting()
 {
     if (isset($this->highlightingRevertData)) {
         $this->driver->executeScript($this->highlightingRevertData['script'], $this->highlightingRevertData['args']);
         $this->highlightingRevertData = null;
     }
 }
コード例 #14
0
ファイル: WebDriverTest.php プロジェクト: surjit/Codeception
 public function testSaveSessionSnapshotsExcludeInvalidCookieDomains()
 {
     $this->notForPhantomJS();
     $fakeWdOptions = Stub::make('\\Facebook\\WebDriver\\WebDriverOptions', ['getCookies' => Stub::atLeastOnce(function () {
         return [['name' => 'PHPSESSID', 'value' => '123456', 'path' => '/'], ['name' => '3rdParty', 'value' => '_value_', 'path' => '/', 'domain' => '.3rd-party.net']];
     })]);
     $fakeWd = Stub::make(self::WEBDRIVER_CLASS, ['manage' => Stub::atLeastOnce(function () use($fakeWdOptions) {
         return $fakeWdOptions;
     })]);
     // Mock the WebDriverOptions::getCookies() method on the first call to introduce a 3rd-party cookie
     // which has to be ignored when saving a snapshot.
     $originalWebDriver = $this->module->webDriver;
     $this->module->webDriver = $fakeWd;
     $this->module->seeCookie('PHPSESSID');
     $this->module->seeCookie('3rdParty');
     $this->module->saveSessionSnapshot('login');
     // Restore the original WebDriver
     $this->module->webDriver = $originalWebDriver;
     $this->webDriver->manage()->deleteAllCookies();
     $this->module->dontSeeCookie('PHPSESSID');
     $this->module->dontSeeCookie('3rdParty');
     $this->module->loadSessionSnapshot('login');
     $this->module->seeCookie('PHPSESSID');
     $this->module->dontSeeCookie('3rdParty');
 }
コード例 #15
0
 /**
  * Constructor. Подготовка драйвера Selenium
  */
 public function __construct($seleniumDriverHost = "http://localhost:8910", $driverBrowserName = 'phantomjs', $driverBrowserUserAgent = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:25.0) Gecko/20100101 Firefox/25.0')
 {
     $this->seleniumDriverHost = $seleniumDriverHost;
     $capabilities = array(WebDriverCapabilityType::BROWSER_NAME => $driverBrowserName, 'phantomjs.page.settings.userAgent' => $driverBrowserUserAgent);
     $this->driver = RemoteWebDriver::create($seleniumDriverHost, $capabilities, 5000);
     $window = new WebDriverDimension(1280, 1024);
     $this->driver->manage()->window()->setSize($window);
 }
コード例 #16
0
 /** 
  * 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);
 }
コード例 #17
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();
 }
コード例 #18
0
ファイル: TestCase.php プロジェクト: phanan/koel
 /**
  * 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));
 }
コード例 #19
0
ファイル: Unit.php プロジェクト: tigron/skeleton-test
 /**
  * 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;
 }
コード例 #20
0
ファイル: WebDriverTest.php プロジェクト: corcre/elabftw
 public function testSessionSnapshots()
 {
     $this->module->amOnPage('/');
     $this->module->setCookie('PHPSESSID', '123456', ['path' => '/']);
     $this->module->saveSessionSnapshot('login');
     $this->module->seeCookie('PHPSESSID');
     $this->webDriver->manage()->deleteAllCookies();
     $this->module->dontSeeCookie('PHPSESSID');
     $this->module->loadSessionSnapshot('login');
     $this->module->seeCookie('PHPSESSID');
 }
コード例 #21
0
 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);
 }
コード例 #22
0
 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);
 }
コード例 #23
0
ファイル: Scraphp.php プロジェクト: hilbertus/scraphp
 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);
     }
 }
コード例 #24
0
ファイル: UITestCase.php プロジェクト: ekowabaka/cfx
 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);
 }
コード例 #25
0
 public static function create(WebDriverConfig $config)
 {
     if (!$config->isValid()) {
         throw new \Exception('Configuration is invalid. Check that all your properties are defined.');
     }
     $defaultBrowserCapabilities = [WebDriverCapabilityType::BROWSER_NAME => $config->getBrowserName()];
     $browserCapabilities = $config->getBrowserCapabilities();
     if (empty($browserCapabilities)) {
         if (!$config->getBrowserProxyHost() && !$config->getBrowserProxyPort()) {
             $config->setBrowserCapability(WebDriverCapabilityType::PROXY, ['proxyType' => 'manual', 'httpProxy' => $config->getBrowserProxyHost() . ':' . $config->getBrowserProxyPort(), 'sslProxy' => $config->getBrowserProxyHost() . ':' . $config->getBrowserProxyPort()]);
         }
     }
     $browserCapabilities = array_merge($defaultBrowserCapabilities, $config->getBrowserCapabilities());
     return RemoteWebDriver::create(sprintf('http://%s:%d/wd/hub', $config->getSeleniumServerHost(), $config->getSeleniumServerPort()), $browserCapabilities);
 }
コード例 #26
0
ファイル: Puffin.php プロジェクト: nubium/puffin
 /**
  * Generate the screenshot of the dom element
  *
  * @param string $identifier identifies your test object
  * @param array $coords Coordinates where the DOM element is located
  * @return string Path of the current screenshot image
  * @throws \RuntimeException
  */
 private function createScreenshot($identifier, array $coords)
 {
     $screenShotDir = Configuration::logDir() . 'debug/';
     if (!is_dir($screenShotDir)) {
         mkdir($screenShotDir, 0777, true);
     }
     $screenshotPath = $screenShotDir . 'fullscreenshot.tmp.png';
     $elementPath = $this->getScreenshotPath($identifier);
     $this->remoteWebDriver->takeScreenshot($screenshotPath);
     $screenShotImage = new Imagick();
     $screenShotImage->readImage($screenshotPath);
     $screenShotImage->cropImage($coords['width'], $coords['height'], $coords['x'], $coords['y']);
     $screenShotImage->writeImage($elementPath);
     unlink($screenshotPath);
     return $elementPath;
 }
 /** @BeforeScenario */
 public function before($event)
 {
     $username = getenv("SAUCE_USERNAME");
     $access_key = getenv("SAUCE_ACCESS_KEY");
     $platform = getenv("platform");
     $browser_name = getenv("browserName");
     $version = getenv("version");
     $scenario_name = $event->getScenario()->gettitle();
     $feature_name = $event->getScenario()->getFeature()->gettitle();
     $host = sprintf('http://%s:%s@ondemand.saucelabs.com/wd/hub', $username, $access_key);
     $desired_capabilities = new stdClass();
     $desired_capabilities->platform = $platform;
     $desired_capabilities->browserName = $browser_name;
     $desired_capabilities->version = $version;
     $desired_capabilities->name = $feature_name . " - " . $scenario_name;
     $this->driver = RemoteWebDriver::create($host, $desired_capabilities);
 }
コード例 #28
0
ファイル: RunTestsCommand.php プロジェクト: carnage/selenium
 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>");
     }
 }
コード例 #29
0
 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;
 }
コード例 #30
0
 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());
 }