2

I need a headless web browser with JS support to use during cron. It seems like the simpletest module does what I need, but how could one initiate a browser and hand it a DOM?

Outside the context of Drupal cron, it would go like this:

require_once('simpletest/browser.php');

$browser = &new SimpleBrowser();
$browser->get('http://php.net/');

But, is there a way I can use the code that the simpletest module already provides?

  • 3
    Do you really need js during cron? Seems needlessly complicated; couldn't you just provide equivalent functions to the js code in php? Without js, you can easily call cron via Drush. See: drupalcode.org/project/drush.git/blob_plain/HEAD:/docs/… – greg_1_anderson Oct 16 '12 at 6:21
  • Why was my question closed? It relates directly to Drupal development, using a popular module, for a real problem and can be clearly answered. greg_1_anderson's comment ignores the question. – Joe Beuckman Oct 16 '12 at 11:39
  • 2
    @Joe I voted to close as off topic because the question was essentially "I need a headless web browser with JS support to use during cron" which in itself can be answered without any reference to Drupal. Your edit makes it clearer that you wish to do this using Drupal modules so I've voted to re-open :) – Clive Oct 16 '12 at 13:17
  • 3
    The only point of my comment was that you should seriously consider whether you need js during cron. From your updated example, it looks like you do. I think this is an interesting question, and voted to re-open it. – greg_1_anderson Oct 16 '12 at 15:05
4

If you want a PHP headless web browser, you might look at Mink.

Gherkin/Behat seem to be getting some traction in the Drupal community and in the PHP community more broadly for Behavioral Driven Development. Mink also supports browser emulation systems (like Selenium), which you typically need in order to interact with Javascript.

1

SimpleBrowser does not support Javascript. I'll have to use a headless browser like Phantom or Zombie or script something to execute the JS more directly with a given DOM.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.