Commit 9b605ebe authored by Son Nguyen's avatar Son Nguyen
Browse files

Implement menu navigation behat fixtures (Bug 1404012)



Change-Id: I716ac2f23e149a91de956758b8484cf8a3e5e2cf
Signed-off-by: default avatarSon Nguyen <son.nguyen@catalyst.net.nz>
parent 13a85f79
<?php
/**
* @package mahara
* @subpackage test/behat
* @author Son Nguyen, Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
* @copyright portions from Moodle Behat, 2013 David Monllaó
*
*/
/**
* Navigation steps definitions.
*
*/
require_once(__DIR__ . '/BehatBase.php');
use Behat\Mink\Exception\ExpectationException as ExpectationException,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException,
Behat\Mink\Exception\DriverException as DriverException,
WebDriver\Exception\NoSuchElement as NoSuchElement,
WebDriver\Exception\StaleElementReference as StaleElementReference,
Behat\Behat\Context\Step\Given as Given,
Behat\Behat\Context\Step\When as When,
Behat\Behat\Context\Step\Then as Then
;
/**
* Navigation steps definitions for mahara
*
*/
class BehatNavigation extends BehatBase {
/**
* Helper function to get main menu item node.
*
* @throws ExpectationException if node not found.
* @param string $menuitemtext the title of menu item e.g. "Dashboard", "Content".
* @return NodeElement
*/
protected function get_main_menu_item_node($menuitemtext) {
// Avoid problems with quotes.
$nodetextliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($menuitemtext);
$exception = new ExpectationException('The menu item "' . $menuitemtext . ' not found or invisible in "', $this->getSession());
$xpath = "//div[@id='main-nav']" .
"/ul[@id='nav']" .
"/li" .
"/span/a[normalize-space(.)=" . $nodetextliteral ."]";
$node = $this->find('xpath', $xpath, $exception);
return $node;
}
/**
* Helper function to get sub menu item node.
*
* @throws ExpectationException if node not found.
* @param string $menuitemtext the title of menu item e.g. "Profile", "Pages".
* @return NodeElement
*/
protected function get_sub_menu_item_node($menuitemtext) {
// Avoid problems with quotes.
$nodetextliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($menuitemtext);
$exception = new ExpectationException('The menu item "' . $menuitemtext . ' not found or invisible in "', $this->getSession());
$xpath = "//div[@id='sub-nav']" .
"/ul" .
"/li" .
"/span/a[normalize-space(.)=" . $nodetextliteral ."]";
$node = $this->find('xpath', $xpath, $exception);
return $node;
}
/**
* Choose a main menu item
*
* @Given /^I choose "(?P<menu_item>(?:[^"]|\\")*)"$/
*/
public function i_choose_menu($menuitem) {
$menuitemnode = $this->get_main_menu_item_node($menuitem);
$menuitemnode->click();
}
/**
* Choose a sub menu item in a main menu item
*
* @Given /^I choose "(?P<menu_item>(?:[^"]|\\")*)" in "(?P<mainmenu_item>(?:[^"]|\\")*)"$/
*/
public function i_choose_submenu($menuitem, $mainmenuitem) {
$menuitemnode = $this->get_main_menu_item_node($mainmenuitem);
$menuitemnode->click();
$this->getSession()->wait(self::TIMEOUT * 1000, self::PAGE_READY_JS);
$menuitemnode = $this->get_sub_menu_item_node($menuitem);
$menuitemnode->click();
}
}
......@@ -15,6 +15,7 @@
*/
require_once(dirname(dirname(__DIR__)) . '/classes/BehatHooks.php');
require_once(dirname(dirname(__DIR__)) . '/classes/BehatGeneral.php');
require_once(dirname(dirname(__DIR__)) . '/classes/BehatNavigation.php');
require_once(dirname(dirname(__DIR__)) . '/classes/BehatForms.php');
require_once(dirname(dirname(__DIR__)) . '/classes/BehatDataGenerators.php');
......@@ -33,6 +34,7 @@ class BehatMaharaInitContext extends MinkContext {
// Initialize must have subcontexts
$this->useContext('BehatHooks', new BehatHooks($parameters));
$this->useContext('BehatGeneral', new BehatGeneral($parameters));
$this->useContext('BehatNavigation', new BehatNavigation($parameters));
$this->useContext('BehatForms', new BehatForms($parameters));
$this->useContext('BehatDataGenerators', new BehatDataGenerators($parameters));
$this->useContext('mahara', new MaharaContext($parameters));
......
@javascript @core @admin @user @navigation
Feature: Mahara users can navigate their portfolio
As a mahara user
I can navigate my portfolio
Scenario: Navigate portfolio
Given the following "institutions" exist:
| name | displayname | registerallowed | registerconfirm |
| instone | Institution One | ON | OFF |
| insttwo | Institution Two | ON | OFF |
And the following "users" exist:
| username | password | email | firstname | lastname | institution | authname | role |
| userA | Password1 | test01@example.com | Pete | Mc | mahara | internal | admin |
| userB | Password1 | test02@example.com | Son | Nguyen | instone | internal | admin |
| userC | Password1 | test03@example.com | Jack | Smith | insttwo | internal | admin |
Given I am on homepage
When I fill in "login_username" with "userA"
And I fill in "login_password" with "Password1"
And I press "Login"
Then I should see "Dashboard"
And I choose "Content"
And I should see "Profile"
And I choose "Collections" in "Portfolio"
And I should see "Collections"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment