示例#1
0
 private function _createDerivativeMethodFromXML(\SimpleXMLElement $li)
 {
     $text = $li->asXML();
     preg_match('/(?P<name>[a-zA-Z]+)\\s*\\((?P<args>[a-zA-Z0-9\\,\\s\\<\\>\\/\\"\\#\\=]+)\\)/', $text, $m) && array_key_exists('name', $m) && array_key_exists('args', $m) or die('Error at parse derivative method: ' . $text);
     // Name
     $method = Method::createNew();
     $method->name = $m['name'];
     // Arguments
     if ($args = trim($m['args'])) {
         foreach (explode(',', $args) as $arg) {
             $argument = Argument::createNew()->setMethod($method);
             $argument->name = trim(strip_tags($arg));
             $method->addArgument($argument);
         }
     }
     return $method;
 }
$argument->name = 'context';
$argument->type = Argument::DEFAULT_TYPE;
$argument->description = 'the message to be sent to the browser';
$mSetContext->addArgument($argument);
// return value
$mSetContext->returnValue = ReturnValue::createNew();
$mSetContext->returnValue->type = ReturnValue::TYPE_VOID;
// add to common method list (method and its derivative methods)
$methods[] = $mSetContext;
// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------
// ---- shutDownSeleniumServer
$mShutDownSeleniumServer = Method::createNew();
$mShutDownSeleniumServer->name = 'shutDownSeleniumServer';
$mShutDownSeleniumServer->type = Method::determineTypeByName($mShutDownSeleniumServer->name);
$mShutDownSeleniumServer->subtype = Method::determineSubtypeByName($mShutDownSeleniumServer->name);
$mShutDownSeleniumServer->description = <<<TEXT
    Kills the running Selenium Server and all browser sessions. After you run this command, you will no longer be able
    to send commands to the server; you can't remotely start the server once it has been stopped.
    Normally you should prefer to run the "stop" command, which terminates the current browser session,
    rather than shutting down the entire server.
