PHP code example of zzctmac / flwt

1. Go to this page and download the library: Download zzctmac/flwt library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zzctmac / flwt example snippets


class Login extends \flwt\wpd\Page
{
    protected $thumb = "form#login_form>input#username+input#password+input#submitBtn";
    protected $urlPattern = "/login.html";
}

class Valid extends \flwt\wpd\Page
{
    protected $thumb = "h1#tip";
    protected $urlPattern = "/valid.php";
}



use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;

/**
 * 创建webdriver实例
 * 将用到的Page类添加到PageClassManager(方便跳转到新页面自动找到对应的Page类)
 * etc
 * 可以在phpunit中定义的bootstrap.php 做这些预备工作
**/


$host = 'http://localhost:4444/wd/hub'; // this is the default


$capabilities = DesiredCapabilities::chrome();
$driver = RemoteWebDriver::create($host, $capabilities, 5000);

\flwt\UrlHandler::setPrefix("http://localhost");

\flwt\Resource::create($driver);

PageClassManager::addClass(Login::class);
PageClassManager::addClass(Valid::class);


\dfb\Login::openNow();
\flwt\query\Emmet::get('#username')->input('username');
$alert = \flwt\query\Emmet::get('#password')->input('password')->submit(1);
$alert->click();



class PageTest extends PHPUnit_Framework_TestCase
{
    public function submitDataProvider()
    {
        $data = array(
            array('u1', 'p1', 'success'),
            array('u2', 'p2', 'failed')
        );
        return $data;
    }

    /**
     * @dataProvider submitDataProvider
     * @param $name
     * @param $password
     * @param $expected
     */
    public function test_submit($name, $password, $expected)
    {

        Login::openNow();
        \flwt\query\Emmet::get('#username')->input($name);
        \flwt\query\Emmet::get('#password')->input($password)->submit();
        $tip = \flwt\query\Emmet::get('#tip');
        $this->assertEquals($expected, $tip->getText());
    }
}