Actions

Difference between revisions of "Selenium Test Case Methods"

From Joomla! Documentation

(Available Selenium Test Case Methods)
(+colorized)
Line 32: Line 32:
 
* Loads the configuration variables defined in <code>tests/system/servers/configdef.php</code> and launches the test browser accordingly.
 
* Loads the configuration variables defined in <code>tests/system/servers/configdef.php</code> and launches the test browser accordingly.
  
<pre> public function setUp()
+
<source lang="php">
{
+
public function setUp()
$cfg = new SeleniumConfig();
+
{
$this->cfg = $cfg; // save current configuration
+
    $cfg = new SeleniumConfig();
$this->setBrowser($cfg->browser);
+
    $this->cfg = $cfg; // save current configuration
$this->setBrowserUrl($cfg->host.$cfg->path);
+
    $this->setBrowser($cfg->browser);
if(isset($cfg->selhost)) {
+
    $this->setBrowserUrl($cfg->host.$cfg->path);
$this->setHost($cfg->selhost);
+
    if(isset($cfg->selhost)) {
}
+
        $this->setHost($cfg->selhost);
echo ".\n".'Starting '.get_class($this).".\n";
+
    }
}</pre>
+
    echo ".\n".'Starting '.get_class($this).".\n";
 +
}
 +
</source>
  
 
=== doAdminLogin ===
 
=== doAdminLogin ===
 
* Logs into the administrative side of Joomla!
 
* Logs into the administrative side of Joomla!
  
<pre> function doAdminLogin()
+
<source lang="php">
{
+
function doAdminLogin()
//$this->setUp();
+
{
echo "Logging in to admin.\n";
+
    //$this->setUp();
$cfg = new SeleniumConfig();
+
    echo "Logging in to admin.\n";
$this->open($cfg->path . "administrator/index.php?option=com_login");
+
    $cfg = new SeleniumConfig();
$this->waitForPageToLoad("30000");
+
    $this->open($cfg->path . "administrator/index.php?option=com_login");
$this->type("mod-login-username", $cfg->username);
+
    $this->waitForPageToLoad("30000");
$this->type("mod-login-password", $cfg->password);
+
    $this->type("mod-login-username", $cfg->username);
$this->click("link=Log in");
+
    $this->type("mod-login-password", $cfg->password);
$this->waitForPageToLoad("30000");
+
    $this->click("link=Log in");
}</pre>
+
    $this->waitForPageToLoad("30000");
 +
}
 +
</source>
  
 
=== doAdminLogout ===
 
=== doAdminLogout ===
 
* Logs out of the administrative side of Joomla!
 
* Logs out of the administrative side of Joomla!
<pre> function doAdminLogout()
+
<source lang="php">
{
+
function doAdminLogout()
$this->gotoAdmin();
+
{
echo "Logging out of back end.\n";
+
    $this->gotoAdmin();
$this->click("link=Logout");
+
    echo "Logging out of back end.\n";
}</pre>
+
    $this->click("link=Logout");
 +
}
 +
</source>
  
 
=== gotoAdmin ===
 
=== gotoAdmin ===
 
* Navigates to the administrative side of Joomla!
 
* Navigates to the administrative side of Joomla!
<pre> function gotoAdmin()
+
<source lang="php">
{
+
function gotoAdmin()
echo "Browsing to admin.\n";
+
{
$cfg = new SeleniumConfig();
+
    echo "Browsing to admin.\n";
$this->open($cfg->path . "administrator");
+
    $cfg = new SeleniumConfig();
}</pre>
+
    $this->open($cfg->path . "administrator");
 +
}
 +
</source>
  
 
=== gotoSite ===
 
=== gotoSite ===
 
* Navigates to the front end of Joomla!
 
* Navigates to the front end of Joomla!
<pre> function gotoSite()
+
<source lang="php">
{
+
function gotoSite()
echo "Browsing to site.\n";
+
{
$cfg = new SeleniumConfig();
+
    echo "Browsing to site.\n";
$this->open($cfg->path);
+
    $cfg = new SeleniumConfig();
}</pre>
+
    $this->open($cfg->path);
 +
}
 +
</source>
  
 
=== doFrontEndLogin ===
 
=== doFrontEndLogin ===
 
* Logs into the front end of Joomla!
 
* Logs into the front end of Joomla!
<pre> function doFrontEndLogin()
+
<source lang="php">
{
+
function doFrontEndLogin()
$this->gotoSite();
+
{
echo "Logging into front end of site.\n";
+
    $this->gotoSite();
$this->type("modlgn_username", "admin");
+
    echo "Logging into front end of site.\n";
$this->type("modlgn_passwd", "password");
+
    $this->type("modlgn_username", "admin");
$this->click("Submit");
+
    $this->type("modlgn_passwd", "password");
$this->waitForPageToLoad("30000");
+
    $this->click("Submit");
}</pre>
+
    $this->waitForPageToLoad("30000");
 +
}
 +
