PHP 5.3+ Web瀏覽器模擬測試:Mink

bgn4 9年前發布 | 17K 次閱讀 Mink 測試工具

Mink 是開源的 PHP 瀏覽器/控制器 模擬測試工具。Mink 可以模擬 Web 應用和瀏覽器之間的交互,測試 Web 應用的行為是否正確。

<?php

use Behat\Mink\Mink, Behat\Mink\Session, Behat\Mink\Driver\GoutteDriver, Behat\Mink\Driver\Goutte\Client as GoutteClient; $startUrl = '

// init Mink and register sessions $mink = new Mink(array( 'goutte1' => new Session(new GoutteDriver(new GoutteClient())), 'goutte2' => new Session(new GoutteDriver(new GoutteClient())), 'custom' => new Session(new MyCustomDriver($startUrl)) ));

// set the default session name $mink->setDefaultSessionName('goutte2');

// visit a page $mink->getSession()->visit($startUrl);

// call to getSession() without argument will always return a default session if has one (goutte2 here) $mink->getSession()->getPage()->findLink('Downloads')->click(); echo $mink->getSession()->getPage()->getContent();

// call to getSession() with argument will return session by its name $mink->getSession('custom')->getPage()->findLink('Downloads')->click(); echo $mink->getSession('custom')->getPage()->getContent();

// this all is done to make possible mixing sessions $mink->getSession('goutte1')->getPage()->findLink('Chat')->click(); $mink->getSession('goutte2')->getPage()->findLink('Chat')->click();</pre>

項目主頁:http://www.baiduhome.net/lib/view/home/1430832116976

 本文由用戶 bgn4 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!