Selenium Firefox web-driver adapter (for Laravel 5.2.* and standalone use)
This package uses the facebook's php-webdriver library
Collect all mostly used methods in one class and give providers and aliases for working vs it
Now can be used standalone
-
Laravel 5.3.x:
in developing
-
Laravel 5.2.x:
1.0.1
-
Laravel 5.1.x:
0.1.2
-
Laravel < 5.1:
not supported
Run composer require lionmm/laravel-ff-webdriver
In your config/app.php
add LionMM\WebDriver\WebDriverServiceProvider::class,
to the end of the providers
array
'providers' => array(
...
LionMM\WebDriver\WebDriverServiceProvider::class,
),
Add the WebDriver
facade to the end of the aliases
array as well
'aliases' => array(
...
'WebDriver' => LionMM\WebDriver\Facades\WebDriver::class,
),
For using library you must install and run Selenium server
By default, library try to connect to http://localhost:4444/wd/hub
You can change that path in config/webdriver.php
(see above)
Best way - using Facade by alias WebDriver::method()
Also, you can make instance of \LionMM\WebDriver\WebDriver
class
<?php
use LionMM\WebDriver\WebDriver;
class Foo {
public function Bar()
{
$webDriver = \App::make('webdriver'); // use \App::make for DI and 'webdriver' for singleton
}
}
OR
<?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)
<?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'
<?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
Use method get($url)
for load a new web page in the current browser window.
waitForElement($selector, $index, $timeout)
checkForElement($selector)
getAllElements($selector, $need, $timeout)
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.
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 atgetTitle()
: 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 formatexecuteScript($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.