Example #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;
 }
// ------------------------------------------------------------------------
// ========================================================================
//
// 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');
    $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?
    assertsObject($checkpoint)->hasAttribute('mainHeader');
    assertsString($checkpoint->mainHeader)->equals("Storyplayer: Working With Windows");
    assertsObject($checkpoint)->hasAttribute('secondHeader');
    assertsString($checkpoint->secondHeader)->equals("Storyplayer: Second Window");
});
// ------------------------------------------------------------------------
// ========================================================================
//
// 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 = getCheckpoint();
    // what size do we expect?
    $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');
//
// ------------------------------------------------------------------------
// ========================================================================
//
// 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');
// ========================================================================
//
// 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');
    // switch to the iFrame
    usingBrowser()->switchToIframe('iframe1');
    // get the h1
    $checkpoint->iFrameHeader = fromBrowser()->getText()->fromHeadingWithId('storyplayer_working_with_iframes');
    // switch back to the main frame
    usingBrowser()->switchToMainFrame();
    // get a h1
    $checkpoint->mainHeader = 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');
//
// ------------------------------------------------------------------------
// ========================================================================
//
// PRE-TEST PREDICTION
//
// ------------------------------------------------------------------------
// ========================================================================
//
// PRE-TEST INSPECTION
//
// ------------------------------------------------------------------------
// ========================================================================
//
// POSSIBLE ACTION(S)
//
// ------------------------------------------------------------------------
$story->addAction(function () {
    // load our test page
    usingBrowser()->gotoPage("file://" . __DIR__ . '/../../testpages/WorkingWithForms.html');
    // check the control that we're interested in
    expectsForm('test_form')->inputWithLabel('Page Subtitle')->isBlank();
});
// ========================================================================
//
// POST-TEST INSPECTION
//
// ------------------------------------------------------------------------
$story->addPostTestInspection(function () {
    // do nothing
});