为什么这些错误来自casperjs?

时间:2018-07-30 07:17:04

标签: php laravel phantomjs casperjs

我正在使用laravel,我想使用casperjs。但是安装似乎是错误的

-我遵循的步骤-

  1. https://packagist.org/packages/jerome-breton/casperjs-installer
    • 编写者需要jerome-breton / casperjs-installer

下一步

  1. https://packagist.org/packages/phpcasperjs/phpcasperjs
    • 编写者需要phpcasperjs / phpcasperjs命令

我在控制器中编写了以下代码

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Browser\Casper;

class TestController extends Controller
{
private static $casperBinPath = '/usr/local/bin/';

public static function setUpBeforeClass()
{
    if (!file_exists(self::$casperBinPath . 'casperjs')) {
        self::$casperBinPath = 'node_modules/casperjs/bin/';
    }
}

public function testStart_onGoogleSearchPage()
{
    $casper = new Casper(self::$casperBinPath);

    $casper->start('http://www.google.com');
    $casper->fillForm(
        'form[action="/search"]',
        array(
            'q' => 'search'
        ),
        true);
    $casper->click('h3.r a');
    $casper->run();

    $this->assertTrue(is_array($casper->getOutput()));
    $this->assertTrue(sizeof($casper->getOutput()) > 0);
    $this->assertNotNull($casper->getCurrentUrl());
}
}

此后,我去了http://127.0.0.1/test/public/ 但是,我收到此错误安装是否错误?

tempnam (): file created in the system's temporary directory

C:\Bitnami\wampstack-7.1.20- 
0\apache2\htdocs\test\vendor\phpcasperjs\phpcasperjs\src\Casper.php
    $output = array();

    $fragment = <<<FRAGMENT
casper.then(function () {
this.echo('$this->TAG_CURRENT_URL' + this.getCurrentUrl());
this.echo('$this->TAG_CURRENT_TITLE' + this.getTitle());
this.echo('$this->TAG_CURRENT_PAGE_CONTENT' + 
this.getPageContent().replace(new RegExp('\\r?\\n','g'), ''));
this.echo('$this->TAG_CURRENT_HTML' + this.getHTML().replace(new RegExp('\\r? 
\\n','g'), ''));
this.echo('$this->TAG_CURRENT_HEADERS' + 
JSON.stringify(this.currentResponse.headers));
this.echo('$this->TAG_CURRENT_STATUS' + this.currentResponse.status);
this.echo('$this->TAG_CURRENT_STATUS_TEXT' + 
this.currentResponse.statusText);
this.echo('$this->TAG_CURRENT_COOKIES' + JSON.stringify(phantom.cookies));
});

casper.run();

FRAGMENT;

    $this->script .= $fragment;
    $filename = tempnam($this->tempDir, 'php-casperjs-');  <<-- red color (error)

    file_put_contents($filename, $this->script);

    // options parsing
    $options = '';
    foreach ($this->options as $option => $value) {
        $options .= ' --' . $option . '=' . $value;
    }

    exec($this->path2casper . 'casperjs ' . $filename . $options, $output);
    if (empty($output)) {
        throw new \Exception('Can not find CasperJS.');
    }

    $this->setOutput($output);
    $this->processOutput();

    unlink($filename);

    return $output;
Arguments
"tempnam(): file created in the system's temporary directory"

请给我一些建议。

0 个答案:

没有答案