diff --git a/.travis.yml b/.travis.yml index 661cece5da..6b563dedb3 100755 --- a/.travis.yml +++ b/.travis.yml @@ -51,6 +51,14 @@ before_install: #- sudo apt-get install -qq php5-cli php5-fpm before_script: + # setup selenium2 + chrome driver + - wget https://chromedriver.storage.googleapis.com/2.27/chromedriver_linux64.zip && unzip chromedriver_linux64.zip && sudo mv chromedriver /usr/bin + - sh -e /etc/init.d/xvfb start + - export DISPLAY=:99.0 + - wget http://selenium-release.storage.googleapis.com/3.1/selenium-server-standalone-3.1.0.jar + - java -jar selenium-server-standalone-3.1.0.jar > /dev/null & + - sleep 5 + #- which composer #- php -d memory_limit=2G /usr/bin/composer update #- php -d memory_limit=2G /home/travis/.phpenv/shims/composer update diff --git a/tests/behat/behat.yml b/tests/behat/behat.yml index ecbe19e756..93d9e46ef7 100644 --- a/tests/behat/behat.yml +++ b/tests/behat/behat.yml @@ -3,7 +3,12 @@ default: Behat\MinkExtension: base_url: http://my.chamilo.net goutte: ~ - selenium2: ~ + show_cmd: 'open %s' + selenium2: + wd_host: "http://127.0.0.1:4444/wd/hub" + browser: chrome + default_session: selenium2 + javascript_session: selenium2 suites: default: paths: [ %paths.base%/features ] diff --git a/tests/behat/features/bootstrap/FeatureContext.php b/tests/behat/features/bootstrap/FeatureContext.php index 0b7085469e..ac1e504410 100644 --- a/tests/behat/features/bootstrap/FeatureContext.php +++ b/tests/behat/features/bootstrap/FeatureContext.php @@ -294,4 +294,81 @@ class FeatureContext extends MinkContext "CKEDITOR.instances[\"$fieldId\"].setData(\"$value\");" ); } + + /** + * @Given /^I fill hidden field "([^"]*)" with "([^"]*)"$/ + */ + public function iFillHiddenFieldWith($field, $value) + { + $this->getSession()->getPage()->find( + 'css', + 'input[name="'.$field.'"]' + )->setValue($value); + } + + /** + * @When /^(?:|I )fill in select2 input "(?P(?:[^"]|\\")*)" with id "(?P(?:[^"]|\\")*)" and value "(?P(?:[^"]|\\")*)"$/ + */ + public function iFillInSelectInputWithAndSelect($field, $id, $value) + { + $page = $this->getSession()->getPage(); + $this->getSession()->executeScript("$('$field').select2({data : [{id: $id, text: '$value'}]});"); + } + + /** + * @When /^(?:|I )confirm the popup$/ + */ + public function confirmPopup() + { + // See + // https://gist.github.com/blazarecki/2888851 + /** @var \Behat\Mink\Driver\Selenium2Driver $driver Needed because no cross-driver way yet */ + //$driver = $this->getSession()->getDriver(); + $this->getSession()->getDriver()->getWebDriverSession()->accept_alert(); + } + + /** + * @When /^(?:|I )fill in select bootstrap input "(?P(?:[^"]|\\")*)" with "(?P(?:[^"]|\\")*)" and select "(?P(?:[^"]|\\")*)"$/ + */ + public function iFillInSelectBootstrapInputWithAndSelect($field, $value, $entry) + { + $page = $this->getSession()->getPage(); + + $inputField = $page->find('css', $field); + if (!$inputField) { + throw new \Exception('No field found'); + } + + $choice = $inputField->getParent()->find('css', '.bootstrap-select'); + if (!$choice) { + throw new \Exception('No select bootstrap choice found'); + } + $choice->press(); + + $selectInput = $inputField->getParent()->find('css', '.bootstrap-select .form-control'); + if (!$selectInput) { + throw new \Exception('No input found'); + } + + $selectInput->setValue($value); + $this->getSession()->wait(3000); + + $chosenResults = $inputField->getParent()->findAll('css', '.dropdown-menu inner li'); + foreach ($chosenResults as $result) { + //$option = $result->find('css', '.text'); + if ($result->getText() == $entry) { + $result->click(); + break; + } + } + } + + /** + * @When /^wait for the page to be loaded$/ + */ + public function waitForThePageToBeLoaded() + { + //$this->getSession()->wait(10000, "document.readyState === 'complete'"); + $this->getSession()->wait(3000); + } } diff --git a/tests/behat/features/exercise.feature b/tests/behat/features/exercise.feature index aaf49fbe22..6f24747dfe 100644 --- a/tests/behat/features/exercise.feature +++ b/tests/behat/features/exercise.feature @@ -6,7 +6,7 @@ Feature: Exercise tool Given I am a platform administrator And I am on course "TEMP" homepage - Scenario: Create an exercise + Scenario: Create an exercise Given I am on "/main/exercise/exercise_admin.php?cidReq=TEMP" When I fill in the following: | exercise_title | Exercise 1 | diff --git a/tests/behat/features/link.feature b/tests/behat/features/link.feature index dfe58b18d1..7eb1bdefd7 100644 --- a/tests/behat/features/link.feature +++ b/tests/behat/features/link.feature @@ -6,7 +6,7 @@ Feature: Link tool Given I am a platform administrator And I am on course "TEMP" homepage - Scenario: Create a link category + Scenario: Create a link category Given I am on "/main/link/link.php?action=addcategory&cidReq=TEMP" When I fill in the following: | category_title | Category 1 | diff --git a/tests/behat/features/lp.feature b/tests/behat/features/lp.feature index 138842f5e9..b60a442773 100644 --- a/tests/behat/features/lp.feature +++ b/tests/behat/features/lp.feature @@ -6,14 +6,14 @@ Feature: LP tool Given I am a platform administrator And I am on course "TEMP" homepage - Scenario: Create a LP category + Scenario: Create a LP category Given I am on "/main/lp/lp_controller.php?cidReq=TEMP&action=add_lp_category" When I fill in the following: | name | LP category 1 | And I press "submit" Then I should see "Added" - Scenario: Create a LP + Scenario: Create a LP Given I am on "/main/lp/lp_controller.php?cidReq=TEMP&action=add_lp" When I fill in the following: | lp_name | LP 1 | @@ -30,12 +30,12 @@ Feature: LP tool # And I press "submit_button" # Then I should see "Document 1" - Scenario: Delete a LP category + Scenario: Delete a LP category Given I am on "/main/lp/lp_controller.php?cidReq=TEMP&action=list" And I follow "Delete" Then I should not see "LP category 1" - Scenario: Delete a LP + Scenario: Delete a LP Given I am on "/main/lp/lp_controller.php?cidReq=TEMP&action=list" And I follow "Delete" Then I should not see "LP 1" diff --git a/tests/behat/features/session.feature b/tests/behat/features/session.feature new file mode 100644 index 0000000000..4caed76e45 --- /dev/null +++ b/tests/behat/features/session.feature @@ -0,0 +1,41 @@ +Feature: Session tool + In order to use the session tool + The admin should be able to create a session + + Background: + Given I am a platform administrator + + Scenario: Create a session category + Given I am on "/main/session/session_category_add.php" + When I fill in the following: + | name | category_1 | + And I press "Add category" + Then I should see "The category has been added" + + @javascript + Scenario: Create a session + Given I am on "/main/session/session_add.php" + When I fill in the following: + | name | Session 1 | + And I fill in select2 input "#coach_username" with id "1" and value "admin" +# And I follow "Advanced settings" +# And I fill in select bootstrap input "#session_category" with "category_1" and select "category_1" + And I press "submit" + Then I should see "Add courses to this session (Session 1)" + Then I select "TEMP (TEMP)" from "NoSessionCoursesList[]" + And I press "add_course" + And I press "next" + Then I should see "Update successful" + + Scenario: Delete session + Given I am on "/main/session/session_list.php?keyword=Session+1" + And wait for the page to be loaded + And I follow "Delete" + And I confirm the popup + Then I should see "Deleted" + + Scenario: Delete session category + Given I am on "/main/session/session_category_list.php" + And I follow "Delete" + And I confirm the popup + Then I should see "The selected categories have been deleted" \ No newline at end of file diff --git a/tests/behat/features/socialGroup.feature b/tests/behat/features/socialGroup.feature index 9dd10c3fa8..2a5c03ff1d 100644 --- a/tests/behat/features/socialGroup.feature +++ b/tests/behat/features/socialGroup.feature @@ -3,14 +3,14 @@ Feature: Social Group As an administrator I need to be able to create a social group, invite users and post a message - Scenario: Create a social group - Given I am a platform administrator - And I am on "/main/social/group_add.php" - When I fill in the following: - | name | Behat Test Group | - | description | This is a group created by Behat | - And I press "submit" - Then I should see "Group added" + Scenario: Create a social group + Given I am a platform administrator + And I am on "/main/social/group_add.php" + When I fill in the following: + | name | Behat Test Group | + | description | This is a group created by Behat | + And I press "submit" + Then I should see "Group added" # Scenario: Invite a friend to group # Given I am a platform administrator diff --git a/tests/behat/features/work.feature b/tests/behat/features/work.feature index b22fc086dc..e5037d4618 100644 --- a/tests/behat/features/work.feature +++ b/tests/behat/features/work.feature @@ -6,12 +6,10 @@ Feature: Work tool Given I am a platform administrator And I am on course "TEMP" homepage - Scenario: Create a work + Scenario: Create a work Given I am on "/main/work/work.php?action=create_dir&cidReq=TEMP" When I fill in the following: | new_dir | Work 1 | | description | Work description | And I press "submit" Then I should see "Directory created" - -