TEXT;
// return value
$mShutDownSeleniumServer->returnValue = ReturnValue::createNew();
$mShutDownSeleniumServer->returnValue->type = ReturnValue::TYPE_VOID;
// add to common method list (method and its derivative methods)
$methods[] = $mShutDownSeleniumServer;
// .... other methods place here. Should be added:
// keyDownNative
// keyPressNative
// keyUpNative
 /**
  * Creates new method with the specified name (converts from current method).
  * Only {@link Method::SUBTYPE_BASE} + {@link Method::SUBTYPE_STORE} supported for current method.
  *
  * @param Method $oldMethod     Source method, from which created new method
  * @param string $newMethodName Name of new method
  *
  * @return Method               New converted method
  * @throws \Exception           If current method has unsupported subtype, or incorrect name for new method
  */
 function createNewMethodWithName(Method $oldMethod, $newMethodName)
 {
     $newMethod = $oldMethod->createClone();
     $newMethod->name = $newMethodName;
     $newMethod->type = Method::determineTypeByName($newMethod->name);
     $newMethod->subtype = Method::determineSubtypeByName($newMethod->name);
     $newMethod->description = $this->_addEndDotIfNotExist($newMethod->description);
     // add end of last sentence
     // see also links
     $newMethod->seeLinks = Helper::prependAssoc($newMethod->seeLinks, [$oldMethod->getNameFQSEN() => 'Base method, from which has been generated (automatically) current method']);
     if ($oldMethod->subtype === Method::SUBTYPE_BASE) {
         // ---- Source method has Action type
         switch ($newMethod->subtype) {
             case Method::SUBTYPE_BASE:
                 // Action --> Action
                 return $newMethod;
             case Method::SUBTYPE_AND_WAIT:
                 // Action --> Action
                 $newMethod->description .= '<h4>Notes:</h4>' . '<p>After execution of this action, Selenium wait for a new page to load ' . '(see ' . CodeGenerator::linkToMethod('waitForPageToLoad') . ')</p>';
                 return $newMethod;
             default:
                 self::throwException("Incorrect subtype for creating of new method: '{$oldMethod->subtype}'. " . "Source method (Action) should be converted only to Action.");
         }
     } elseif ($oldMethod->subtype === Method::SUBTYPE_STORE) {
         // ---- Source method has Accessor type
         switch ($newMethod->subtype) {
             case Method::SUBTYPE_STORE:
                 // Accessor --> Accessor
                 $newMethod->description .= '<h4>Stored value:</h4>' . '<p>' . $newMethod->returnValue->description . ' (see ' . CodeGenerator::linkToProperty('doc_Stored_Variables', '', 'Stored Variables') . ')</p>';
                 $newMethod->returnValue->description = '';
                 // store* methods has no return value todo to check this
                 return $newMethod;
             case Method::SUBTYPE_GET:
                 // Accessor --> Accessor
                 $newMethod->deleteArgumentByName('variableName');
                 return $newMethod;
             case Method::SUBTYPE_IS:
                 // Accessor --> Accessor
                 $newMethod->deleteArgumentByName('variableName');
                 return $newMethod;
             case Method::SUBTYPE_ASSERT:
                 // Accessor --> Assertion
             // Accessor --> Assertion
             case Method::SUBTYPE_ASSERT_NOT:
                 $derivativeMethod = $newMethod->getDerivativeMethodByName($newMethodName, true);
                 $newMethod->setArgumentsAndKeepOldDescription($derivativeMethod->arguments);
                 $relatedVerifyMethodName = $newMethod->makeNameForSubtype(Method::SUBTYPE_VERIFY);
                 $newMethod->description = 'Assertion: ' . $newMethod->description . '<h4>Value to verify:</h4> ' . '<p>' . $newMethod->returnValue->description . '</p>' . '<h4>Notes:</h4> ' . '<p>If assertion will fail the test, it will abort the current test case ' . '(in contrast to the ' . CodeGenerator::linkToMethod($relatedVerifyMethodName) . ').</p>';
                 $newMethod->returnValue->description = '';
                 // assert* methods has no return value todo to check this
                 return $newMethod;
             case Method::SUBTYPE_VERIFY:
                 // Accessor --> Assertion
             // Accessor --> Assertion
             case Method::SUBTYPE_VERIFY_NOT:
                 $derivativeMethod = $newMethod->getDerivativeMethodByName($newMethodName, true);
                 $newMethod->setArgumentsAndKeepOldDescription($derivativeMethod->arguments);
                 $relatedAssertMethodName = $newMethod->makeNameForSubtype(Method::SUBTYPE_ASSERT);
                 $newMethod->description = 'Assertion: ' . $newMethod->description . '<h4>Value to verify:</h4> ' . '<p>' . $newMethod->returnValue->description . '</p>' . '<h4>Notes:</h4> ' . '<p>If assertion will fail the test, it will continue to run the test case ' . '(in contrast to the ' . CodeGenerator::linkToMethod($relatedAssertMethodName) . ').</p>';
                 $newMethod->returnValue->description = '';
                 // verify* methods has no return value todo to check this
                 return $newMethod;
             case Method::SUBTYPE_WAIT_FOR:
                 // Accessor --> Assertion
             // Accessor --> Assertion
             case Method::SUBTYPE_WAIT_FOR_NOT:
                 $derivativeMethod = $newMethod->getDerivativeMethodByName($newMethodName, true);
                 $newMethod->setArgumentsAndKeepOldDescription($derivativeMethod->arguments);
                 $newMethod->description = 'Assertion: ' . $newMethod->description . '<h4>Expected value/condition:</h4> ' . '<p>' . $newMethod->returnValue->description . '</p>' . '<h4>Notes:</h4> ' . "<p>This command wait for some condition to become true (or returned value is equal specified value).</p>" . '<p>This command will succeed immediately if the condition is already true.</p>';
                 $newMethod->returnValue->description = '';
                 // waitFor* methods has no return value todo to check this
                 return $newMethod;
             default:
                 self::throwException("Incorrect subtype for creating of new method: '{$oldMethod->subtype}'. " . "Source method (Accessor) should be converted only to Accessor or Assertion.");
         }
     } else {
         self::throwException("Incorrect subtype of source method: '{$oldMethod->subtype}'. " . "Source method support only Method::SUBTYPE_BASE and Method::SUBTYPE_STORE subtypes.");
     }
     return $newMethod;
 }
// Load manual description of some methods
$manualMethodsDescription = (require_once 'source-doc/manual_methods_description.php');
// Parsing of official documentation
$parser = new Parser(file_get_contents(SELENIUM_DOC_REFERENCE));
// Search description for available selenium commands (methods of phpunit-selenium-driver)
$driver = new phpunitSeleniumDriver();
$generator = new CodeGenerator();
$seleniumCommands = $driver->getAvailableSeleniumCommands();
$methodsByBaseName = [];
$notFounded = [];
foreach ($seleniumCommands as $methodFullName => $returnType) {
    // Create model of available method
    $method = models\Method::createNew();
    $method->name = $methodFullName;
    $method->type = models\Method::determineTypeByName($methodFullName);
    $method->subtype = models\Method::determineSubtypeByName($methodFullName);
    $method->returnValue = models\ReturnValue::createNew();
    $method->returnValue->type = $returnType;
    // Search of description in manual/parsed docs
    $documentedMethod = null;
    if (array_key_exists($methodFullName, $manualMethodsDescription)) {
        $documentedMethod = $manualMethodsDescription[$methodFullName];
    } elseif ($foundMethod = $parser->getMethodByBaseName($method->getBaseName(true))) {
        $documentedMethod = $generator->createNewMethodWithName($foundMethod, $method->name);
        // convert to target method
        $documentedMethod->returnValue->type = $returnType;
        // selenium documentation has no info about php variable type
    }
    if ($documentedMethod) {
        $methodsByBaseName[$method->getBaseName()][] = $documentedMethod;
    } else {