Exemplo n.º 1
0
 /**
  * getAccessToken
  *
  * @param array $options Options to use when getting token
  *
  * @return string Access token
  */
 public function getAccessToken($options = array())
 {
     // Grab the details of our user
     $user = $this->args[0];
     // Start getting our token
     $disableCache = isset($options['disable_cache']) && $options['disable_cache'];
     // Get our runtime config
     $config = $this->st->getRuntimeConfig();
     // Check the one in the runtime config if we've not disabled the cache
     if (isset($config->facebookAccessToken, $config->facebookAccessToken->expires) && $config->facebookAccessToken->expires > time() && !$disableCache) {
         return $config->facebookAccessToken->access_token;
     }
     // Login to Facebook
     usingBrowser()->gotoPage($this->login_url);
     usingBrowser()->type($user['email'])->intoFieldWithId('email');
     usingBrowser()->type($user['password'])->intoFieldWithId('pass');
     usingBrowser()->click()->fieldWithName('login');
     // Get our access token
     $tokenCreationTime = time();
     usingBrowser()->gotoPage($this->developer_url);
     $access_token = fromBrowser()->getValue()->fromFieldWithId('access_token');
     // Write it to the config
     $config->facebookAccessToken = array("access_token" => $access_token, "expires" => $tokenCreationTime + 5400);
     $this->st->saveRuntimeConfig();
     return $access_token;
 }
Exemplo n.º 2
0
 protected function initActions()
 {
     // shorthand
     $formId = $this->args[0];
     // find the form
     $formElement = fromBrowser()->get()->elementById($formId);
     // is it really a form?
     if (strtolower($formElement->name()) !== 'form') {
         throw new E5xx_ActionFailed('form');
     }
     // yes, it really is a form
     $this->formId = $formId;
     $this->setTopElement($formElement);
 }
Exemplo n.º 3
0
 protected function initActions()
 {
     // call our parent initActions() first
     parent::initActions();
     // shorthand
     $formId = $this->args[0];
     // find the form
     $formElement = fromBrowser()->get()->elementById($formId);
     // is it really a form?
     if (strtolower($formElement->name()) !== 'form') {
         throw new E5xx_ActionFailed(__METHOD__, "expected form element, got element '" . $formElement->name() . "'");
     }
     // yes, it really is a form
     $this->formId = $formId;
     $this->setTopElement($formElement);
 }
Exemplo n.º 4
0
 public function getTableContents($xpath)
 {
     // what are we doing?
     $log = usingLog()->startAction("get HTML table using xpath");
     // can we find the table?
     try {
         $tableElement = fromBrowser()->get()->elementByXpath($xpath);
     } catch (Exception $e) {
         // no such table
         $log->endAction("no matching table");
         throw new E5xx_ActionFailed(__METHOD__);
     }
     // at this point, it looks like we'll have something to return
     $return = [];
     // extract the headings
     $headings = [];
     $thElements = $tableElement->getElements('xpath', 'descendant::thead/tr/th');
     foreach ($thElements as $thElement) {
         $headings[] = $thElement->text();
     }
     // extract the contents
     $row = 0;
     $column = 0;
     $trElements = $tableElement->getElements('xpath', 'descendant::tbody/tr');
     foreach ($trElements as $trElement) {
         $column = 0;
         $tdElements = $trElement->getElements('xpath', "descendant::td");
         foreach ($tdElements as $tdElement) {
             if (isset($headings[$column])) {
                 $return[$row][$headings[$column]] = $tdElement->text();
             } else {
                 $return[$row][] = $tdElement->text();
             }
             $column++;
         }
         $row++;
     }
     // all done
     $log->endAction("found table with {$column} columns and {$row} rows");
     return $return;
 }
