Exemplo n.º 1
0
 /**
  * @When /I click the element (.+)$/
  */
 function i_click($thing)
 {
     $this->init_webdriver();
     $element = $this->webdriver->findElementBy(\LocatorStrategy::id, $thing);
     if (empty($element)) {
         $this->assert_true(false, sprintf('{step}Could not find the element with the id "%s"', $thing));
     } else {
         $element->click();
     }
 }
 /**
  *
  * @param type $strategy
  * @param type $name
  * @param boolean $failIfNotExists whether should fail test if element not exists
  * @return WebElement
  */
 public function getElement($strategy, $name, $failIfNotExists = true)
 {
     $i = 0;
     do {
         try {
             $element = $this->webdriver->findElementBy($strategy, $name);
         } catch (NoSuchElementException $e) {
             print_r("\nWaiting for \"" . $name . "\" element to appear...\n");
             sleep(self::STEP_WAITING_TIME);
             $i += self::STEP_WAITING_TIME;
         }
     } while (!isset($element) && $i <= self::MAX_WAITING_TIME);
     if (!isset($element) && $failIfNotExists) {
         $this->fail("Element has not appeared after " . self::MAX_WAITING_TIME . " seconds.");
     }
     return $element;
 }
Exemplo n.º 3
0
<?php

/*
Copyright 2011 3e software house & interactive agency

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.
*/
// XAMPP NOTE: First please download Selenium RC (*.jar) from here : http://seleniumhq.org/download/
// XAMPP NOTE: Start the Selenium RC Server via cmd with: java -jar selenium-server-standalone-2.25.0.jar
// XAMPP NOTE: Then start this script with the cmd from here: .\php.exe  -f webdriver-test-example.php
// XAMPP NOTE: This example uses php-webdriver-bindings-0.9.0 (see the folder xampp\pear\phpwebdriver)
require_once "phpwebdriver/WebDriver.php";
require_once "phpwebdriver/LocatorStrategy.php";
$webdriver = new WebDriver("localhost", "4444");
$webdriver->connect("firefox");
$webdriver->get("http://google.com");
$element = $webdriver->findElementBy(LocatorStrategy::name, "q");
$element->sendKeys(array("selenium google code"));
$element->submit();
$webdriver->close();