</source>
  
 
=== doFrontEndLogout ===
 
=== doFrontEndLogout ===
 
* Logs out of the front end of Joomla!
 
* Logs out of the front end of Joomla!
<pre> function doFrontEndLogout()
+
<source lang="php">
{
+
function doFrontEndLogout()
$this->gotoSite();
+
{
echo "Logging out of front end of site.\n";
+
    $this->gotoSite();
$this->click("Submit");
+
    echo "Logging out of front end of site.\n";
$this->waitForPageToLoad("30000");
+
    $this->click("Submit");
}</pre>
+
    $this->waitForPageToLoad("30000");
 +
}</source>
  
 
=== setTinyText ===
 
=== setTinyText ===
 
* Allows the test to input data
 
* Allows the test to input data
<pre> function setTinyText($text)
+
<source lang="php">
{
+
function setTinyText($text)
$this->selectFrame("text_ifr");
+
{
$this->type("tinymce", $text);
+
    $this->selectFrame("text_ifr");
$this->selectFrame("relative=top");
+
    $this->type("tinymce", $text);
}</pre>
+
    $this->selectFrame("relative=top");
 +
}</source>
  
 
[[Category:Bug Squad]] [[Category:Development]] [[Category:Testing]] [[Category:Automated Testing]]
 
[[Category:Bug Squad]] [[Category:Development]] [[Category:Testing]] [[Category:Automated Testing]]

Revision as of 22:02, 7 June 2010

Contents

News and Updates

2010 02 10 : Initial draft of this article

Introduction

With the introduction of System tests in February 2010, there are also a number of Joomla! specific methods that can be used. These methods are part of the SeleniumJoomlaTestCase class, as defined by the file tests/system/SeleniumJoomlaTestCase.php

These methods exist so that none of the path or login information is coded into the tests. Instead, it comes from the config file located at tests/system/servers/configdef.php See Running_Automated_Tests_for_Version_1.6#Create_a_Selenium_Configuration_File These methods can also be used for creating streamlined tests by replacing common and repetitive actions.

Available Selenium Test Case Methods

As of this writing, the following methods belong to the SeleniumJoomlaTestCase class.

setUp

  • Loads the configuration variables defined in tests/system/servers/configdef.php and launches the test browser accordingly.
public function setUp()
{
    $cfg = new SeleniumConfig();
    $this->cfg = $cfg; // save current configuration
    $this->setBrowser($cfg->browser);
    $this->setBrowserUrl($cfg->host.$cfg->path);
    if(isset($cfg->selhost)) {
        $this->setHost($cfg->selhost);
    }
    echo ".\n".'Starting '.get_class($this).".\n";
}

doAdminLogin

  • Logs into the administrative side of Joomla!
function doAdminLogin()
{
    //$this->setUp();
    echo "Logging in to admin.\n";
    $cfg = new SeleniumConfig();
    $this->open($cfg->path . "administrator/index.php?option=com_login");
    $this->waitForPageToLoad("30000");
    $this->type("mod-login-username", $cfg->username);
    $this->type("mod-login-password", $cfg->password);
    $this->click("link=Log in");
    $this->waitForPageToLoad("30000");
}

doAdminLogout

  • Logs out of the administrative side of Joomla!
function doAdminLogout()
{
    $this->gotoAdmin();
    echo "Logging out of back end.\n";
    $this->click("link=Logout");
}

gotoAdmin

  • Navigates to the administrative side of Joomla!
function gotoAdmin()
{
    echo "Browsing to admin.\n";
    $cfg = new SeleniumConfig();
    $this->open($cfg->path . "administrator");
}

gotoSite

  • Navigates to the front end of Joomla!
function gotoSite()
{
    echo "Browsing to site.\n";
    $cfg = new SeleniumConfig();
    $this->open($cfg->path);
}

doFrontEndLogin

  • Logs into the front end of Joomla!
function doFrontEndLogin()
{
    $this->gotoSite();
    echo "Logging into front end of site.\n";
    $this->type("modlgn_username", "admin");
    $this->type("modlgn_passwd", "password");
    $this->click("Submit");
    $this->waitForPageToLoad("30000");
}

doFrontEndLogout

  • Logs out of the front end of Joomla!
function doFrontEndLogout()
{
    $this->gotoSite();
    echo "Logging out of front end of site.\n";
    $this->click("Submit");
    $this->waitForPageToLoad("30000");
}

setTinyText

  • Allows the test to input data
function setTinyText($text)
{
    $this->selectFrame("text_ifr");
    $this->type("tinymce", $text);
    $this->selectFrame("relative=top");
}