Webdriver adapter (for Larave or standalone usage)
, (*1)
, (*2)
Selenium Firefox web-driver adapter (for Laravel 5.2.* and standalone use), (*3)
This package uses the facebook's php-webdriver library, (*4)
Collect all mostly used methods in one class and give providers and aliases for working vs it, (*5)
Now can be used standalone, (*6)
Laravel supporting
-
Laravel 5.3.x: in developing, (*7)
-
Laravel 5.2.x: 1.0.1, (*8)
-
Laravel 5.1.x: 0.1.2, (*9)
-
Laravel < 5.1: not supported, (*10)
Quick start
Install
Run composer require lionmm/laravel-ff-webdriver, (*11)
Laravel 5.1.x to 5.2.x
In your config/app.php add LionMM\WebDriver\WebDriverServiceProvider::class, to the end of the providers array, (*12)
'providers' => array(
...
LionMM\WebDriver\WebDriverServiceProvider::class,
),
Add the WebDriver facade to the end of the aliases array as well, (*13)
'aliases' => array(
...
'WebDriver' => LionMM\WebDriver\Facades\WebDriver::class,
),
Usage
Selenium requirement
For using library you must install and run Selenium server, (*14)
By default, library try to connect to http://localhost:4444/wd/hub, (*15)
You can change that path in config/webdriver.php (see above), (*16)
Using library
Best way - using Facade by alias WebDriver::method(), (*17)
Also, you can make instance of \LionMM\WebDriver\WebDriver class, (*18)
<?php
use LionMM\WebDriver\WebDriver;
class Foo {
public function Bar()
{
$webDriver = \App::make('webdriver'); // use \App::make for DI and 'webdriver' for singleton
}
}
OR, (*19)
<?php
use LionMM\WebDriver\WebDriver;
class Foo {
/** @var WebDriver */
private $webDriver;
public function __construct(WebDriver $webDriver)
{
$this->webDriver = $webDriver;
}
}
Next step - you must init Driver with method initDriver($parameters, $request_time_limit), (*20)
<?php
\WebDriver::initDriver(['lang' => 'en', 'no-flash' => true, 'proxy' => '220.155.15.133:8080'], 50000);
Instead, the parameter lang You can specify directly 'accept_languages' => 'ru-RU,ru,en,en-US,uk', (*21)
<?php
\WebDriver::initDriver(['accept_languages' => 'ru-RU,ru,en,en-US,uk', 'no-flash' => false, 'proxy' => '220.155.15.133:8080'], 50000, 'http:hub.site:5555/wd/hub');
By default flash is enabled and accept_languages set to ru-RU,ru,en,en-US,uk, (*22)
Go to url
Use method get($url) for load a new web page in the current browser window., (*23)
Operate vs page content
waitForElement($selector, $index, $timeout)
checkForElement($selector)
getAllElements($selector, $need, $timeout)
Frames
-
switchToFrame($element): Switch to the iframe by its id or name.
-
switchToDefaultContent(): Switch to the main document if the page contains iframes. Otherwise, switch to the first frame on the page.
Service functions
-
quit($wait = 0): run automatically in __destruct() method. Quits driver, closing every associated window. (hope this...)
-
deleteAllCookies(): Delete all the cookies that are currently visible.
-
getCookies(): Get all the cookies for the current domain.
-
addCookie($cookie): Add a specific cookie.
-
getCurrentURL(): Get a string representing the current URL that the browser is looking at
-
getTitle(): Get the title of the current page.
-
getPageSource(): Get the source of the last loaded page.
-
takeScreenshot($pathToSave): Take a screenshot of the current page. if parameter $pathToSave not set method return the screenshot contents in PNG format
-
executeScript($jsCode, $arguments, $async): Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. The result of evaluating the script will be returned.