Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
4c0de87177
@ -11,17 +11,12 @@
|
||||
host="127.0.0.1"
|
||||
port="4444"
|
||||
timeout="30000"/>
|
||||
<browser name="Google Chrome on localhost"
|
||||
browser="googlechrome"
|
||||
host="127.0.0.1"
|
||||
port="4444"
|
||||
timeout="30000"/>
|
||||
</selenium>
|
||||
|
||||
<php>
|
||||
<const name="TESTSUITE_SERVER" value="localhost"/>
|
||||
<const name="TESTSUITE_USER" value="root"/>
|
||||
<const name="TESTSUITE_PASSWORD" value=""/>
|
||||
<const name="TESTSUITE_PASSWORD" value="root"/>
|
||||
<const name="TESTSUITE_DATABASE" value="test"/>
|
||||
<const name="TESTSUITE_PHPMYADMIN_HOST" value="http://localhost" />
|
||||
<const name="TESTSUITE_PHPMYADMIN_URL" value="/phpmyadmin" />
|
||||
|
||||
38
test/AllSeleniumTests.php
Normal file
38
test/AllSeleniumTests.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* runs all defined Selenium tests
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once 'PHPUnit/TextUI/TestRunner.php';
|
||||
require_once dirname(__FILE__).'/selenium/PmaSeleniumTestCase.php';
|
||||
require_once dirname(__FILE__).'/selenium/PmaSeleniumLoginTest.php';
|
||||
require_once dirname(__FILE__).'/selenium/PmaSeleniumXssTest.php';
|
||||
require_once dirname(__FILE__).'/selenium/PmaSeleniumPrivilegesTest.php';
|
||||
|
||||
class AllSeleniumTests
|
||||
{
|
||||
public static function main()
|
||||
{
|
||||
$parameters = array();
|
||||
PHPUnit_TextUI_TestRunner::run(self::suite(), $parameters);
|
||||
}
|
||||
|
||||
public static function suite()
|
||||
{
|
||||
$suite = new PHPUnit_Framework_TestSuite('phpMyAdmin');
|
||||
|
||||
$suite->addTestSuite('PmaSeleniumLoginTest');
|
||||
//$suite->addTestSuite('PmaSeleniumXssTest');
|
||||
//$suite->addTestSuite('PmaSeleniumPrivilegesTest');
|
||||
return $suite;
|
||||
}
|
||||
}
|
||||
?>
|
||||
32
test/selenium/Helper.php
Normal file
32
test/selenium/Helper.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
require_once 'TestConfig.php';
|
||||
|
||||
class Helper {
|
||||
|
||||
public static $selenium;
|
||||
public static $config;
|
||||
|
||||
function __construct() {
|
||||
self::$config = new TestConfig();
|
||||
}
|
||||
|
||||
public static function isLoggedIn($selenium) {
|
||||
return $selenium->isElementPresent('//*[@id="serverinfo"]/a[1]');
|
||||
}
|
||||
|
||||
public static function logOutIfLoggedIn($selenium) {
|
||||
if (self::isLoggedIn($selenium)) {
|
||||
$selenium->selectFrame("frame_navigation");
|
||||
$selenium->clickAndWait("css=img.icon.ic_b_home");
|
||||
}
|
||||
}
|
||||
|
||||
public static function getBrowserString() {
|
||||
$browserString = self::$config->getCurrentBrowser();
|
||||
return $browserString;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Selenium TestCase for login related tests
|
||||
@ -6,38 +7,31 @@
|
||||
* @package PhpMyAdmin-test
|
||||
* @group Selenium
|
||||
*/
|
||||
|
||||
require_once 'PmaSeleniumTestCase.php';
|
||||
require_once 'Helper.php';
|
||||
|
||||
class PmaSeleniumLoginTest extends PHPUnit_Extensions_SeleniumTestCase {
|
||||
|
||||
class PmaSeleniumLoginTest extends PmaSeleniumTestCase
|
||||
{
|
||||
protected $captureScreenshotOnFailure = true;
|
||||
protected $screenshotPath = '/var/www/screenshots';
|
||||
protected $screenshotUrl = 'http://localhost/screenshots';
|
||||
public function setUp() {
|
||||
$helper = new Helper();
|
||||
$this->setBrowser(Helper::getBrowserString());
|
||||
$this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL);
|
||||
}
|
||||
|
||||
public function testLogin()
|
||||
{
|
||||
$this->doLogin();
|
||||
public function testSuccessfulLogin() {
|
||||
$log = new PmaSeleniumTestCase($this);
|
||||
$log->login(TESTSUITE_USER, TESTSUITE_PASSWORD);
|
||||
$this->assertTrue($log->isSuccessLogin());
|
||||
Helper::logOutIfLoggedIn($this);
|
||||
}
|
||||
|
||||
// Check if login error happend
|
||||
if ($this->isElementPresent("//html/body/div/div[@class='error']")) {
|
||||
$this->fail($this->getText("//html/body/div/div[@class='error']"));
|
||||
}
|
||||
public function testLoginWithWrongPassword() {
|
||||
$log = new PmaSeleniumTestCase($this);
|
||||
$log->login("Admin", "Admin");
|
||||
$this->assertTrue($log->isUnsuccessLogin());
|
||||
Helper::logOutIfLoggedIn($this);
|
||||
}
|
||||
|
||||
// Check server info heder is present //*[@id="serverinfo"]
|
||||
for ($second = 0;; $second++) {
|
||||
if ($second >= 60)
|
||||
$this->fail("Timeout waiting main page to load!");
|
||||
try {
|
||||
if ($this->isElementPresent("//*[@id=\"serverinfo\"]"))
|
||||
break;
|
||||
} catch (Exception $e) {
|
||||
$this->fail("Exception: ".$e->getMessage());
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@ -7,65 +7,63 @@
|
||||
* @group Selenium
|
||||
*/
|
||||
|
||||
// Optionally add the php-client-driver to your include path
|
||||
//set_include_path(get_include_path() . PATH_SEPARATOR . '/opt/selenium-remote-control-1.0.1/selenium-php-client-driver-1.0.1/PEAR/');
|
||||
|
||||
// Include the main phpMyAdmin user config
|
||||
// currently only $cfg['Test'] is used
|
||||
require_once 'config.sample.inc.php';
|
||||
|
||||
|
||||
|
||||
class PmaSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase
|
||||
class PmaSeleniumTestCase
|
||||
{
|
||||
protected $selenium;
|
||||
protected $cfg;
|
||||
private $txtUsername;
|
||||
private $txtPassword;
|
||||
private $btnLogin;
|
||||
private $selenium;
|
||||
private $config;
|
||||
|
||||
protected $captureScreenshotOnFailure = true;
|
||||
protected $screenshotPath = '/var/www/screenshots';
|
||||
protected $screenshotUrl = 'http://localhost/screenshots';
|
||||
public function __construct($selenium) {
|
||||
$this->txtUsername = 'input_username';
|
||||
$this->txtPassword = 'input_password';
|
||||
$this->btnLogin = 'input_go';
|
||||
$this->config = new TestConfig();
|
||||
$this->selenium = $selenium;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
global $cfg;
|
||||
$this->cfg =& $cfg;
|
||||
//PHPUnit_Extensions_SeleniumTestCase::$browsers = $this->cfg['Test']['broswers'];
|
||||
|
||||
$this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL);
|
||||
|
||||
$this->start();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->stop();
|
||||
/**
|
||||
* perform a login
|
||||
* @param <type> $username
|
||||
* @param <type> $password
|
||||
*/
|
||||
public function login($username, $password) {
|
||||
|
||||
$this->selenium->open($this->config->getLoginURL());
|
||||
$this->selenium->type($this->txtUsername, $username);
|
||||
$this->selenium->type($this->txtPassword, $password);
|
||||
$this->selenium->click($this->btnLogin);
|
||||
$this->selenium->waitForPageToLoad($this->config->getTimeoutValue());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* perform a login
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function doLogin()
|
||||
{
|
||||
$this->open(TESTSUITE_PHPMYADMIN_URL);
|
||||
// Somehow selenium does not like the language selection on the cookie login page, forced English in the config for now.
|
||||
//$this->select("lang", "label=English");
|
||||
|
||||
$this->waitForPageToLoad("30000");
|
||||
$this->type("input_username", TESTSUITE_USER);
|
||||
$this->type("input_password", TESTSUITE_PASSWORD);
|
||||
$this->click("input_go");
|
||||
$this->waitForPageToLoad("30001");
|
||||
public function isSuccessLogin() {
|
||||
if($this->selenium->isElementPresent("//*[@id=\"serverinfo\"]")){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isUnsuccessLogin() {
|
||||
$val = $this->selenium->getValue('input_go');
|
||||
if($this->selenium->isElementPresent("//html/body/div/div[@class='error']")){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Just a dummy to show some example statements
|
||||
*
|
||||
public function mockTest()
|
||||
{
|
||||
// Slow down the testing speed, ideal for debugging
|
||||
//$this->setSpeed(4000);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
19
test/selenium/README
Normal file
19
test/selenium/README
Normal file
@ -0,0 +1,19 @@
|
||||
Guide to run the AllSeleniumTests.php (Yasitha Pandithawatta)
|
||||
=====================================
|
||||
|
||||
1. Tested with version 4.0
|
||||
2. Configure the testing environment - Browser and the following feilds in phpunit.xml.dist
|
||||
<php>
|
||||
<const name="TESTSUITE_SERVER" value="localhost"/>
|
||||
<const name="TESTSUITE_USER" value="root"/>
|
||||
<const name="TESTSUITE_PASSWORD" value="root"/>
|
||||
<const name="TESTSUITE_DATABASE" value="test"/>
|
||||
<const name="TESTSUITE_PHPMYADMIN_HOST" value="http://localhost" />
|
||||
<const name="TESTSUITE_PHPMYADMIN_URL" value="/phpmyadmin-dev" />
|
||||
</php>
|
||||
3. Start the selenium server
|
||||
4. run $ phpunit test/AllSeleniumTests.php
|
||||
|
||||
Note: Only PmaSeleniumLoginTest.php is fixed and added to the test suit.
|
||||
|
||||
|
||||
52
test/selenium/TestConfig.php
Normal file
52
test/selenium/TestConfig.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
class TestConfig {
|
||||
|
||||
private $loginURL;
|
||||
private $timeoutValue;
|
||||
|
||||
public function __construct() {
|
||||
$xml = simplexml_load_file("phpunit.xml.dist");
|
||||
$xmlDoc = new DOMDocument();
|
||||
$xmlDoc->load('phpunit.xml.dist');
|
||||
$searchNode = $xmlDoc->getElementsByTagName("browser");
|
||||
foreach ($searchNode as $searchNode) {
|
||||
$this->setCurrentBrowser($searchNode->getAttribute('browser'));
|
||||
$this->setTimeoutValue($searchNode->getAttribute('timeout'));
|
||||
}
|
||||
$this->setLoginURL(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL);
|
||||
}
|
||||
|
||||
public function setLoginURL($value) {
|
||||
|
||||
$this->loginURL = $value;
|
||||
}
|
||||
|
||||
public function getLoginURL() {
|
||||
|
||||
return $this->loginURL;
|
||||
}
|
||||
|
||||
public function setTimeoutValue($value) {
|
||||
|
||||
$this->timeoutValue = $value;
|
||||
}
|
||||
|
||||
public function getTimeoutValue() {
|
||||
|
||||
return $this->timeoutValue;
|
||||
}
|
||||
|
||||
public function setCurrentBrowser($value) {
|
||||
|
||||
$this->currentBrowser = $value;
|
||||
}
|
||||
|
||||
public function getCurrentBrowser() {
|
||||
|
||||
return $this->currentBrowser;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user