// POSSIBLE ACTION(S)
//
// ------------------------------------------------------------------------
$story->addAction(function () {
    // get the checkpoint, to store data in
    $checkpoint = getCheckpoint();
    // load our test page
    usingBrowser()->gotoPage("file://" . __DIR__ . '/../../testpages/WorkingWithWindows.html');
    // get the h1
    $checkpoint->mainHeader = fromBrowser()->getText()->fromHeadingWithId('storyplayer_working_with_windows');
    // open the second window
    usingBrowser()->click()->linkWithText('open a second window');
    // switch to the second window
    usingBrowser()->switchToWindow("Storyplayer: Second Window");
    // get the h1
    $checkpoint->secondHeader = fromBrowser()->getText()->fromHeadingWithId('storyplayer_second_window');
    // close the second window
    // this leaves the browser in a bit of a state
    usingBrowser()->closeCurrentWindow();
    // switch back to the first window
    usingBrowser()->switchToWindow("Storyplayer: Working With Windows");
});
// ========================================================================
//
// POST-TEST INSPECTION
//
// ------------------------------------------------------------------------
$story->addPostTestInspection(function () {
    // get the checkpoint
    $checkpoint = getCheckpoint();
    // do we have the content we expected?
//
// PRE-TEST INSPECTION
//
// ------------------------------------------------------------------------
// ========================================================================
//
// POSSIBLE ACTION(S)
//
// ------------------------------------------------------------------------
$story->addAction(function () {
    // get the checkpoint, to store data in
    $checkpoint = getCheckpoint();
    // load our test page
    usingBrowser()->gotoPage("http://news.bbc.co.uk");
    // get the title of the test page
    $checkpoint->title = fromBrowser()->getTitle();
});
// ========================================================================
//
// POST-TEST INSPECTION
//
// ------------------------------------------------------------------------
$story->addPostTestInspection(function () {
    // get the checkpoint
    $checkpoint = getCheckpoint();
    // what title are we expecting?
    $expectedTitle = fromStoryplayer()->getStorySetting("modules.http.remotePage.title");
    // do we have the title we expected?
    assertsObject($checkpoint)->hasAttribute('title');
    assertsString($checkpoint->title)->equals($expectedTitle);
});
// ------------------------------------------------------------------------
// ========================================================================
//
// PRE-TEST INSPECTION
//
// ------------------------------------------------------------------------
// ========================================================================
//
// POSSIBLE ACTION(S)
//
// ------------------------------------------------------------------------
$story->addAction(function () {
    // get the checkpoint, to store data in
    $checkpoint = getCheckpoint();
    // load our test page
    usingBrowser()->gotoPage("file://" . __DIR__ . '/../../testpages/index.html');
    // get a h2 by its ID
    $checkpoint->content = fromBrowser()->getText()->fromHeadingWithId('self_test_website');
});
// ========================================================================
//
// POST-TEST INSPECTION
//
// ------------------------------------------------------------------------
$story->addPostTestInspection(function () {
    // get the checkpoint
    $checkpoint = getCheckpoint();
    // do we have the content we expected?
    assertsObject($checkpoint)->hasAttribute('content');
    assertsString($checkpoint->content)->equals("Self-Test Website");
});
    $checkpoint->expectedDimensions = array('width' => 400, 'height' => 400);
});
// ========================================================================
//
// POSSIBLE ACTION(S)
//
// ------------------------------------------------------------------------
$story->addAction(function () {
    // get the checkpoint, to store data in
    $checkpoint = getCheckpoint();
    // load our test page
    usingBrowser()->gotoPage("file://" . __DIR__ . '/../../testpages/index.html');
    // resize the window
    usingBrowser()->resizeCurrentWindow($checkpoint->expectedDimensions['width'], $checkpoint->expectedDimensions['height']);
    // remember the new size for later
    $checkpoint->actualDimensions = fromBrowser()->getCurrentWindowSize();
    // did the browser change size?
    expectsBrowser()->currentWindowSizeIs($checkpoint->expectedDimensions['width'], $checkpoint->expectedDimensions['height']);
});
// ========================================================================
//
// POST-TEST INSPECTION
//
// ------------------------------------------------------------------------
$story->addPostTestInspection(function () {
    // get the checkpoint
    $checkpoint = getCheckpoint();
    // do we have the dimensions at all?
    assertsObject($checkpoint)->hasAttribute('expectedDimensions');
    assertsObject($checkpoint)->hasAttribute('actualDimensions');
    // do they match?
// ========================================================================
//
// POSSIBLE ACTION(S)
//
// ------------------------------------------------------------------------
$story->addAction(function () {
    // get the checkpoint, to store data in
    $checkpoint = getCheckpoint();
    // load our test page
    usingBrowser()->gotoPage("file://" . __DIR__ . '/../../testpages/WorkingWithIFrames.html');
    // get a h1
    $checkpoint->mainHeader = fromBrowser()->getText()->fromHeadingWithId('storyplayer_working_with_iframes');
    // switch to the iFrame
    usingBrowser()->switchToIframe('iframe1');
    // get the h1 now
    $checkpoint->iFrameHeader = fromBrowser()->getText()->fromHeadingWithId('storyplayer_working_with_iframes');
});
// ========================================================================
//
// POST-TEST INSPECTION
//
// ------------------------------------------------------------------------
$story->addPostTestInspection(function () {
    // get the checkpoint
    $checkpoint = getCheckpoint();
    // do we have the content we expected?
    assertsObject($checkpoint)->hasAttribute('mainHeader');
    assertsString($checkpoint->mainHeader)->equals("Storyplayer: Working With IFrames");
    assertsObject($checkpoint)->hasAttribute('iFrameHeader');
    assertsString($checkpoint->iFrameHeader)->equals("IFrame Content");
});
// PRE-TEST PREDICTION
//
// ------------------------------------------------------------------------
// ========================================================================
//
// PRE-TEST INSPECTION
//
// ------------------------------------------------------------------------
// ========================================================================
//
// POSSIBLE ACTION(S)
//
// ------------------------------------------------------------------------
$story->addAction(function () {
    // load our test page
    usingBrowser()->gotoPage("file://" . __DIR__ . '/../../testpages/index.html');
});
// ========================================================================
//
// POST-TEST INSPECTION
//
// ------------------------------------------------------------------------
$story->addPostTestInspection(function () {
    // if this feature is working, the browser should already be open
    // and we can just grab the title
    $title = fromBrowser()->getTitle();
    // do we have the title we expected?
    assertsString($title)->equals("Storyplayer: Welcome To The Tests!");
    // all done - shut down the browser
    stopDevice();
});
Exemplo n.º 11
0
 public function waitForTitle($timeout, $title, $failedTitle = null)
 {
     // what are we doing?
     $log = usingLog()->startAction("check that the the right page has loaded");
     // check the title
     usingTimer()->waitFor(function () use($title, $failedTitle) {
         // have we already failed?
         if ($failedTitle && fromBrowser()->getTitle() == $failedTitle) {
             return false;
         }
         // we have not failed yet
         expectsBrowser()->hasTitle($title);
     }, $timeout);
     // all done
     $log->endAction();
 }
Exemplo n.º 12
0
 public function currentWindowSizeIs($width, $height)
 {
     // what are we doing?
     $log = usingLog()->startAction("current browser window dimensions must be '{$width}' x '{$height}' (w x h)");
     // get the dimensions
     $dimensions = fromBrowser()->getCurrentWindowSize();
     // are they right?
     if ($dimensions['width'] != $width || $dimensions['height'] != $height) {
         throw new E5xx_ExpectFailed(__METHOD__, "{$width} x {$height}", "{$dimensions['width']} x {$dimensions['height']}");
     }
     // all done
     $log->endAction();
 }