lionmm/laravel-ff-webdriver

This package is abandoned and no longer maintained. No replacement package was suggested.

Selenium Firefox web-driver interface for Laravel 5.1.* - 5.2.*

1.0.4 2017-11-15 13:22 UTC

This package is not auto-updated.

Last update: 2021-02-25 14:39:07 UTC


README

Latest Stable Version Total Downloads License

GitHub tag GitHub release Github All Releases

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 supporting

  • 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

Quick start

Install

Run composer require lionmm/laravel-ff-webdriver

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

'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,
),

Usage

Selenium requirement

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)

Using library

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

Go to url

Use method get($url) for load a new web page in the current browser window.

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.