Created
August 23, 2015 11:35
-
-
Save PsyChip/d57f8c9d32a410ed7929 to your computer and use it in GitHub Desktop.
Minified php driver for selenium web automation framework (http://www.seleniumhq.org)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Minified Sellenium PHP Driver | |
* Requires original webdriver to run | |
* | |
* Coded By Armagan Corlu aka Psy_chip | |
* root@psychip.net | |
* 2012 | |
* | |
* + Macro Support | |
* + minified functions | |
* | |
* initial array: (host,port,browser,startpage); | |
*/ | |
class SEdriver extends Webdriver { | |
public $buffer; | |
public $latency = 1; | |
function __construct($details) { | |
parent::__construct($details['host'], $details['port']); | |
$this->connect($details['engine']); | |
if (isset($details['page'])) { | |
$this->get($details['page']); | |
} | |
} | |
function click($id) { | |
parent::findElementBy(LocatorStrategy::id, $id)->click(); | |
} | |
function html() { | |
$this->buffer = $this->getpagesource(); | |
return $this->buffer; | |
} | |
function focus($id) { | |
parent::selectWindow($id); | |
} | |
function sendkey($id, $value) { | |
$arr = Array(); | |
$arr[] = $value; | |
parent::findElementBy(LocatorStrategy::id, $id)->sendKeys($arr); | |
} | |
function fillform($formdata) { | |
foreach (array_keys($formdata) as $id) { | |
$this->sendkey($id, $formdata[$id]); | |
} | |
} | |
function loadscript($file) { | |
$script = file_get_contents($file); | |
parent::executeScript($script, array()); | |
} | |
function screenshot($file) { | |
parent::getScreenshotAndSaveToFile($file); | |
} | |
function runmacro($macro) { | |
foreach (array_keys($macro) as $action) { | |
$act = explode('-', $action); | |
switch ($act[1]) { | |
case 'GET': | |
$this->get($macro[$action]); | |
break; | |
case 'FOCUS': | |
$this->focus($macro[$action]); | |
break; | |
case 'CLICK': | |
$this->click($macro[$action]); | |
break; | |
case 'FILL': | |
foreach (array_keys($macro[$action]) as $domid) { | |
$this->sendkey($domid, $macro[$action][$domid]); | |
} | |
break; | |
case 'RUNJS': | |
$this->execute($macro[$action], array()); | |
break; | |
case 'FRAME': | |
$this->focusFrame($macro[$action]); | |
break; | |
} | |
sleep($this->latency); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment