Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Behat: Difference between revisions

From MoodleDocs
No edit summary
(redirect)
 
(24 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Behat is a Behaviour Driven Development (BDD) framework. This document is a work in progress (STABLE team week off project) and it should not be taken into account for nothing out of this scope nor nothing official.
#redirect [[Acceptance testing]]
 
== Example ==
The expected behaviours are specified as scenarios.
 
=== Basic scenarios ===
 
    Scenario: Login as an existing user
      Given I am on "login/index.php"
      When I fill in "username" with "admin"
      And I fill in "password" with "moodle"
      And I press "loginbtn"
      Then I should see "Moodle 101: Course Name"
 
    Scenario: Login as an unexisting user
      Given I am on "login/index.php"
      When I fill in "username" with "adminasdasd"
      And I fill in "password" with "moodlesdfasdf"
      And I press "loginbtn"
      Then I should see "Invalid login, please try again"
 
=== Complex scenario ===
The aim of this project is to be able to define scenarios like this. Note the quoted strings are received as variables by the steps definitions which will process them.
 
  Scenario: A teacher adds a discussion
    Given I am logged as a "teacher"
    And I go to a course
    And I create a "forum" activity
    And I view the "forum" activity
    When I add a "forum_discussion" filling the fields "subject,message[text]" with "I'm the user subject,Dealing with \, split"    # Wrapper step, it will redirect the petition to a "forum_discussion" method
    Then I should see "Discussion"
    And I should see "Subject"
    And I should see "I'm the user subject"
 
In order to be able to process the "logged as a $roleshortname" or the "a course" statements a config file with test data must be set (http://docs.behat.org/guides/7.config.html)
 
== Contexts ==
Each step are processed in a step definition, which are defined in "context" classes
 
=== Contexts Organization ===
The Features context class is split in different context to ease the step definitions location.
 
* A main FeaturesContext class which extends MinkContext, the basic web development set of actions (http://docs.behat.org/guides/2.definitions.html#definitions-home-featurecontext-class)
** Contains all the basic steps definitions like visit($url), pressButton($button) to manage the browser
** The cross-component and the most common Moodle actions like iAmLoggedAsA($roleshortname) or aUserAssignedInContextOfContextlevel($roleshortname, $instanceid, $contextlevel) to speed up the creation of scenarios
* An abstract BaseContext class with helper methods
* A context for each Moodle component extending BaseContext that has access to the main FeaturesContext class (http://docs.behat.org/guides/4.context.html#using-subcontexts)

Latest revision as of 08:20, 10 May 2013

Redirect to: